Commit graph

301 commits

Author SHA1 Message Date
Joseph C. Sible
ef51ed3950
Simplify literalEquals 2020-02-08 14:09:17 -05:00
Vidar Holen
9d604ae732
Merge pull request #1822 from yetamrra/arrayindex
SC2191: Tighten index checks
2020-02-08 10:48:07 -08:00
Vidar Holen
1ca0b72329
Merge pull request #1816 from josephcsible/cleanups
Various cleanups and refactorings
2020-02-08 10:38:27 -08:00
Benjamin Gordon
474b23d6e7 SC2191: Tighten index checks
When adding a value containing an equals sign to an indexed array, the
left side is treated as an index if it looks like [N]=val and N is
numeric.  SC2191 currently warns about anything that looks like key=val
even though non-numeric values of key will never be treated as an index.
This causes spurious warnings for the common pattern of building up
program arguments in an array, such as:
  args=(
    --dry-run
    --in="${my_var}"
    --out=/some/path
    -f
  )
  /bin/program "${args[@]}"

Since only numeric expressions can be a valid index for an indexed
array, only emit SC2191 if the left side of a literal string containing
an equals looks numeric.  Other more complicated constructs should still
warn because shellcheck doesn't know if they may evaluate to a numeric
result.  Associative arrays still warn because a non-numeric left side
is a valid subscript.
2020-02-05 16:50:32 -07:00
Joseph C. Sible
e820a5642b Adjust a pattern to get rid of a fromJust 2020-02-02 00:40:22 -05:00
Joseph C. Sible
392b57b8e8 Use maybe instead of isJust and fromJust 2020-02-02 00:27:05 -05:00
Joseph C. Sible
6595e14d25 Adjust a pattern to avoid tail 2020-02-02 00:24:24 -05:00
Joseph C. Sible
115ef29079 Use pattern matching instead of head 2020-02-02 00:16:59 -05:00
Joseph C. Sible
76b798394f Use case matching instead of null
Using null followed by a head, tail, or a partial pattern match is
an anti-pattern. Use case matching instead.
2020-02-01 23:07:16 -05:00
Joseph C. Sible
8a005526cc Use drop instead of splitAt since we only use the second half 2020-02-01 23:04:04 -05:00
Joseph C. Sible
c29b6afa56 Use null instead of comparing with empty lists 2020-02-01 23:04:04 -05:00
Joseph C. Sible
e6e89d68fd Use list comprehensions instead of clunky combinations of map and filter 2020-02-01 23:04:04 -05:00
Joseph C. Sible
f25b8bd03a Use gets instead of fmapping the result of get 2020-02-01 22:50:20 -05:00
Joseph C. Sible
d7278b95f2 Remove unnecessary "map snd" 2020-02-01 22:50:19 -05:00
Joseph C. Sible
5487b3f229 Use sortOn instead of sortBy and comparing 2020-02-01 22:50:18 -05:00
Joseph C. Sible
28978a8b65 Use maybe instead of fromMaybe and fmap 2020-02-01 22:50:17 -05:00
Joseph C. Sible
f5c6771016 Use find instead of listToMaybe and filter 2020-02-01 22:50:16 -05:00
Joseph C. Sible
0f48bb78a5 Remove incorrect otherwise
You're supposed to use otherwise where you need a Boolean, not a pattern
match. This is misleadingly shadowing the real otherwise. Use _ instead.
2020-02-01 22:50:14 -05:00
Joseph C. Sible
93be86f988 Use "drop 1" instead of clumsily rewriting it 2020-02-01 22:50:14 -05:00
Joseph C. Sible
3449e6be21 Get rid of our getOpt, as it already exists as lookup 2020-02-01 22:50:13 -05:00
Joseph C. Sible
2e52c2b56a Use notElem instead of not on the result of elem 2020-02-01 22:50:11 -05:00
Vidar Holen
1696296c0a Make SC2141 trigger more broadly 2020-02-01 16:51:40 -08:00
Vidar Holen
cbcca528ae Merge branch 'iss1724-builtin-support' of https://github.com/jabberabbe/shellcheck into jabberabbe-iss1724-builtin-support 2019-12-21 18:13:07 -08:00
Vidar Holen
83187dafd7 Added a unit test for parsing shell keyword case branches 2019-12-21 17:59:09 -08:00
Gandalf-
3f296a08c1 Issue 1731 Literals in case patterns
https://github.com/koalaman/shellcheck/issues/1731

Any literal except esac is valid pattern in a case statement
2019-12-18 20:23:48 -08:00
Vidar Holen
0f15fa49ba Make SC2230 optional 2019-12-07 16:11:49 -08:00
Vidar Holen
9f578f41a1 Explicitly add 'mappend' for old GHC versions 2019-11-16 11:16:15 -08:00
Vidar Holen
989ac32625
Merge pull request #1734 from gabrielelana/braced-regular-for
Parse regular `for` with body in curly braces
2019-11-15 20:59:51 -08:00
Vidar Holen
2bbfd0570d
Merge pull request #1735 from gabrielelana/quoted-heredoc
Support for heredoc quoted token like `'"FOO"`
2019-11-15 20:27:10 -08:00
Vidar Holen
f44624a9c0 Hide <> from Writer to not conflict with Semigroup 2019-11-14 20:02:25 -08:00
Vidar Holen
c75bbcbd60 Include missing Semigroup import 2019-11-13 22:10:27 -08:00
Vidar Holen
4a63a3a8bd For SC2256, make sure the complete string is a variable name 2019-11-13 21:48:01 -08:00
Benjamin Gordon
2341a4c683 SC2256: Check for translated strings matching known variables
SC2247 already warns about translated strings that look like $"(foo)" or
$"{foo}".  Since typical use of translated strings is to translate whole
messages, a string like $"foo" is likely to be a similar mistake if foo
is the name of an existing variable.  Conversely, a string like
$"foo bar" is potentially meant to be a message id even if foo is a
known variable.

Add a warning for the $"foo" case, but make it separate from the
existing warning so that projects that reuse variable names as their
message ids can separately disable the new warning.
2019-11-13 16:41:16 -07:00
Vidar Holen
93eca1cb8e Only trigger SC1014 when command is a complete word (fixes #1737) 2019-11-03 13:26:23 -08:00
Vidar Holen
e701cf6fad Warn about [ x -ot y ] in POSIX mode 2019-11-03 13:25:35 -08:00
Vidar Holen
5962b01816 Correctly handle empty variables for SC2086 (fixes #1722) 2019-11-03 12:46:25 -08:00
Tito Sacchi
84ca7711c4 Make command-specific checks act on builtin ...
Now if shellchecks encounters a command like `builtin cmd ...`
it applies the same check that would be applied to `cmd ...`.
2019-11-01 14:28:00 +01:00
Tito Sacchi
0e0de94045 Fix issue #1724
(bash: missing support for 'builtin' keyword)
Now shellcheck looks for the arguments to 'builtin' to determine
read/written variables. A change in the parser makes sure that
assignments are parsed correctly in commands that start with 'builtin'.
2019-11-01 13:49:17 +01:00
gabriele.lana
699aac589a Support for heredoc quoted token like '"FOO"
Fixes #1650
2019-10-26 17:36:32 +02:00
gabriele.lana
30c75340e6 Parse regular for with body in curly braces
Fixes #1694
2019-10-26 15:41:46 +02:00
Vidar Holen
4dfd7eb1cf Use single quotes for the format string example in SC2059 2019-10-24 10:33:17 -07:00
Vidar Holen
60f75e5b8a Warn about unexpected characters after ]/]] (fixes #1680) 2019-10-13 20:26:40 -07:00
Vidar Holen
f042b0ebd1 Merge branch 'iboss-ptk-read-t-0' 2019-10-12 20:55:32 -07:00
Vidar Holen
764fdcb260 Move failing test to correct check 2019-10-12 20:50:55 -07:00
Vidar Holen
7473d4a743 Make read -t 0 test more forgiving towards other flags 2019-10-12 20:45:36 -07:00
Vidar Holen
91abd979f2 Merge branch 'read-t-0' of https://github.com/iboss-ptk/shellcheck into iboss-ptk-read-t-0 2019-10-12 20:23:13 -07:00
Vidar Holen
afea62de4e Suggest using $((..)) in [ 2*3 -eq 6 ] (fixes #1641) 2019-10-12 19:55:20 -07:00
Supanat Pothivarakorn
7fb399528c Allow read -t 0 to not require -r flag
since it has specific purpose for checking only
2019-10-02 22:34:43 +07:00
Vidar Holen
de9ab4e6ef Fix glob range duplicate warning in [!!] (fixes #1706) 2019-09-28 14:03:11 -07:00
Vidar Holen
e01c470598 Suggest quoting case patterns, as for SC2053 (fixes #1682) 2019-09-08 20:08:43 -07:00