简体   繁体   English

如何使用 allow: 带有 eslintrc.js 的选项

[英]How to use allow: options with eslintrc.js

I am having the following eslintrc.js :我有以下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: [ /** */ ] .我想包括一些例外情况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 .但是每次当我在我的文件中将其添加为 key: value 属性时,ESLint 都会返回一个错误,并显示以下文本: unable to use allow on top level So the question is, how to achieve such results, with allow?那么问题来了,如何通过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.长话短说,我无法将我的规则集与 MongoDB _id命名一起使用,所以我有 ESLint 只是为了忽略变量命名中的_id ,而不是禁用命名约定规则本身。

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规则,您可能还需要添加以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取.eslintrc.js忽略所有无js文件 - How to get .eslintrc.js ignore all none js files 必须使用import加载ES Module.eslintrc.js - Must use import to load ES Module .eslintrc.js .eslintrc.js键,带“-”(破折号) - .eslintrc.js keys with “-” (dash) React Native 中的“.eslintrc.js”是什么? - What is “.eslintrc.js” in React Native? 在 .eslintrc.js 文件中使用导出默认值而不是 module.exports - Use export default in .eslintrc.js file instead of module.exports 错误:.eslintrc.js 中的 ESLint 配置无效:-意外的顶级属性“文件” - Error: ESLint configuration in .eslintrc.js is invalid: - Unexpected top-level property "files" env.es6=true 和 parserOptions.ecmaVersion=6 at.eslintrc.js 有什么区别? - What the difference between env.es6=true and parserOptions.ecmaVersion=6 at .eslintrc.js? npm init nuxt-app 结果出现问题“无法加载在‘.eslintrc.js » @nuxtjs/eslint-config’中声明的插件‘unicorn’” - npm init nuxt-app results a problem "Failed to load plugin 'unicorn' declared in '.eslintrc.js » @nuxtjs/eslint-config'" ESLint 8.31.0“错误:无法加载在‘.eslintrc.js » eslint-config-standard’中声明的插件‘import’:找不到模块‘array.prototype.flatmap’” - ESLint 8.31.0 "Error: Failed to load plugin 'import' declared in '.eslintrc.js » eslint-config-standard': Cannot find module 'array.prototype.flatmap" 如何在 eslintrc 文件中使用导入? - How to use import inside eslintrc file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM