Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change "eslint:recommended" to warnings

Tags:

eslint

I am using

"extends": "eslint:recommended",

in my .eslintrcfile. These rules fail the lint by default. Is there a way for me to change all of them to warnings without having to specify each one individually? So, is there a way to change the rule level en-masse for an extended rule set?

For example, I would love to be able to do something like:

"extends": [
  ["eslint:recommended", 1]
],
like image 261
Matthew Herbst Avatar asked Sep 03 '15 22:09

Matthew Herbst


2 Answers

You can use the eslint plugin eslint-plugin-only-warn if you need to change all ESLint errors to warnings.

If you still need some rules to trigger a full error, you could try this fork of only-warn, eslint-plugin-switch-error-warn (disclaimer - I am the fork author). It switches errors to warnings and visa versa, so you can set specific rules to "warn" to make them trigger errors again. This will give you the added functionality to specify exceptions, though it might get rather confusing!

You will also need to set any rules that default to warning (such as 'no-console') to 'error' mode explicitly, to get them to only give warnings with the switcher plugin.

like image 141
Geoff Davids Avatar answered Oct 09 '22 02:10

Geoff Davids


As mentioned by @Gyandeep, no: http://eslint.org/docs/user-guide/configuring.html#configuring-rules

I wrote a script to make it a little less painful for you:

#!/bin/sh

list=$(curl -silent http://eslint.org/docs/rules/ | grep '(recommended)' | sed -e 's,.*<a .*>\([^<]*\)</a>.*,\1,g' | grep -v 'configuration documentation')

for rule in ${list}; do
    echo \"$rule\": 1,
done;

That'll result in:

"comma-dangle": 1,
"no-cond-assign": 1,
"no-console": 1,
"no-constant-condition": 1,
"no-control-regex": 1,
"no-debugger": 1,
"no-dupe-args": 1,
"no-dupe-keys": 1,
"no-duplicate-case": 1,
"no-empty-character-class": 1,
"no-empty": 1,
"no-ex-assign": 1,
"no-extra-boolean-cast": 1,
"no-extra-semi": 1,
"no-func-assign": 1,
"no-inner-declarations": 1,
"no-invalid-regexp": 1,
"no-irregular-whitespace": 1,
"no-negated-in-lhs": 1,
"no-obj-calls": 1,
"no-regex-spaces": 1,
"no-sparse-arrays": 1,
"no-unreachable": 1,
"use-isnan": 1,
"valid-typeof": 1,
"no-fallthrough": 1,
"no-octal": 1,
"no-redeclare": 1,
"no-delete-var": 1,
"no-undef": 1,
"no-unused-vars": 1,
"no-mixed-spaces-and-tabs": 1,

If you look here: http://eslint.org/docs/rules/ you'll note the rules included by eslint:recommended are followed by (recommended). The script pulls the website, geps the lines with (recommended) then uses sed to do some regex magic that extracts the rule from the anchor tags.

Don't forget to take out the last , - I have to leave something for you to do ;) - and insert this in your .eslintrc file between:

"rules": {
   ...output of script goes here...
}

If you're not familiar with bash scripts, don't forget to make it executable... even easier, just copy the output I pasted above! :)

Hope this helps.

like image 5
jpoveda Avatar answered Oct 09 '22 01:10

jpoveda