简体   繁体   English

如何在我的 nx 工作区中覆盖 eslint 规则?

[英]How do I override an eslint rule in my nx workspace?

How do I overrride the eslint rules in plugin:@nrwl/nx/typescript ?如何覆盖plugin:@nrwl/nx/typescript中的 eslint 规则? I've made this change to the root of .eslintrc.json .我已经对.eslintrc.json的根进行了更改。

"rules": {
  "@typescript-eslint/member-ordering": "warn"
},

and still get an error after introducing a demonstration violation of the rule并且在引入违反规则的演示后仍然出现错误

D:\me\sample\apps\my-app\src\app\app.component.ts
  16:3  error  Member outOfOrder should be declared before all instance method definitions  @typescript-eslint/member-ordering

✖ 1 problem (1 error, 0 warnings)

Lint errors found in the listed files.

I tried adding the rule change to the overrides section for typescript too.我也尝试将规则更改添加到 typescript 的overrides部分。

There is no way to set this on the root level as your project's .eslintrc.json will always override those changes due to @nrwl/nx/typescript being set in the overrides section.由于在覆盖部分设置了@nrwl/nx/typescript ,因此无法在根级别设置它,因为您的项目的.eslintrc.json将始终覆盖这些更改。

You will unfortunately have to set this is every project in the overrides section.不幸的是,您必须将其设置为覆盖部分中的每个项目。

If you have multiple projects and/or multiple changes that need to be applied, you can extract it into eslint-custom-overrides file and use it as the last in the extends section:如果您有多个项目和/或需要应用多个更改,您可以将其提取到eslint-custom-overrides文件中,并将其用作extends部分中的最后一个:

{
  "extends": ["../../.eslintrc.json"],
  "ignorePatterns": ["!**/*"],
  "overrides": [
    {
      "files": ["*.ts"],
      "extends": [
        "plugin:@nrwl/nx/typescript",
        "../../eslintrc-custom-overrides.json"
      ],
   },
   ...
  ],
  ...
}

Your eslintrc-custom-overrides.json would look like this:你的eslintrc-custom-overrides.json看起来像这样:

{
  "overrides": [
    {
      "files": ["*.ts"],
      "rules": {
         "@typescript-eslint/member-ordering": "warn"
      }
    }
  ]
}

Check for more details on the NX Issue .查看有关NX 问题的更多详细信息。

I have found a solution that works great for me that avoids any copy pasting (that I found unacceptable) and more or less goes against the "not possible" assertion in the accepted answer.我找到了一个对我很有用的解决方案,它可以避免任何复制粘贴(我认为这是不可接受的),并且或多或少地违背了已接受答案中的“不可能”断言。 The key for me was not using the file based overrides and do extends instead.对我来说,关键不是使用基于文件的覆盖,而是使用扩展。 It works great and does exactly what I want it to do (and not seeing any downsides).它工作得很好,并且完全符合我的要求(并且没有看到任何缺点)。 Hope it helps:希望能帮助到你:

A NextJS / React UI project一个 NextJS / React UI 项目在此处输入图像描述

A config for a NodeJS GraphQL project NodeJS GraphQL 项目的配置

在此处输入图像描述

A config for all NextJS / UI Projects所有 NextJS / UI 项目的配置

在此处输入图像描述

A config for everything that can be overridden by anything above可以被上述任何内容覆盖的所有内容的配置

在此处输入图像描述

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

相关问题 如何覆盖此ESLint TypeScript规则? - How do I override this ESLint TypeScript rule? 我可以在 eslint 配置中编写自己的自定义规则吗? - Can I write my own custom rule in eslint config? 如何修复 spawn ENAMETOOLONG 错误 nrwl nx 工作区 - How to fix spawn ENAMETOOLONG error nrwl nx workspace NX 工作区,如何使用 cli 更改 Angular 应用程序名称? - NX workspace, how to change an Angular app name with the the cli? 如何在 nx 工作区的 VSCode 中运行 NextJS 客户端调试器 - How to run NextJS client side debugger in VSCode in nx workspace 如何在 nrwl nx 工作区中使用标签运行 cypress 测试 - How to run cypress tests with tags in nrwl nx workspace 如何使用反应开发服务器禁用 @typescript-eslint/no-unused-vars 规则 - How can I disable @typescript-eslint/no-unused-vars rule with react dev server 我将 eslint 文档中的所有推荐规则添加到 my.eslintrc.js 文件中,它们都抛出“未找到规则的定义” - I added all the recommended rules from the eslint docs to my .eslintrc.js file and they all throw 'Definition for rule was not found' eslint 为什么我的插件显示未找到规则定义? - eslint why does my plugin show Definition for rule was not found? 如何解决我的 TypeScript/ESLint/Webpack 转译问题 - How can I solve my TypeScript/ESLint/Webpack transpiling problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM