简体   繁体   中英

How to use allow: options with eslintrc.js

I am having the following eslintrc.js :

module.exports = {
  extends: ['airbnb-typescript/base'],
  parserOptions: {
    project: './tsconfig.json',
    sourceType: 'module',
  },
  ignorePatterns: ['*.js'],
  rules: {
    'no-underscore-dangle': 0,
    ...
  }
};

And I'd like to include some exceptions with allow: [ /** */ ] . But each time when I am adding this as a key: value property in my file, ESLint returns me an error with the following text: unable to use allow on top level . So the question is, how to achieve such results, with allow?

Long story short, I am unable to use my set of rules with MongoDB _id naming, so I have ESLint just to ignore only _id in variable naming, instead of disabling the naming-convention rule itself.

Is there any way to solve this problem?

It works for me:

"no-underscore-dangle": ["error", { allow: ["_id"] }]

If you are using the @typescript-eslint/naming-convention rule, you may also need to add this:

"@typescript-eslint/naming-convention": [
  "error",
  {
    selector: ["variable"],
    format: ["strictCamelCase", "PascalCase", "UPPER_CASE"],
    filter: {
      regex: "^_id$",
      match: false,
    },
  },
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM