Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SC2102 issues wrong warning in negated character class #1706

Closed
2 tasks done
rillig opened this issue Sep 27, 2019 · 5 comments
Closed
2 tasks done

SC2102 issues wrong warning in negated character class #1706

rillig opened this issue Sep 27, 2019 · 5 comments

Comments

@rillig
Copy link

rillig commented Sep 27, 2019

For bugs

  • SC2102
  • online
  • The rule's wiki page does not already cover this
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit

Here's a snippet or screenshot that shows the problem:

#! /bin/sh

case $1 in
[!!]) echo wrong
esac

Here's what shellcheck currently says:

Line 4:
[!!]) echo wrong
^-- SC2102: Ranges can only match single chars (mentioned due to duplicates).

Here's what I wanted or expected to see:

No warning since the first ! is for negation, and the second ! is literal.

@koalaman
Copy link
Owner

Nice catch! This has now been fixed, thanks!

@rillig
Copy link
Author

rillig commented Sep 29, 2019

According to POSIX, only the ! character means negation:

A bracket expression starting with an unquoted <circumflex> character produces unspecified results.

This could be reason enough to provide another warning. I checked that the NetBSD /bin/sh supports it since March 2017. I'm not sure about the other shells.

@willholen
Copy link

Such a warning is already in place when you use #!/bin/sh

@bsdshell
Copy link

bsdshell commented Oct 1, 2019

Hi,
how to disable all the warnings?
can I just enable all the errors?
shellcheck on SpaceEmacs.

@koalaman
Copy link
Owner

koalaman commented Oct 1, 2019

@bsdshell You can use shellcheck -S error. I don't know how you'd set this up in SpaceEmacs, but shellcheck will at least look for an environment variable export SHELLCHECK_OPTS='-S error'

Kangie pushed a commit to Kangie/shellcheck that referenced this issue Feb 27, 2023
Merge of upstream through 5c7d812

Conflicts:
	src/ShellCheck/Analytics.hs

Manual changes:
        Cleaned up mintor conflicts in variables with spaces lists.

Changelog:
----------------------------------------------------------------
Benjamin Gordon (12):
      CHROMIUM: Exclude from CQ
      CHROMIUM: Initial support for portage
      CHROMIUM: Disable SC2155 for portage files
      CHROMIUM: Make SC2164 recommend die when running in portage
      CHROMIUM: Add predefined portage variables
      CHROMIUM: Add OWNERS file
      CHROMIUM: Add eclass variables to portage lists
      CHROMIUM: Don't warn about missing find paths in portage
      CHROMIUM: Add more internal portage variables
      CHROMIUM: Disable SC2016 for python_gen_any_dep
      CHROMIUM: Exempt more commands from single quote warnings
      SC2256: Check for translated strings matching known variables

David Burger (1):
      Remove binhost-pre-cq from COMMIT-QUEUE.ini.

Laurent VERDOÏA (1):
      Make image build process a bit simpler

Merlin Göttlinger (1):
      Nix install instructions

Supanat Pothivarakorn (1):
      Allow `read -t 0` to not require -r flag

Vidar Holen (29):
      Make `-f diff` stop saying it found more issues when it didn't.
      Update TravisCI config for new winghc docker image
      Remove _cleanup now that builds don't run in sequence
      Suggest quoting case patterns, as for SC2053 (fixes koalaman#1682)
      Fix glob range duplicate warning in [!!] (fixes koalaman#1706)
      Suggest using `$((..))` in `[ 2*3 -eq 6 ]` (fixes koalaman#1641)
      Merge branch 'read-t-0' of https://github.com/iboss-ptk/shellcheck into iboss-ptk-read-t-0
      Make `read -t 0` test more forgiving towards other flags
      Move failing test to correct check
      Merge branch 'iboss-ptk-read-t-0'
      Warn about unexpected characters after ]/]] (fixes koalaman#1680)
      Use single quotes for the format string example in SC2059
      Correctly handle empty variables for SC2086 (fixes koalaman#1722)
      Warn about [ x -ot y ] in POSIX mode
      Only trigger SC1014 when command is a complete word (fixes koalaman#1737)
      For SC2256, make sure the complete string is a variable name
      Merge branch 'translatedVars'
      Merge pull request koalaman#1749 from lvjp/simple-docker-build
      Include missing Semigroup import
      Hide <> from Writer to not conflict with Semigroup
      Update brew before building on macOS due to incompatible Ruby
      Merge pull request koalaman#1735 from gabrielelana/quoted-heredoc
      Merge pull request koalaman#1734 from gabrielelana/braced-regular-for
      Merge pull request koalaman#1716 from ryantig/ryantig-patch-1
      Merge pull request koalaman#1728 from mgttlinger/patch-1
      Support Cabal 3. Man page no longer autobuilds.
      Explicitly add 'mappend' for old GHC versions
      Revert docker image to 18.04 since ld fails on later versions
      Try to search for binary on macOS/Cabal3

Will Bradley (5):
      Allow local in sh scripts even though it isn't officially part of POSIX shell.
      CHROMIUM: stop complaining about 'which' in portage build scripts
      CHROMIUM: portage compatibility: squelch warnings for EBUILD_PHASE_FUNC
      CHROMIUM: increase depth of categorization for Portage files
      CHROMIUM: Implement check for illegal stable KEYWORDS in -9999 cros-workon Ebuilds.

gabriele.lana (2):
      Parse regular `for` with body in curly braces
      Support for heredoc quoted token like `'"FOO"`

ryantig (1):
      Update README.md

 .compile_binaries                     |  23 +-
 .travis.yml                           |   2 +-
 CHANGELOG.md                          |  11 +
 COMMIT-QUEUE.ini                      |  12 +
 Dockerfile                            |   4 +-
 OWNERS                                |   3 +
 README.md                             |   7 +-
 Setup.hs                              |  36 --
 ShellCheck.cabal                      |  12 +-
 manpage                               |   4 +
 shellcheck.1.md                       |   5 +-
 src/ShellCheck/AST.hs                 |   2 +-
 src/ShellCheck/Analytics.hs           | 222 ++++++++++--
 src/ShellCheck/AnalyzerLib.hs         |  38 ++-
 src/ShellCheck/Checker.hs             |   7 +-
 src/ShellCheck/Checks/Commands.hs     |  37 +-
 src/ShellCheck/Checks/ShellSupport.hs |   4 +-
 src/ShellCheck/Data.hs                | 625 +++++++++++++++++++++++++++++++++-
 src/ShellCheck/Formatter/Diff.hs      |  21 +-
 src/ShellCheck/Interface.hs           |  24 +-
 src/ShellCheck/Parser.hs              |  26 +-
 21 files changed, 978 insertions(+), 147 deletions(-)
 create mode 100644 COMMIT-QUEUE.ini
 create mode 100644 OWNERS
 delete mode 100644 Setup.hs
 create mode 100755 manpage

BUG=chromium:1024635
TEST=stack test

Change-Id: I3eb00707cb2f2b4e967d4db430a7e8ca2e41626e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants