How to use allow: options with eslintrc.js

Viewed 86

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?

1 Answers

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,
    },
  },
],
Related