Suggest quoting case patterns, as for SC2053 (fixes #1682)
This commit is contained in:
parent
71a4053e8c
commit
e01c470598
|
@ -2,6 +2,9 @@
|
|||
### Fixed
|
||||
- `-f diff` no longer claims that it found more issues when it didn't
|
||||
|
||||
### Added
|
||||
- SC2254: Suggest quoting expansions in case statements
|
||||
|
||||
## v0.7.0 - 2019-07-28
|
||||
### Added
|
||||
- Precompiled binaries for macOS and Linux aarch64
|
||||
|
|
|
@ -125,6 +125,7 @@ nodeChecks = [
|
|||
,checkArithmeticDeref
|
||||
,checkArithmeticBadOctal
|
||||
,checkComparisonAgainstGlob
|
||||
,checkCaseAgainstGlob
|
||||
,checkCommarrays
|
||||
,checkOrNeq
|
||||
,checkEchoWc
|
||||
|
@ -1338,6 +1339,21 @@ checkComparisonAgainstGlob params (TC_Binary _ SingleBracket op _ word)
|
|||
|
||||
checkComparisonAgainstGlob _ _ = return ()
|
||||
|
||||
prop_checkCaseAgainstGlob1 = verify checkCaseAgainstGlob "case foo in lol$n) foo;; esac"
|
||||
prop_checkCaseAgainstGlob2 = verify checkCaseAgainstGlob "case foo in $(foo)) foo;; esac"
|
||||
prop_checkCaseAgainstGlob3 = verifyNot checkCaseAgainstGlob "case foo in *$bar*) foo;; esac"
|
||||
checkCaseAgainstGlob _ t =
|
||||
case t of
|
||||
(T_CaseExpression _ _ cases) -> mapM_ check cases
|
||||
_ -> return ()
|
||||
where
|
||||
check (_, list, _) = mapM_ check' list
|
||||
check' expr@(T_NormalWord _ list)
|
||||
-- If it's already a glob, assume that's what the user wanted
|
||||
| not (isGlob expr) && any isQuoteableExpansion list =
|
||||
warn (getId expr) 2254 "Quote expansions in case patterns to match literally rather than as a glob."
|
||||
check' _ = return ()
|
||||
|
||||
prop_checkCommarrays1 = verify checkCommarrays "a=(1, 2)"
|
||||
prop_checkCommarrays2 = verify checkCommarrays "a+=(1,2,3)"
|
||||
prop_checkCommarrays3 = verifyNot checkCommarrays "cow=(1 \"foo,bar\" 3)"
|
||||
|
|
Loading…
Reference in New Issue