GithubHelp home page GithubHelp logo

Comments (15)

koalaman avatar koalaman commented on July 22, 2024 2

It's per structure, so you can do

shellcheck disable=SC2034
{
AAAA=aaaa
BBBB=bbbb 
CCCC=cccc 
DDDD=dddd
}

from shellcheck.

servel333 avatar servel333 commented on July 22, 2024 2

I actually don't want to disable this warning for all files I'm checking, just specific ones.

from shellcheck.

cooljeanius avatar cooljeanius commented on July 22, 2024

I would find this feature useful

from shellcheck.

koalaman avatar koalaman commented on July 22, 2024

From 43ed5e7 you can use # shellcheck disable=SC1234,SC5678. It's scoped to the immediate pipeline and any &&/|| following it.

It's worth noting that errors in a shellcheck directive (# shellcheck...) is a parsing error by design. This lets shellcheck tell you why # shellcheck ignore=1234:5678 is wrong, but also means that parsing stops if you've written # shellcheck doesn't like this.

I'd appreciate any feedback people have for this feature!

from shellcheck.

pihentagy avatar pihentagy commented on July 22, 2024

How can I disable the ps|grep warning here:

echo -n " zombie: $(ps -e -o state  | grep Z | wc -l) "

from shellcheck.

koalaman avatar koalaman commented on July 22, 2024
# shellcheck disable=SC2009
echo -n " zombie: $(ps -e -o state  | grep Z | wc -l) "

from shellcheck.

pihentagy avatar pihentagy commented on July 22, 2024

Thank you, I made a a dumb error: I had typo in the warning id, that's why it seemed not to work.

from shellcheck.

geoffmeyers avatar geoffmeyers commented on July 22, 2024

feedback is that it works great. maybe add it to the --help docs for ease of use?

from shellcheck.

servel333 avatar servel333 commented on July 22, 2024

It appears the directive will only apply to the line following the directive. For example:

# shellcheck disable=SC2034
AAAA=aaaa # < No 'appears unused'
BBBB=bbbb # < Getting 'appears unused' error
# shellcheck disable=SC2034
CCCC=cccc # < No 'appears unused'
DDDD=dddd # < Getting 'appears unused' error

I would expect the shellcheck directive to disable all of this error in the file, but if we need backwards compatibility, I would like a way to disable all of a specific type of error for the whole file.

My usecase: I have a dotenv file where I am declaring a lot of variables that I'm never using, because they are getting used in other files in my application. I would like to use shellcheck to syntax check the file but I don't need any 'appears unused' errors as they are irrelevant to my use.

I would strongly prefer not to have to write a shellcheck disable for each line in my file...

from shellcheck.

servel333 avatar servel333 commented on July 22, 2024

I used that method to solve my problem and it did work in my case, however I dislike the idea of having to change my code structure in order to make an ignore rule function. I would prefer to see a different directive to make all instances ignored.

Thanks for the feature though, it works great otherwise and this linter is very helpful for showing me some best-practices that I didn't know about.

from shellcheck.

koalaman avatar koalaman commented on July 22, 2024

Thanks, glad you like it!

In the near future you're likely to see file-wide ignores, but right now they're per structure

from shellcheck.

servel333 avatar servel333 commented on July 22, 2024

Understood. Thanks.

from shellcheck.

brother avatar brother commented on July 22, 2024

@servel333 also remember that you can disable it on the command line, might hide valid warnings in other files if you are processing more than one in a single go though. Just mentioning it as it looks like it's missing in this thread.

brother ~$ cat /tmp/test.sh
#!/bin/sh

echo "--no quote--"
for i in ${TMPDIR:=/tmp}; do echo "$i"; done
echo "------------"

echo "--- quote---"
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
echo "------------"

# shellcheck disable=SC2034
AAAA=aaaa # < No 'appears unused'
BBBB=bbbb # < Getting 'appears unused' error
# shellcheck disable=SC2034
CCCC=cccc # < No 'appears unused'
DDDD=dddd # < Getting 'appears unused' error
brother ~$ shellcheck /tmp/test.sh 

In /tmp/test.sh line 8:
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
         ^-- SC2066: Since you double quoted this, it will not word split, and the loop will only run once.


In /tmp/test.sh line 13:
BBBB=bbbb # < Getting 'appears unused' error
^-- SC2034: BBBB appears unused. Verify it or export it.


In /tmp/test.sh line 16:
DDDD=dddd # < Getting 'appears unused' error
^-- SC2034: DDDD appears unused. Verify it or export it.

brother ~$ shellcheck /tmp/test.sh -eSC2034

In /tmp/test.sh line 8:
for i in "${TMPDIR:=/tmp}"; do echo "$i"; done
         ^-- SC2066: Since you double quoted this, it will not word split, and the loop will only run once.

from shellcheck.

servel333 avatar servel333 commented on July 22, 2024

I didn't know you could disable it in the command line like that. I'm using Sublime that's auto-running the command though and so for my use case it doesn't solve my problem. Good to know though, thanks.

from shellcheck.

koalaman avatar koalaman commented on July 22, 2024

If Sublime isn't configurable you can set SHELLCHECK_OPTS in recent versions of shellcheck

from shellcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.