简体   繁体   English

ESLint 禁用带有模式的特定规则

[英]ESLint disable specific rule with pattern

So I am new to ESLint, and want to disable a specific rule I don't like, but I don't know which is it and how to.所以我是 ESLint 的新手,想禁用我不喜欢的特定规则,但我不知道它是什么以及如何。

So my.eslintrc.js looks like this:所以 my.eslintrc.js 看起来像这样:

module.exports = {
    root: true,
    env: {
        node: true,
        es2021: true,
    },
    extends: ['eslint:recommended', 'prettier'],
    parserOptions: {
        ecmaVersion: 12,
        sourceType: 'module',
    },
    plugins: ['prettier'],
    rules: {
        'prettier/prettier': [
            1,
            {
                trailingComma: 'es5',
                singleQuote: true,
                semi: true,
                tabWidth: 4,
                printWidth: 120,
            },
        ],
        ...require('eslint-config-prettier').rules,
        'no-unused-vars': 'off',
    },
};

And in routes, for each route I have an async wrapper function called "aW".在路由中,对于每条路由,我都有一个名为“aW”的异步包装器 function。 Because of this, eslint is warning me and trying to break the lines, and I don't really like that.正因为如此,eslint 警告我并试图打破界限,而我真的不喜欢那样。 So it looks like this:所以它看起来像这样:

在此处输入图像描述

and I want to keep it like that.我想保持这种状态。

But when I format that file, it turns to this:但是当我格式化该文件时,它变成了这样:

在此处输入图像描述

which I really don't like...我真的不喜欢...

How can I disable that rule (maybe with pattern if line contains "aW"), but without commenting each line with "// eslint-ignore"如何禁用该规则(如果行包含“aW”,则可能使用模式),但不使用“// eslint-ignore”注释每一行

Even though Prettier is configured in your ESLint configuration file as an ESLint rule via an integration plugin ( prettier-eslint-plugin ), it's a separate project from ESLint.即使 Prettier 通过集成插件( prettier-eslint-plugin )在您的 ESLint 配置文件中配置为 ESLint 规则,它也是一个独立于 ESLint 的项目。 The point of Prettier is to cede control over such details of formatting to focus on more important things. Prettier 的重点是放弃对这些格式细节的控制,以专注于更重要的事情。 If you still want that control, like where lines should break and so on, Prettier probably isn't for you as you can't customize these things using it and it's intentionally been made that way .如果你仍然想要那种控制,比如应该在哪里换行等等,Prettier 可能不适合你,因为你不能使用它来定制这些东西,而且它是故意这样设计的。 Just remove all the mentions of Prettier from the ESLint config.只需从 ESLint 配置中删除所有提到 Prettier 的内容。

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

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