Merge branch 'master' into readme-pandoc

This commit is contained in:
Virgil 2019-05-09 20:32:07 +10:00 committed by GitHub
commit 1c7a9f8a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 29 deletions

View File

@ -21,6 +21,7 @@ See [the gallery of bad code](README.md#user-content-gallery-of-bad-code) for ex
## Table of Contents ## Table of Contents
- [Table of Contents](#table-of-contents)
- [How to use](#how-to-use) - [How to use](#how-to-use)
- [On the web](#on-the-web) - [On the web](#on-the-web)
- [From your terminal](#from-your-terminal) - [From your terminal](#from-your-terminal)
@ -46,6 +47,7 @@ See [the gallery of bad code](README.md#user-content-gallery-of-bad-code) for ex
- [Reporting bugs](#reporting-bugs) - [Reporting bugs](#reporting-bugs)
- [Contributing](#contributing) - [Contributing](#contributing)
- [Copyright](#copyright) - [Copyright](#copyright)
- [Other Resources](#other-resources)
## How to use ## How to use
@ -53,7 +55,7 @@ There are a number of ways to use ShellCheck!
### On the web ### On the web
Paste a shell script on https://www.shellcheck.net for instant feedback. Paste a shell script on <https://www.shellcheck.net> for instant feedback.
[ShellCheck.net](https://www.shellcheck.net) is always synchronized to the latest git commit, and is the easiest way to give ShellCheck a go. Tell your friends! [ShellCheck.net](https://www.shellcheck.net) is always synchronized to the latest git commit, and is the easiest way to give ShellCheck a go. Tell your friends!
@ -88,7 +90,7 @@ It makes canonical use of exit codes, so you can just add a `shellcheck` command
For example, in a Makefile: For example, in a Makefile:
``` ```Makefile
check-scripts: check-scripts:
# Fail if any of these files have warnings # Fail if any of these files have warnings
shellcheck myscripts/*.sh shellcheck myscripts/*.sh
@ -96,7 +98,7 @@ check-scripts:
or in a Travis CI `.travis.yml` file: or in a Travis CI `.travis.yml` file:
``` ```yaml
script: script:
# Fail if any of these files have warnings # Fail if any of these files have warnings
- shellcheck myscripts/*.sh - shellcheck myscripts/*.sh
@ -183,9 +185,17 @@ On Solus:
eopkg install shellcheck eopkg install shellcheck
On Windows (via [scoop](http://scoop.sh)): On Windows (via [chocolatey](https://chocolatey.org/packages/shellcheck)):
scoop install shellcheck ```cmd
C:\> choco install shellcheck
```
Or Windows (via [scoop](http://scoop.sh)):
```cmd
C:\> scoop install shellcheck
```
From Snap Store: From Snap Store:
@ -215,22 +225,26 @@ pandoc -s -f markdown-smart -t man shellcheck.1.md -o shellcheck.1
sudo mv shellcheck.1 /usr/share/man/man1 sudo mv shellcheck.1 /usr/share/man/man1
``` ```
## Travis CI ### Travis CI
Travis CI has now integrated ShellCheck by default, so you don't need to manually install it. Travis CI has now integrated ShellCheck by default, so you don't need to manually install it.
If you still want to do so in order to upgrade at your leisure or ensure the latest release, follow the steps to install the shellcheck binary, bellow. If you still want to do so in order to upgrade at your leisure or ensure you're
using the latest release, follow the steps below to install a binary version.
## Installing the shellcheck binary ### Installing a pre-compiled binary
*Pre-requisite*: the program 'xz' needs to be installed on the system. The pre-compiled binaries come in `tar.xz` files. To decompress them, make sure
To install it on debian/ubuntu/linux mint, run `apt install xz-utils`. `xz` is installed.
To install it on Redhat/Fedora/CentOS, run `yum -y install xz`. On Debian/Ubuntu/Mint, you can `apt install xz-utils`.
On Redhat/Fedora/CentOS, `yum -y install xz`.
A simple installer may do something like:
```bash ```bash
export scversion="stable" # or "v0.4.7", or "latest" scversion="stable" # or "v0.4.7", or "latest"
wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-"${scversion}".linux.x86_64.tar.xz" | tar -xJv wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
cp shellcheck-"${scversion}"/shellcheck /usr/bin/ cp "shellcheck-${scversion}/shellcheck" /usr/bin/
shellcheck --version shellcheck --version
``` ```
@ -284,12 +298,15 @@ may use a legacy codepage. In `cmd.exe`, `powershell.exe` and Powershell ISE,
make sure to use a TrueType font, not a Raster font, and set the active make sure to use a TrueType font, not a Raster font, and set the active
codepage to UTF-8 (65001) with `chcp`: codepage to UTF-8 (65001) with `chcp`:
> chcp 65001 ```cmd
Active code page: 65001 chcp 65001
```
In Powershell ISE, you may need to additionally update the output encoding: In Powershell ISE, you may need to additionally update the output encoding:
> [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 ```powershell
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
```
### Running tests ### Running tests
@ -467,13 +484,13 @@ Alexander Tarasikov,
Issues can be ignored via environmental variable, command line, individually or globally within a file: Issues can be ignored via environmental variable, command line, individually or globally within a file:
https://github.com/koalaman/shellcheck/wiki/Ignore <https://github.com/koalaman/shellcheck/wiki/Ignore>
## Reporting bugs ## Reporting bugs
Please use the GitHub issue tracker for any bugs or feature suggestions: Please use the GitHub issue tracker for any bugs or feature suggestions:
https://github.com/koalaman/shellcheck/issues <https://github.com/koalaman/shellcheck/issues>
## Contributing ## Contributing
@ -492,7 +509,7 @@ Copyright 2012-2018, Vidar 'koala_man' Holen and contributors.
Happy ShellChecking! Happy ShellChecking!
## Other Resources ## Other Resources
* The wiki has [long form descriptions](https://github.com/koalaman/shellcheck/wiki/Checks) for each warning, e.g. [SC2221](https://github.com/koalaman/shellcheck/wiki/SC2221). * The wiki has [long form descriptions](https://github.com/koalaman/shellcheck/wiki/Checks) for each warning, e.g. [SC2221](https://github.com/koalaman/shellcheck/wiki/SC2221).
* ShellCheck does not attempt to enforce any kind of formatting or indenting style, so also check out [shfmt](https://github.com/mvdan/sh)! * ShellCheck does not attempt to enforce any kind of formatting or indenting style, so also check out [shfmt](https://github.com/mvdan/sh)!

View File

@ -23,7 +23,8 @@ description: |
# snap connect shellcheck:removable-media # snap connect shellcheck:removable-media
version: git version: git
grade: devel base: core18
grade: stable
confinement: strict confinement: strict
apps: apps:
@ -34,11 +35,11 @@ apps:
parts: parts:
shellcheck: shellcheck:
plugin: dump plugin: dump
source: ./ source: .
build-packages: build-packages:
- cabal-install - cabal-install
- squid3 - squid
build: | override-build: |
# See comments in .snapsquid.conf # See comments in .snapsquid.conf
[ "$http_proxy" ] && { [ "$http_proxy" ] && {
squid3 -f .snapsquid.conf squid3 -f .snapsquid.conf
@ -48,6 +49,6 @@ parts:
cabal sandbox init cabal sandbox init
cabal update || cat /var/log/squid/* cabal update || cat /var/log/squid/*
cabal install -j cabal install -j
install: |
install -d $SNAPCRAFT_PART_INSTALL/usr/bin install -d $SNAPCRAFT_PART_INSTALL/usr/bin
install .cabal-sandbox/bin/shellcheck $SNAPCRAFT_PART_INSTALL/usr/bin install .cabal-sandbox/bin/shellcheck $SNAPCRAFT_PART_INSTALL/usr/bin

View File

@ -1424,7 +1424,8 @@ prop_checkInexplicablyUnquoted5 = verifyNot checkInexplicablyUnquoted "\"$dir\"/
prop_checkInexplicablyUnquoted6 = verifyNot checkInexplicablyUnquoted "\"$dir\"some_stuff\"$file\"" prop_checkInexplicablyUnquoted6 = verifyNot checkInexplicablyUnquoted "\"$dir\"some_stuff\"$file\""
prop_checkInexplicablyUnquoted7 = verifyNot checkInexplicablyUnquoted "${dir/\"foo\"/\"bar\"}" prop_checkInexplicablyUnquoted7 = verifyNot checkInexplicablyUnquoted "${dir/\"foo\"/\"bar\"}"
prop_checkInexplicablyUnquoted8 = verifyNot checkInexplicablyUnquoted " 'foo'\\\n 'bar'" prop_checkInexplicablyUnquoted8 = verifyNot checkInexplicablyUnquoted " 'foo'\\\n 'bar'"
checkInexplicablyUnquoted _ (T_NormalWord id tokens) = mapM_ check (tails tokens) prop_checkInexplicablyUnquoted9 = verifyNot checkInexplicablyUnquoted "[[ $x =~ \"foo\"(\"bar\"|\"baz\") ]]"
checkInexplicablyUnquoted params (T_NormalWord id tokens) = mapM_ check (tails tokens)
where where
check (T_SingleQuoted _ _:T_Literal id str:_) check (T_SingleQuoted _ _:T_Literal id str:_)
| not (null str) && all isAlphaNum str = | not (null str) && all isAlphaNum str =
@ -1435,12 +1436,21 @@ checkInexplicablyUnquoted _ (T_NormalWord id tokens) = mapM_ check (tails tokens
T_DollarExpansion id _ -> warnAboutExpansion id T_DollarExpansion id _ -> warnAboutExpansion id
T_DollarBraced id _ -> warnAboutExpansion id T_DollarBraced id _ -> warnAboutExpansion id
T_Literal id s -> T_Literal id s ->
unless (quotesSingleThing a && quotesSingleThing b) $ unless (quotesSingleThing a && quotesSingleThing b || isRegex (getPath (parentMap params) trapped)) $
warnAboutLiteral id warnAboutLiteral id
_ -> return () _ -> return ()
check _ = return () check _ = return ()
-- Regexes for [[ .. =~ re ]] are parsed with metacharacters like ()| as unquoted
-- literals, so avoid overtriggering on these.
isRegex t =
case t of
(T_Redirecting {} : _) -> False
(a:(TC_Binary _ _ "=~" lhs rhs):rest) -> getId a == getId rhs
_:rest -> isRegex rest
_ -> False
-- If the surrounding quotes quote single things, like "$foo"_and_then_some_"$stuff", -- If the surrounding quotes quote single things, like "$foo"_and_then_some_"$stuff",
-- the quotes were probably intentional and harmless. -- the quotes were probably intentional and harmless.
quotesSingleThing x = case x of quotesSingleThing x = case x of
@ -2727,7 +2737,7 @@ checkTrailingBracket _ token =
parameters = oversimplify command parameters = oversimplify command
guard $ opposite `notElem` parameters guard $ opposite `notElem` parameters
return $ warn id 2171 $ return $ warn id 2171 $
"Found trailing " ++ str ++ " outside test. Missing " ++ opposite ++ "?" "Found trailing " ++ str ++ " outside test. Add missing " ++ opposite ++ " or quote if intentional."
_ -> return () _ -> return ()
invert s = invert s =
case s of case s of