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

I can't set linting options #3102

Closed
jfoclpf opened this issue Feb 19, 2017 · 21 comments
Closed

I can't set linting options #3102

jfoclpf opened this issue Feb 19, 2017 · 21 comments

Comments

@jfoclpf
Copy link

jfoclpf commented Feb 19, 2017

I have a config.json file

{
  "eqeqeq": false
}

I typed

jshint --config "/path/to/my/config.json"

and still I get errors/warnings regarding "==" and "==="

What is wrong?

@jfoclpf jfoclpf changed the title "eqeqeq" option doesn't seem to work I can't set linting options Feb 19, 2017
@jfoclpf
Copy link
Author

jfoclpf commented Feb 19, 2017

Also I tried the following file package.json in the working directory where I execute jshint and where myfile.js is stored

{
    "jshintConfig": {
        "eqeqeq": false,
        "evil": false,
        "multistr": false
    }
}

then I typed:

jshint myfile.js

and still the linting options do not take effect.

Could anyone kindly help!? I'm working around for 1 day and I can't figure out what I am doing wrong.

@nicolo-ribaudo
Copy link
Contributor

Does it work if you use eqeqeq: true?

@jfoclpf
Copy link
Author

jfoclpf commented Feb 19, 2017

Nope, now as I type jshint --config "/path/to/my/config.json" I get Error:SyntaxError: Unexpected token e.

And according to the documentation when set to true, these options will make JSHint produce more warnings about your code.

edit: I set "eqeqeq": true and the warnings persist. Any ideas? Is there a command to confirm that jshint really accepted the config.json?

@jugglinmike
Copy link
Member

This is very strange. Could you share the input code, preferably reduced as
much as possible? Could you also let us know which version of JSHint you are
using (via jshint --version)?

@jfoclpf
Copy link
Author

jfoclpf commented Feb 19, 2017

Sure

The version I'm using is v2.9.4

Here it goes the input code:
capturar

@jugglinmike
Copy link
Member

By "the input code," I meant, "the JavaScript program that you are linting."

@jfoclpf
Copy link
Author

jfoclpf commented Feb 20, 2017

Sure, I attach here

The first error appears, as you can see on the above shell, on line 63, which is simply:

    if(length==0){
        return null;
    }

myscript.zip

@jfoclpf
Copy link
Author

jfoclpf commented Feb 20, 2017

If I try a file with only this simple code, it gives the same warning

function test(input_var){
    if (input_var == 0){
        return true;
    }
    else{
        return false;
    }  
}

But it seems that it appears only while comparing with '0', because this code gives no error

function test(input_var){
    if (input_var == 1){
        return true;
    }
    else{
        return false;
    }  
}

Is it supposed to be like that?

@jugglinmike
Copy link
Member

The eqeqeq option is an "enforcing option," meaning that it should only
produce warnings when set to true. You have identified an inconsistency in
JSHint's enforcement of this particular linting rule.

The option's description states, "This options prohibits the use of == and !=
in favor of === and !==." Enabling it will cause JSHint to issue warning
W118 for offending code. However, JSHint will issue a separate warning (W041)
if either side of the comparison is a "falsey" literal value, regardless of
the value of the eqeqeq option
.

The long-term resolution for the project, removing W041 altogether. It's a
shame because it makes JSHint less strict by default, but the current behavior
is inconsistent and confusing. And while the warning message for W041 is far
more descriptive (and therefore a better choice to keep around), we can't
change W118 in-place outside of a major version release. This should be
relatively straightforward, so I've marked this issue as a "good first bug."

The short-term resolution for users is to disable W041 in your project
configuration, either with an in-line directive:

// jshint -W041

Or within a JSHint configuration file:

{
  "-W041": true
}

@jugglinmike jugglinmike changed the title I can't set linting options Comparison operators ==/!== reported too aggressively Feb 25, 2017
@jfoclpf
Copy link
Author

jfoclpf commented Feb 25, 2017

Thank you for your message

But your option "-W041": true still gives an error while comparing == with 0

@jugglinmike
Copy link
Member

Can you be more specific? For instance, if I paste the following code into the
editor on http://jshint.com, then I see the warning,

if (x == 0) {}

...then I see the following warning:

One warning

1 Use '===' to compare with '0'.

However, when I insert that option, the warning is suppressed:

// jshint -W041: true
if (x == 0) {}

How does your experience differ?

@jugglinmike jugglinmike changed the title Comparison operators ==/!== reported too aggressively Comparison operators ==/!= reported too aggressively Feb 25, 2017
@jfoclpf
Copy link
Author

jfoclpf commented Feb 25, 2017

I didn't try with the comment // in the .js file.
I simply added this line "-W041": true to the JSON object of the JSHint configuration file.

capturar

@jugglinmike
Copy link
Member

In that case, we'll need to ensure that JSHint is actually reading that file. Can you try deliberately inserting a JSON syntax error--for instance:

{
  "-W041": true,
  this is not valid JSON
}

If everything is configured properly, JSHint should report a syntax error in the configuration file. If it does not, then JSHint isn't reading that file at all.

@jfoclpf
Copy link
Author

jfoclpf commented Feb 26, 2017

It works as you said, it gave an error

capturar

@josephzidell
Copy link

Remove the trailing comma:

{
  "-W041": true
}

@jfoclpf
Copy link
Author

jfoclpf commented Feb 27, 2017

@josephzidell I was told not to by @jugglinmike so we can test the config file, check previous message

@jugglinmike
Copy link
Member

I'm still unable to reproduce the error. This is very tricky. Since it seems to
require multiple files, I've created a standalone project on GitHub to help us
isolate the problem:

https://github.com/jshint/gh-3102

Can you clone that repository, follow the instructions, and let me know what
you find?

@jfoclpf
Copy link
Author

jfoclpf commented Mar 12, 2017

I cloned and I tested.
Exactly as you said:

It seems it is working

capturar

@jfoclpf
Copy link
Author

jfoclpf commented Mar 12, 2017

It seems that it does not save the configuration file, because when I run just in one line, it works, but when I use in two command lines, it doesn't work

it doesn't work

./node_modules/.bin/jshint --config cfg_jshint.json
./node_modules/.bin/jshint myscript.js

it does work

./node_modules/.bin/jshint --config cfg_jshint.json myscript.js

It's working now 👍
Even the other version, I need to run the command in only one line.

@jugglinmike
Copy link
Member

jugglinmike commented Mar 12, 2017

Ah, yes--the command-line interface is stateless, so one invocation will not
effect the next (note that this may change in the future, though--we recently
received a feature request for result caching
).

This issue has grown a bit unwieldy, making it a little confusing for use as a
bug report. I've created gh-3109 to track the bug and reverted this issue's
title to the original previous value.

Glad we got to the bottom of this one!

@jugglinmike jugglinmike changed the title Comparison operators ==/!= reported too aggressively I can't set linting options Mar 12, 2017
@jfoclpf
Copy link
Author

jfoclpf commented Mar 12, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants