Skip to content

Commit dff8f94

Browse files
committed
Improve SC2283 message and position
1 parent 2e5c56b commit dff8f94

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ShellCheck/Analytics.hs

+9-3
Original file line numberDiff line numberDiff line change
@@ -4236,16 +4236,22 @@ checkSecondArgIsComparison _ t =
42364236
case argString of
42374237
'=':'=':'=':'=':_ -> Nothing -- Don't warn about `echo ======` and such
42384238
'+':'=':_ ->
4239-
return $ err (getId t) 2285 $
4239+
return $ err (headId t) 2285 $
42404240
"Remove spaces around += to assign (or quote '+=' if literal)."
42414241
'=':'=':_ ->
42424242
return $ err (getId t) 2284 $
42434243
"Use [ x = y ] to compare values (or quote '==' if literal)."
42444244
'=':_ ->
4245-
return $ err (getId t) 2283 $
4246-
"Use [ ] to compare values, or remove spaces around = to assign (or quote '=' if literal)."
4245+
return $ err (headId arg) 2283 $
4246+
"Remove spaces around = to assign (or use [ ] to compare, or quote '=' if literal)."
42474247
_ -> Nothing
42484248
_ -> return ()
4249+
where
4250+
-- We don't pinpoint exactly, but this helps cases like foo =$bar
4251+
headId t =
4252+
case t of
4253+
T_NormalWord _ (x:_) -> getId x
4254+
_ -> getId t
42494255

42504256
return []
42514257
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])

0 commit comments

Comments
 (0)