How to end the linter's tyranny?
-
Hello!
I’m new to this. I’ve started building some stuff in Quasar, testing it live withquasar dev
, and it’s very nice.
Only problem is the linter who insists on telling me how I should format my code and doesn’t let it compile when he finds any reason to nitpick on it.
I strongly disagree with many of his authoritarian rules and want to end this tyranny.
I tried it with editing the ‘.eslintrc.js’, adding rules like so:// add your custom rules here 'rules': { 'quotes': 0, 'semi': 0, 'space-infix-ops': 0, 'indent': 0, 'spaced-comment': 0, 'eol-last': 0, 'no-unused-vars': 0, 'space-before-function-paren': 0, 'space-unary-ops': 0, 'key-spacing': 0, "comma-dangle": 0,
I think he accepted some of these overrulings, but most he does not. (Not sure which and what all of these mean atm., but for example the comma-dangle is a point of disagreement where my ruling is ignored.)
Is there anything wrong with how I stated the rules? I just googled them and thought
0
translates to “STFU” for all of these rules.Thanks in advance for any hints on how to fix this!
-
Not all rules are boolean AFAIK, for instance, for comma-dangle. https://eslint.org/docs/rules/comma-dangle
Scott
-
I agree with your desire to end his Tyranny, though part of me secretly thinks I should just give into it.
Anyway, if you want to learn more about what the rules are (or can be set to), I found Airbnb’s Javascript guide to be very helpful. Each rule shows which eslint setting are related to it. https://github.com/airbnb/javascript
-
Thanks for the hint!
I had already found that site, but I can’t seem to make sense of its instructions, e.g. for the the comma-dangle rule in particular.
I tried:"comma-dangle": ["error", "ignore"],
which I thought should be a valid option. Although I have no idea what the “error” is supposed to mean, especially when I don’t want to get any error at all.
It was just that all examples included["error", ...
in the beginning, without an explanation what that means and what alternatives there are for “error”, if any.
Anyway, this did not work.
So I tried just a simple string value:"comma-dangle": "ignore",
which also had no effect.
The same applies for
space-(before/after)-function-paren
and some other rules, which also has this strange["error", ...]
format in the eslint examples, without explanation what the significance of that first array element “error” is supposed to be. Whatever I try to set there, even copied directly from the examples, does not seem to get accepted. -
The first value “error” means it kills the process after finding the non-rule-matching error in your code. That means, compiling will stop and you have to fix your code accordingly.
The other values you can add are “off” and “warn”. So, theoretically,
'comma-dangle': 'off'
Should turn it off. Or,
'comma-dangle': ['warn', { 'arrays': 'always', 'objects': 'always', 'imports': 'always', 'exports': 'always', 'functions': 'always' }] }
That should get you warnings, when you haven’t added commas behind the listed code syntax types.
Disclaimer, I am no expert here either. So, I’m not going from experience, but rather deduction from reading the docs too.
Btw, I also just read, setting a “0” as you did, should turn off the rule completely. So, I am no longer sure what is the real issue.
Oh, and please also make sure you are using single quotes.
Scott
-
The other values you can add are “off” and “warn”.
Thanks for this enlightening piece of info that I somehow did not find before. Now I understand.
Oh, and I found out what the problem is: The
.eslintrc.js
is not hot-reloaded when runningquasar dev
. I just had to restartquasar dev
and he then he accepted my rules. Heureka! -
Oh my! Glad you found it! The tyranny is over…for you. We servants to the Linter Standard God love no dangling commas, single quotes, no semicolons, two spaces, no spaces at end of lines, extra line at end of files and the rest.
Scott