Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESlint: Turning off a specific rule across a project

I've read the docs on how to disable rules from within a file, however I'm wondering if there is a way to disable or overwrite rules from .eslintrc without overwriting other previous rules & presets I defined. I'm working in an AngularJS project so I used extends property inside my .eslintrc file.

There are 3 specific rules from the angular ESlint plugin that I would like to disable, without disabling everything else I was using previously.

Without the rules property all of my linting rules work fine (spacing, grammar errors etc), but the two lint errors I don't want show up, naturally. However, with the rules property attached, all of my previous rules no longer get applied (spacing grammar errors etc).

I could just declare a rule to disable the specific rule I don't want applied at the top of my file, but that get's very repetitive (that's what I had done previously).

{
  "rules": {
    "wrap-iife": [
      2,
      "inside"
    ],
    "max-len": [
      2,
      120
    ],
    "indent": [
      2,
      2
    ],
    "no-with": 2,
    "no-implicit-coercion": [
      2, {
        "string": true
      }
    ],
    "camelcase": [
      2, {
        "properties": "never"
      }
    ],
    "quotes": [
      2,
      "single"
    ],
    "linebreak-style": [
      2,
      "unix"
    ],
    "semi": [
      2,
      "always"
    ]
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "ecmaFeatures": {
    "modules": true
  },
  "globals": {
    "angular": true
  },
  "extends": "angular",

  //I just want to disable these rules & still use everything else
  //but when I add this, everything else I had previously no longer
  //applies
  "rules": {
    "angular/controller-as-vm": "off",
    "angular/document-service": "off",
    "angular/window-service": "off"
  }
}
like image 319
Clifford Fajardo Avatar asked May 03 '16 11:05

Clifford Fajardo


2 Answers

In you .eslintrc you have two rules keys. The second will overwrite the first. Here's the file with the rules merged together:

{
  "rules": {
    "wrap-iife": [
      2,
      "inside"
    ],
    "max-len": [
      2,
      120
    ],
    "indent": [
      2,
      2
    ],
    "no-with": 2,
    "no-implicit-coercion": [
      2, {
        "string": true
      }
    ],
    "camelcase": [
      2, {
        "properties": "never"
      }
    ],
    "quotes": [
      2,
      "single"
    ],
    "linebreak-style": [
      2,
      "unix"
    ],
    "semi": [
      2,
      "always"
    ],
    "angular/controller-as-vm": "off",
    "angular/document-service": "off",
    "angular/window-service": "off"
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "ecmaFeatures": {
    "modules": true
  },
  "globals": {
    "angular": true
  },
  "extends": "angular"
}
like image 107
user4040648 Avatar answered Oct 19 '22 01:10

user4040648


ESLint config file that disables all rules individually.

This is a Eslint config (eslintrc.json) file that has all the rules turned off so that you can change your code on a rule by rule basis rather than changing all the code to fit all the rules?

https://github.com/ajmaurya99/eslint-rules

like image 21
Aj Maurya Avatar answered Oct 19 '22 03:10

Aj Maurya