add shellcheck

This commit is contained in:
Ingi Hong
2021-04-09 17:58:07 +00:00
committed by AJ ONeal
parent 79818b7628
commit 7068584ef5
4 changed files with 184 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
---
title: ShellCheck
homepage: https://github.com/koalaman/shellcheck
tagline: |
ShellCheck - A shell script static analysis tool
---
To update or switch versions, run `webi shellcheck@stable`, or `@vx.y.z` for a
specific version.
## Cheat Sheet
> shellcheck catches rookie mistakes (and old-habits-die-hard mistakes) in bash
### Run shellcheck in your terminal:
```bash
shellcheck yourscript
```
<!---
### Run shellcheck in your editor:
Include running shellcheck in editor?
It's just links to other linters or extensions
-->
### To use shellcheck in a build or test suite:
Simply include shellcheck in the process.
```bash
check-scripts:
# Fail if any of these files have warnings
shellcheck myscripts/*.sh
```
<!---
Improve this as you need to!
-->
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env pwsh
######################
# Install shellcheck #
######################
# Every package should define these variables
$pkg_cmd_name = "shellcheck"
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\shellcheck.exe"
$pkg_dst = "$pkg_dst_cmd"
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\shellcheck-v$Env:WEBI_VERSION\bin\shellcheck.exe"
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\shellcheck-v$Env:WEBI_VERSION\bin"
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\shellcheck-v$Env:WEBI_VERSION"
$pkg_src = "$pkg_src_cmd"
$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
# Fetch archive
IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
{
# TODO: arch detection
echo "Downloading shellcheck from $Env:WEBI_PKG_URL to $pkg_download"
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
& move "$pkg_download.part" "$pkg_download"
}
IF (!(Test-Path -Path "$pkg_src_cmd"))
{
echo "Installing shellcheck"
# TODO: create package-specific temp directory
# Enter tmp
pushd .local\tmp
# Remove any leftover tmp cruft
Remove-Item -Path ".\shellcheck-v*" -Recurse -ErrorAction Ignore | out-null
Remove-Item -Path ".\shellcheck.exe" -Recurse -ErrorAction Ignore | out-null
# Unpack archive file into this temporary directory
# Windows BSD-tar handles zip. Imagine that.
echo "Unpacking $pkg_download"
& tar xf "$pkg_download"
# Settle unpacked archive into place
echo "Install Location: $pkg_src_cmd"
New-Item "$pkg_src_bin" -ItemType Directory -Force | out-null
Move-Item -Path ".\shellcheck*.exe" -Destination "$pkg_src_cmd"
# Exit tmp
popd
}
echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | out-null
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
function __init_shellcheck() {
set -e
set -u
######################
# Install shellcheck #
######################
# Every package should define these 6 variables
pkg_cmd_name="shellcheck"
pkg_dst_cmd="$HOME/.local/bin/shellcheck"
pkg_dst="$pkg_dst_cmd"
pkg_src_cmd="$HOME/.local/opt/shellcheck-v$WEBI_VERSION/bin/shellcheck"
pkg_src_dir="$HOME/.local/opt/shellcheck-v$WEBI_VERSION"
pkg_src="$pkg_src_cmd"
# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/shellcheck-v0.99.9/bin
mkdir -p "$(dirname $pkg_src_cmd)"
# mv ./shellcheck-*/shellcheck ~/.local/opt/shellcheck-v0.99.9/bin/shellcheck
mv ./shellcheck-*/shellcheck "$pkg_src_cmd"
}
# pkg_get_current_version is recommended, but (soon) not required
pkg_get_current_version() {
# 'shellcheck --version' has output in this format:
# ShellCheck - shell script analysis tool
# version: 0.7.1
# license: GNU General Public License, version 3
# website: https://www.shellcheck.net
# This trims it down to just the version number:
# 0.7.1
echo $(shellcheck --version 2> /dev/null | head -n 2 | tail -n 1 | cut -d' ' -f 2)
}
}
__init_shellcheck
+41
View File
@@ -0,0 +1,41 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'koalaman';
var repo = 'shellcheck';
module.exports = function (request) {
return github(request, owner, repo).then(function (all) {
all.releases
.filter(function (rel) {
// don't include meta versions as actual versions
if (
['latest', 'stable'].includes(rel.version) ||
'v' !== rel.version[0]
) {
return false;
}
return true;
})
.forEach(function (rel) {
// if there is no os or arch or source designation, and it's a .zip, it's Windows amd64
if (
!/(darwin|mac|linux|x86_64|arm|src|source)/i.test(rel.name) &&
/\.zip$/.test(rel.name)
) {
rel.os = 'windows';
rel.arch = 'amd64';
}
});
return all;
});
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the first 5 for demonstration
all.releases = all.releases.slice(0, 5);
console.info(JSON.stringify(all, null, 2));
});
}