ESlint: Turning off a specific rule across a project

11,100

Solution 1

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"
}

Solution 2

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

Share:
11,100
Clifford Fajardo
Author by

Clifford Fajardo

I love creating for the web! In this area, I'm passionate about: Working on Web infrastructure, developer tooling and reverse engineering technologies I use to learn and for fun Creating web experiences that are fast, accessible & delight to use. Interests: Web Platform, Typescript/Open Source Research & Software, Developer tooling, PKM/BASB🧠, Education & Communities

Updated on July 20, 2022

Comments

  • Clifford Fajardo
    Clifford Fajardo almost 2 years

    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"
      }
    }
    
  • Clifford Fajardo
    Clifford Fajardo about 8 years
    Wow - that was it. Thank you!