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

Config file location #3107

Open
pa-0 opened this issue Dec 28, 2024 · 1 comment
Open

Config file location #3107

pa-0 opened this issue Dec 28, 2024 · 1 comment

Comments

@pa-0
Copy link

pa-0 commented Dec 28, 2024

Hi, I'm looking for clarification after consulting shellcheck's man:

  1. Will shellcheck find a config file if it's located at $XDG_CONFIG_HOME/shellcheck/shellcheckrc?
  2. Are the paths that are searched hardcoded? In other words, will it use the value assigned to XDG_CONFIG_HOME if set?

Thanks

@brother
Copy link
Collaborator

brother commented Jan 7, 2025

The man states

Unless --norc is used, ShellCheck will look for a file .shellcheckrc
or shellcheckrc in the script's directory and each parent directory.
...
If no .shellcheckrc is found in any of the parent directories, ShellCheck
will look in ~/.shellcheckrc followed by the XDG config directory
(usually ~/.config/shellcheckrc) on Unix, or %APPDATA%/shellcheckrc on
Windows. Only the first file found will be used.

To answer the questions then:

  1. Will shellcheck find a config file if it's located at $XDG_CONFIG_HOME/shellcheck/shellcheckrc?

No it will not find that file. If you can place it in $XDG_CONFIG_HOME/.shellcheckrc it should work, but that does not seem to be the case... see below.

(Please also note the special care needed by people using snaps and docker and such, it's in the man file as well.)

brother /tmp$ cat $XDG_CONFIG_HOME/shellcheck/shellcheckrc
enable=require-double-brackets
brother /tmp$ shellcheck test.sh

In test.sh line 3:
if [ $1 ]; then
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
if [ "$1" ]; then

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
brother /tmp$ mv $XDG_CONFIG_HOME/shellcheck/shellcheckrc $XDG_CONFIG_HOME/.shellcheckrc
brother /tmp$ shellcheck test.sh

In test.sh line 3:
if [ $1 ]; then
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
if [ "$1" ]; then

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
brother /tmp$ shellcheck --rcfile=$XDG_CONFIG_HOME/.shellcheckrc test.sh 

In test.sh line 3:
if [ $1 ]; then
   ^----^ SC2292 (style): Prefer [[ ]] over [ ] for tests in Bash/Ksh.
     ^-- SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean: 
if [[ "$1" ]]; then

For more information:
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
  https://www.shellcheck.net/wiki/SC2292 -- Prefer [[ ]] over [ ] for tests i...

If no mistakes can be pointed out here I think this should be treated as a bug, at least between documentation and behavior =)

  1. Are the paths that are searched hardcoded? In other words, will it use the value assigned to XDG_CONFIG_HOME if set?

It is supposed to respect the environment set.

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

2 participants