简体   繁体   English

带有 Airbnb 风格指南的 ESLint 不适用于所有规则

[英]ESLint with Airbnb style guide does not work for all rules

Recently I started checking all various JavaScript style guides and I liked Airbnb the best.最近我开始查看各种 JavaScript 风格指南,我最喜欢Airbnb

However, when I configured ESLint with Airbnb style guide, I noticed that some rules defined in their docs are not checked at all.但是,当我使用 Airbnb 样式指南配置ESLint时,我注意到他们的文档中定义的一些规则根本没有被检查。 For example:例如:

  1. Group all your consts and then group all your lets . 将所有consts分组,然后将所有lets分组。
  2. Use shortcuts for booleans, but explicit comparisons for strings and numbers. 对布尔值使用快捷方式,但对字符串和数字使用显式比较。
  3. Use // for single line comments.使用//单行注释。 Place single line comments on a newline above the subject of the comment.将单行注释放在注释主题上方的换行符上。 Put an empty line before the comment unless it's on the first line of a block.除非它在块的第一行,否则在注释前放置一个空行。

So, if you take this code as an example:所以,如果你以这段代码为例:

const array = [1, 2, 3, 4, 5];
let foo = 'foo';
const bar = 'bar';

if (array.length) {
  console.log('Bar:', bar);
  // Chaniging foo
  foo = 'baz';
  console.log('Foo:', foo);
}

The linter should throw 3 errors: linter 应该抛出 3 个错误:

  1. I didn't group all consts and then all lets , I defined them sequentially.我没有将所有const分组,然后将所有let分组,我按顺序定义了它们。
  2. I didn't use explicit comparation in if statement - array.length > 0 .我没有在if语句中使用显式比较 - array.length > 0
  3. I didn't add new line before my comment.我没有在评论之前添加新行。

However, linter does not throw any error.但是,linter 不会抛出任何错误。

Airbnb style guide is a recommendation on how to write code. Airbnb 风格指南是关于如何编写代码的建议
ESLint is a tool created by a separate team, specifically Nicholas C. ESLint 是由一个单独的团队创建的工具,特别是 Nicholas C。 Zakas in the first place.首先是扎卡斯。
So the recommendation utilizes ESLint to automate checks for some of the rules, but not all.所以推荐使用 ESLint 来自动检查一些规则,但不是全部。

Some Airbnb style guide rules have trailing eslint: rule-name , which indicates if it is checked or not.一些 Airbnb 风格指南规则有尾随eslint: rule-name ,表示它是否被选中。 All 3 rules from the topic don't have it.该主题的所有 3 条规则都没有。
Also there is a page that elaborates on new rules addition.还有一个 页面详细说明了新规则的添加。 It states: "As of 2020, we only accept rules related to new ECMAScript features. We prefer that new rules be implemented in plugins".它指出:“截至 2020 年,我们只接受与新 ECMAScript 功能相关的规则。我们更喜欢在插件中实现新规则”。

暂无
暂无

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

相关问题 Airbnb样式指南:命名约定的规则不起作用 - Airbnb style guide:rules for naming conventions not working eslint规则不能与airbnb规则一起使用? - eslint rules not working with airbnb rule? 如何使Airbnb的JavaScript样式eslint指南与React,ES6一起在vim中工作? - How to get Airbnb's JavaScript style eslint guide working in vim with react, es6? 如何将 eslint airbnb 风格指南合并成一个文件以复制到 package.json 中? - How can I concatinate the eslint airbnb style guide into one file to copy into package.json? 为什么即使我将其设置为两个空格和硬制表符,Eslint 仍会在 atom 中使用 Airbnb 样式指南的两个空格规则引发错误? - why does Eslint throws error with the Airbnb style guide's two spaces rule in atom even though I have it set to two spaces and hard tabs? 如何处理 AirBNB 配置中冲突的 eslint 规则 - How to deal with conflicting eslint rules in AirBNB configuration 如何从eslint-config-airbnb有选择地启用eslint规则 - How to selectively enable eslint rules from eslint-config-airbnb 为什么Airbnb风格指南表示不鼓励依赖功能名称推断? - Why does the Airbnb style guide say that relying on function name inference is discouraged? ESLint 问题:标准指南,还是流行的风格指南 - ESLint Question: Standard guide, or a popular style guide 使用 .eslint.json 时无法加载带有 airbnb 的 Eslint - Eslint with airbnb does not load when using .eslint.json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM