From fee6c94d40bf40de6f33fad7fd2770d514b7a811 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 10 Dec 2016 10:57:01 -0800 Subject: [PATCH] Alias ash to dash with warning. --- ShellCheck/Analytics.hs | 13 +++++++++---- ShellCheck/AnalyzerLib.hs | 8 +++++++- ShellCheck/Data.hs | 1 + nextnumber | 10 ++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100755 nextnumber diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 9585c04..b5ccd9a 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -400,15 +400,20 @@ prop_checkShebang1 = verifyNotTree checkShebang "#!/usr/bin/env bash -x\necho co prop_checkShebang2 = verifyNotTree checkShebang "#! /bin/sh -l " prop_checkShebang3 = verifyTree checkShebang "ls -l" prop_checkShebang4 = verifyNotTree checkShebang "#shellcheck shell=sh\nfoo" +prop_checkShebang5 = verifyTree checkShebang "#!/usr/bin/env ash" +prop_checkShebang6 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=dash\n" +prop_checkShebang7 = verifyNotTree checkShebang "#!/usr/bin/env ash\n# shellcheck shell=sh\n" checkShebang params (T_Annotation _ list t) = if any isOverride list then [] else checkShebang params t where isOverride (ShellOverride _) = True isOverride _ = False -checkShebang params (T_Script id sb _) = - [makeComment ErrorC id 2148 - "Tips depend on target shell and yours is unknown. Add a shebang." - | not (shellTypeSpecified params) && sb == "" ] +checkShebang params (T_Script id sb _) = execWriter $ + unless (shellTypeSpecified params) $ do + when (sb == "") $ + err id 2148 "Tips depend on target shell and yours is unknown. Add a shebang." + when (executableFromShebang sb == "ash") $ + warn id 2187 "Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence." prop_checkForInQuoted = verify checkForInQuoted "for f in \"$(ls)\"; do echo foo; done" diff --git a/ShellCheck/AnalyzerLib.hs b/ShellCheck/AnalyzerLib.hs index 469bfed..a48ed5a 100644 --- a/ShellCheck/AnalyzerLib.hs +++ b/ShellCheck/AnalyzerLib.hs @@ -153,6 +153,7 @@ prop_determineShell4 = determineShell (fromJust $ pScript prop_determineShell5 = determineShell (fromJust $ pScript "#shellcheck shell=sh\nfoo") == Sh prop_determineShell6 = determineShell (fromJust $ pScript "#! /bin/sh") == Sh +prop_determineShell7 = determineShell (fromJust $ pScript "#! /bin/ash") == Dash determineShell t = fromMaybe Bash $ do shellString <- foldl mplus Nothing $ getCandidates t shellForExecutable shellString @@ -166,8 +167,13 @@ determineShell t = fromMaybe Bash $ do getCandidates (T_Annotation _ annotations s) = map forAnnotation annotations ++ [Just $ fromShebang s] - fromShebang (T_Script _ s t) = shellFor s + fromShebang (T_Script _ s t) = executableFromShebang s +-- Given a string like "/bin/bash" or "/usr/bin/env dash", +-- return the shell basename like "bash" or "dash" +executableFromShebang :: String -> String +executableFromShebang = shellFor + where shellFor s | "/env " `isInfixOf` s = head (drop 1 (words s)++[""]) shellFor s | ' ' `elem` s = shellFor $ takeWhile (/= ' ') s shellFor s = reverse . takeWhile (/= '/') . reverse $ s diff --git a/ShellCheck/Data.hs b/ShellCheck/Data.hs index 0ef8cfc..fa35405 100644 --- a/ShellCheck/Data.hs +++ b/ShellCheck/Data.hs @@ -88,6 +88,7 @@ shellForExecutable name = "sh" -> return Sh "bash" -> return Bash "dash" -> return Dash + "ash" -> return Dash -- There's also a warning for this. "ksh" -> return Ksh "ksh88" -> return Ksh "ksh93" -> return Ksh diff --git a/nextnumber b/nextnumber new file mode 100755 index 0000000..27dfa0a --- /dev/null +++ b/nextnumber @@ -0,0 +1,10 @@ +#!/bin/bash +# TODO: Find a less trashy way to get the next available error code + +shopt -s globstar + +for i in 1 2 +do + last=$(grep -hv "^prop" **/*.hs | grep -Ewo "$i[0-9]{3}" | sort -n | tail -n 1) + echo "Next ${i}xxx: $((last+1))" +done