ryan
ryan

Reputation: 6655

Overriding eslint rule

I can't seem to override the behavior of "no-use-before-define". I don't want to be warned when a function is used before defined. I've tried disabling & re-enabling the ESLint service in VS Code but with no success.

warning example

VS Code Extensions: ESLint, Prettier

.eslintrc

{
  "env": {
    "browser": true
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "airbnb",
    "plugin:@typescript-eslint/recommended",
    "prettier",
    "prettier/@typescript-eslint",
    "prettier/react",
    "prettier/standard",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    }
  },
  "rules": {
    "no-use-before-define": ["error", { "functions": false, "classes": true }]
  }
}

.prettierrc.js

module.exports = {
  semi:  true,
  trailingComma:  'all',
  singleQuote:  true,
  printWidth:  120,
  tabWidth:  2,
  endOfLine: 'auto',
}

Upvotes: 4

Views: 4385

Answers (2)

jtbandes
jtbandes

Reputation: 118781

I was able to use your configs on a small .tsx file after installing several node modules. It seems like the solution is just: rather than

"no-use-before-define": ["error", { "functions": false, "classes": true }]

it seems you need to use

"@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": true }]

because the error is coming from @typescript-eslint.

Upvotes: 9

Abel Mekonnen
Abel Mekonnen

Reputation: 1915

If all is lost then you can specify rule for a single line using the below command.

/*eslint-disable */

//It will disable all the warnings between comments
alert('eslint disabled');

//To enable just add the below line of code.
/*eslint-enable */

Upvotes: 1

Related Questions