Set default error level to WARN

Viewed 2228

It seems that default error level for all eslint rules are "error". This is annoying as my app doesn't compile even for an omitted semicolon.

How can I set it to "warn" so that my app compiles but shows warnings?

I know I can set each rule to warn manually but I'd prefer to do it globally. In the official docs I haven't found such option.

This my config in .eslingtrc.js:

// http://eslint.org/docs/user-guide/configuring

module.exports = {
  root: true,
  parser: 'babel-eslint',
  parserOptions: {
    sourceType: 'module'
  },
  env: {
    browser: true,
  },
  // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
  extends: 'standard',
  // required to lint *.vue files
  plugins: [
    'html'
  ],
  // add your custom rules here
  'rules': {
    // allow paren-less arrow functions
    'arrow-parens': 0,
    'indent': 1,
    // allow async-await
    'generator-star-spacing': 0,
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
    'padded-blocks': [1, {classes: 'always'}],
    'semi': 1
  }
}
2 Answers

You can use eslint plugin eslint-plugin-only-warn or use the same method as it done in this plugin by patching verify function

If you still need some rules to trigger a full error (eslint-plugin-only-warn will not allow you to do this), you could try the fork eslint-plugin-switch-error-warn (full disclosure - 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.

Related