Skip to content

Commit

Permalink
Make x-comparison warning default
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Apr 11, 2021
1 parent b68df18 commit 5669eb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@
- SC2264: Warn about wrapper functions that blatantly recurse
- SC2265/SC2266: Warn when using & or | with test statements
- SC2267: Warn when using xargs -i instead of -I
- Optional avoid-x-comparisons: Style warning SC2268 for `[ x$var = xval ]`
- SC2268: Warn about unnecessary x-comparisons like `[ x$var = xval ]`

### Fixed
- SC1072/SC1073 now respond to disable annotations, though ignoring parse errors
Expand Down
10 changes: 2 additions & 8 deletions src/ShellCheck/Analytics.hs
Expand Up @@ -196,6 +196,7 @@ nodeChecks = [
,checkAssignToSelf
,checkEqualsInCommand
,checkSecondArgIsComparison
,checkComparisonWithLeadingX
]

optionalChecks = map fst optionalTreeChecks
Expand Down Expand Up @@ -243,13 +244,6 @@ optionalTreeChecks = [
cdPositive = "echo $VAR",
cdNegative = "VAR=hello; echo $VAR"
}, checkUnassignedReferences' True)

,(newCheckDescription {
cdName = "avoid-x-comparisons",
cdDescription = "Warn about 'x'-prefix in comparisons",
cdPositive = "[ \"x$var\" = xval ]",
cdNegative = "[ \"$var\" = val ]"
}, nodeChecksToTreeCheck [checkComparisonWithLeadingX])
]

optionalCheckMap :: Map.Map String (Parameters -> Token -> [TokenComment])
Expand Down Expand Up @@ -4006,7 +4000,7 @@ checkComparisonWithLeadingX params t =
check lhs rhs
_ -> return ()
where
msg = "Avoid outdated x-prefix in comparisons as it no longer serves a purpose."
msg = "Avoid x-prefix in comparisons as it no longer serves a purpose."
check lhs rhs = sequence_ $ do
l <- fixLeadingX lhs
r <- fixLeadingX rhs
Expand Down

0 comments on commit 5669eb2

Please sign in to comment.