Excluding eslint rule from package.json

I have succesfully excluded some stylelint rules before by adding this to my theme’s package.json file:

  ...
  "stylelint": {
    "extends": "stylelint-config-standard",
    "rules": {
      "no-empty-source": null
    }
  },
  ...

I’m trying to do the same as I have a function in my common.js route that is called from a wp plugin (and not from my own script).

I tried adding this to my package.json file:

  "eslintConfig": {
    "extends": "eslint:recommended",
    "rules": {
      "no-unused-vars": "off"
    }
  },

Also tried the above with eslint instead of eslintConfig.

And I added eslint comment to my function:

var myfunction = function() {
      console.log('Hello World!');
    }; // eslint-disable-line no-unused-vars

But none of the above works, my .js keeps from compiling. Any thoughts?

wrong file i think? have you tried this one? https://github.com/roots/sage/blob/master/.eslintrc.js

3 Likes

For my scss files, I have also found stylelint-disable with stylelint-enable very useful when I just want to ignore linting for specific blocks of scss code, such as:

/* stylelint-disable */

* {
  &:focus:not(:focus-visible) {
    outline: none;
  }
}

/* stylelint-enable */