From cef4c1a0bc6889e383cebecf757c854325ff2b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=20Lin=29?= Date: Tue, 16 Apr 2019 17:48:34 +0800 Subject: [PATCH 1/8] snap: Flip `grade` property to stable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the snap to be promoted to the `candidate` and the `stable` release channels Signed-off-by: 林博仁(Buo-ren Lin) --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 9c50293..a3c41d1 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -23,7 +23,7 @@ description: | # snap connect shellcheck:removable-media version: git -grade: devel +grade: stable confinement: strict apps: From 67dbbcbd89bb5f58eaf0e01605fcc3e299361730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=20Lin=29?= Date: Tue, 16 Apr 2019 17:53:01 +0800 Subject: [PATCH 2/8] snap: Drop unneeded trailing slash in the `source` property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 林博仁(Buo-ren Lin) --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index a3c41d1..83ae66d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -34,7 +34,7 @@ apps: parts: shellcheck: plugin: dump - source: ./ + source: . build-packages: - cabal-install - squid3 From 10955a143c81dae6cf7f82cd6dc21a3b9479b30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=20Lin=29?= Date: Tue, 16 Apr 2019 18:10:49 +0800 Subject: [PATCH 3/8] snap: Replace deprecated build and install keyword MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These keywords has been obsoleted in Snapcraft 3. Refer-to: The 'build' keyword has been replaced by 'override-build' Refer-to: The 'install' keyword has been replaced by 'override-build' Signed-off-by: 林博仁(Buo-ren Lin) --- snap/snapcraft.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 83ae66d..73d0eeb 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -38,7 +38,7 @@ parts: build-packages: - cabal-install - squid3 - build: | + override-build: | # See comments in .snapsquid.conf [ "$http_proxy" ] && { squid3 -f .snapsquid.conf @@ -48,6 +48,6 @@ parts: cabal sandbox init cabal update || cat /var/log/squid/* cabal install -j - install: | + install -d $SNAPCRAFT_PART_INSTALL/usr/bin install .cabal-sandbox/bin/shellcheck $SNAPCRAFT_PART_INSTALL/usr/bin From 025c380b8410459f72d806420d408d8f4f9cd956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=8D=9A=E4=BB=81=28Buo-ren=20Lin=29?= Date: Tue, 16 Apr 2019 19:59:29 +0800 Subject: [PATCH 4/8] snap: Migrate to core18 base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch migrates the snap to core18 base, which should make the cabal build work again. Signed-off-by: 林博仁(Buo-ren Lin) --- snap/snapcraft.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 73d0eeb..8365b13 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -23,6 +23,7 @@ description: | # snap connect shellcheck:removable-media version: git +base: core18 grade: stable confinement: strict @@ -37,7 +38,7 @@ parts: source: . build-packages: - cabal-install - - squid3 + - squid override-build: | # See comments in .snapsquid.conf [ "$http_proxy" ] && { From 37b24cc1296b50422540289ce243d3e894bbf6e9 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 4 May 2019 12:18:45 -0700 Subject: [PATCH 5/8] Don't warn about "a"b"c" in =~ regex (fixes #1565) --- src/ShellCheck/Analytics.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index f89df9a..ef05103 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -1424,7 +1424,8 @@ prop_checkInexplicablyUnquoted5 = verifyNot checkInexplicablyUnquoted "\"$dir\"/ prop_checkInexplicablyUnquoted6 = verifyNot checkInexplicablyUnquoted "\"$dir\"some_stuff\"$file\"" prop_checkInexplicablyUnquoted7 = verifyNot checkInexplicablyUnquoted "${dir/\"foo\"/\"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 check (T_SingleQuoted _ _:T_Literal id 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_DollarBraced id _ -> warnAboutExpansion id T_Literal id s -> - unless (quotesSingleThing a && quotesSingleThing b) $ + unless (quotesSingleThing a && quotesSingleThing b || isRegex (getPath (parentMap params) trapped)) $ warnAboutLiteral id _ -> 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", -- the quotes were probably intentional and harmless. quotesSingleThing x = case x of From a3cd5979a2fedc249fc5dde4762ca9eae5e00159 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 4 May 2019 12:54:59 -0700 Subject: [PATCH 6/8] Update message for SC2171 --- src/ShellCheck/Analytics.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index ef05103..766efae 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -2737,7 +2737,7 @@ checkTrailingBracket _ token = parameters = oversimplify command guard $ opposite `notElem` parameters return $ warn id 2171 $ - "Found trailing " ++ str ++ " outside test. Missing " ++ opposite ++ "?" + "Found trailing " ++ str ++ " outside test. Add missing " ++ opposite ++ " or quote if intentional." _ -> return () invert s = case s of From ec25fb4052047a60afc2ff13347ae8aa00a22fd9 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 May 2019 22:59:35 +1000 Subject: [PATCH 7/8] :memo: add Chocolatey installation method - [x] :sparkles: add Chocolatey for Windows installation - [x] :rotating_light: add language types to code blocks --- README.md | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index d426216..bac5561 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,15 @@ 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) - [How to use](#how-to-use) - [On the web](#on-the-web) - [From your terminal](#from-your-terminal) - [In your editor](#in-your-editor) - [In your build or test suites](#in-your-build-or-test-suites) - [Installing](#installing) +- [Travis CI](#travis-ci) +- [Installing the shellcheck binary](#installing-the-shellcheck-binary) - [Compiling from source](#compiling-from-source) - [Installing Cabal](#installing-cabal) - [Compiling ShellCheck](#compiling-shellcheck) @@ -46,6 +49,7 @@ See [the gallery of bad code](README.md#user-content-gallery-of-bad-code) for ex - [Reporting bugs](#reporting-bugs) - [Contributing](#contributing) - [Copyright](#copyright) +- [Other Resources](#other-resources) ## How to use @@ -53,7 +57,7 @@ There are a number of ways to use ShellCheck! ### On the web -Paste a shell script on https://www.shellcheck.net for instant feedback. +Paste a shell script on 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! @@ -88,7 +92,7 @@ It makes canonical use of exit codes, so you can just add a `shellcheck` command For example, in a Makefile: -``` +```Makefile check-scripts: # Fail if any of these files have warnings shellcheck myscripts/*.sh @@ -96,7 +100,7 @@ check-scripts: or in a Travis CI `.travis.yml` file: -``` +```yaml script: # Fail if any of these files have warnings - shellcheck myscripts/*.sh @@ -182,10 +186,18 @@ Or use OneClickInstall - https://software.opensuse.org/package/ShellCheck On Solus: eopkg install shellcheck - -On Windows (via [scoop](http://scoop.sh)): - scoop install shellcheck +On Windows (via [chocolatey](https://chocolatey.org/packages/shellcheck)): + +```cmd +C:\> choco install shellcheck +``` + +Or Windows (via [scoop](http://scoop.sh)): + +```cmd +C:\> scoop install shellcheck +``` From Snap Store: @@ -210,8 +222,10 @@ or see the [storage bucket listing](https://shellcheck.storage.googleapis.com/in Distro packages already come with a `man` page. If you are building from source, it can be installed with: - pandoc -s -t man shellcheck.1.md -o shellcheck.1 - sudo mv shellcheck.1 /usr/share/man/man1 +```console +pandoc -s -t man shellcheck.1.md -o shellcheck.1 +sudo mv shellcheck.1 /usr/share/man/man1 +``` ## Travis CI @@ -282,12 +296,16 @@ 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 codepage to UTF-8 (65001) with `chcp`: - > chcp 65001 - Active code page: 65001 +```cmd +chcp 65001 +Active code page: 65001 +``` 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 @@ -456,7 +474,7 @@ while getopts "a" f; do case $f in "b") # Unhandled getopts flags ## Testimonials -> At first you're like "shellcheck is awesome" but then you're like "wtf are we still using bash" +> 🔉 At first you're like "shellcheck is awesome" but then you're like "wtf are we still using bash" Alexander Tarasikov, [via Twitter](https://twitter.com/astarasikov/status/568825996532707330) @@ -465,13 +483,13 @@ Alexander Tarasikov, Issues can be ignored via environmental variable, command line, individually or globally within a file: -https://github.com/koalaman/shellcheck/wiki/Ignore + ## Reporting bugs Please use the GitHub issue tracker for any bugs or feature suggestions: -https://github.com/koalaman/shellcheck/issues + ## Contributing @@ -490,7 +508,7 @@ Copyright 2012-2018, Vidar 'koala_man' Holen and contributors. Happy ShellChecking! - ## 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). * ShellCheck does not attempt to enforce any kind of formatting or indenting style, so also check out [shfmt](https://github.com/mvdan/sh)! From 2521c1cf56d0f047eee6a7f716a9b99fe4d2e8a6 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 8 May 2019 18:03:58 -0700 Subject: [PATCH 8/8] Tweak README --- README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index bac5561..f11c84e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ See [the gallery of bad code](README.md#user-content-gallery-of-bad-code) for ex - [In your editor](#in-your-editor) - [In your build or test suites](#in-your-build-or-test-suites) - [Installing](#installing) -- [Travis CI](#travis-ci) -- [Installing the shellcheck binary](#installing-the-shellcheck-binary) - [Compiling from source](#compiling-from-source) - [Installing Cabal](#installing-cabal) - [Compiling ShellCheck](#compiling-shellcheck) @@ -227,22 +225,26 @@ pandoc -s -t man shellcheck.1.md -o shellcheck.1 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. -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. -To install it on debian/ubuntu/linux mint, run `apt install xz-utils`. -To install it on Redhat/Fedora/CentOS, run `yum -y install xz`. +The pre-compiled binaries come in `tar.xz` files. To decompress them, make sure +`xz` is installed. +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 -export scversion="stable" # or "v0.4.7", or "latest" -wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-"${scversion}".linux.x86_64.tar.xz" | tar -xJv -cp shellcheck-"${scversion}"/shellcheck /usr/bin/ +scversion="stable" # or "v0.4.7", or "latest" +wget -qO- "https://storage.googleapis.com/shellcheck/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv +cp "shellcheck-${scversion}/shellcheck" /usr/bin/ shellcheck --version ``` @@ -298,7 +300,6 @@ codepage to UTF-8 (65001) with `chcp`: ```cmd chcp 65001 -Active code page: 65001 ``` In Powershell ISE, you may need to additionally update the output encoding: @@ -474,7 +475,7 @@ while getopts "a" f; do case $f in "b") # Unhandled getopts flags ## Testimonials -> 🔉 At first you're like "shellcheck is awesome" but then you're like "wtf are we still using bash" +> At first you're like "shellcheck is awesome" but then you're like "wtf are we still using bash" Alexander Tarasikov, [via Twitter](https://twitter.com/astarasikov/status/568825996532707330)