ESLint:修订间差异
来自康健生活
| (未显示同一用户的10个中间版本) | |||
| 第39行: | 第39行: | ||
npm install eslint-config-standard eslint-plugin-standard eslint-plugin-promise | npm install eslint-config-standard eslint-plugin-standard eslint-plugin-promise | ||
eslint --init</syntaxhighlight> | eslint --init</syntaxhighlight> | ||
== | == 配置文件 == | ||
ESLint 支持多种格式配置文件,同一目录下多个配置文件的优先级顺序如下: | |||
# JavaScript - <code>.eslintrc.js</code>。 | |||
# YAML - <code>.eslintrc.yaml</code>/<code>.eslintrc.yml</code>。 | |||
# JSON - <code>.eslintrc.json</code>,允许 JavaScript 风格注释。 | |||
# Deprecated - <code>.eslintrc</code>,文本格式为 JSON/YAML。 | |||
# package.json - 创建 <code>eslintConfig</code> 属性。 | |||
初始化和生成.eslintrc.*文件。 | 初始化和生成.eslintrc.*文件。 | ||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
eslint --init | eslint --init | ||
</syntaxhighlight>|<syntaxhighlight lang="bash"> | </syntaxhighlight>|<syntaxhighlight lang="bash"> | ||
| 第60行: | 第68行: | ||
Successfully created .eslintrc.yml file in /Users/kangjian/360/medici/client | Successfully created .eslintrc.yml file in /Users/kangjian/360/medici/client | ||
</syntaxhighlight>|➜ client git:(master_sketch_version) ✗}} | </syntaxhighlight>|➜ client git:(master_sketch_version) ✗}} | ||
=== IDE === | |||
vscode: | |||
# 打开 extensions 搜索 ESLint 并安装。 | |||
# 点击 code 菜单,选中 setting/extensions,点击 edit in settings.json。 | |||
<syntaxhighlight lang="javascript"> | |||
{ | |||
"eslint.codeAction.showDocumentation": { | |||
"enable": true | |||
}, | |||
"eslint.format.enable": true, | |||
"eslint.options": { | |||
}, | |||
"eslint.probe": [ | |||
"javascript", | |||
"javascriptreact", | |||
"html" | |||
], | |||
}</syntaxhighlight> | |||
== 命令 == | |||
执行检查命令 | 执行检查命令 | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| 第96行: | 第125行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| [[/规则 |规则]] | | [[/规则|规则]] || [[/eslint-plugin-react|eslint-plugin-react]] | ||
|} | |} | ||
| 第107行: | 第136行: | ||
|- | |- | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |||
=== 我的配置示例 === | |||
{| class="wikitable" | |||
|- | |||
| [[/我的配置-前端-react|我的配置-前端-react]] | |||
|} | |} | ||
| 第142行: | 第177行: | ||
== error == | == error == | ||
=== config === | |||
* ESLint: Expected indentation of 10 spaces but found 20 spaces.( | * ESLint: Expected indentation of 10 spaces but found 20 spaces.( | ||
*: <syntaxhighlight lang="javascript"> | *: <syntaxhighlight lang="javascript"> | ||
| 第207行: | 第243行: | ||
* ESLint: Missing accessibility modifier on method definition constructor.(@typescript-eslint/explicit-member-accessibility) | * ESLint: Missing accessibility modifier on method definition constructor.(@typescript-eslint/explicit-member-accessibility) | ||
*: 缺少可访问的修饰符 | *: 缺少可访问的修饰符 | ||
* Environment key "es2021" is unknown | |||
* The eslint library loaded from /Users/kangjian/360/medici/client/node_modules/eslint/lib/api.js doesn't export a CLIEngine. You need at least eslint@1.0.0 | |||
*: {{Shc_out|<syntaxhighlight lang="bash"> | |||
which eslint</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
/usr/local/bin/eslint | |||
</syntaxhighlight>|➜ client git:(master_sketch_version) ✗}} | |||
=== react === | |||
* Component definition is missing display name | |||
== 雁阵规则 == | == 雁阵规则 == | ||