ESLint:修订间差异
来自康健生活
| (未显示同一用户的22个中间版本) | |||
| 第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.*文件。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
eslint --init | |||
</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
You can also run this command directly using 'npm init @eslint/config'. | |||
Need to install the following packages: | |||
@eslint/create-config | |||
Ok to proceed? (y) y | |||
✔ How would you like to use ESLint? · problems | |||
✔ What type of modules does your project use? · esm | |||
✔ Which framework does your project use? · react | |||
✔ Does your project use TypeScript? · No / Yes | |||
✔ Where does your code run? · browser | |||
✔ What format do you want your config file to be in? · YAML | |||
The config that you've selected requires the following dependencies: | |||
eslint-plugin-react@latest | |||
✔ Would you like to install them now with npm? · No / Yes | |||
Installing eslint-plugin-react@latest | |||
Successfully created .eslintrc.yml file in /Users/kangjian/360/medici/client | |||
</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"> | ||
| 第79行: | 第125行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| [[/规则 |规则]] | | [[/规则|规则]] || [[/eslint-plugin-react|eslint-plugin-react]] | ||
|} | |} | ||
| 第90行: | 第136行: | ||
|- | |- | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |||
=== 我的配置示例 === | |||
{| class="wikitable" | |||
|- | |||
| [[/我的配置-前端-react|我的配置-前端-react]] | |||
|} | |} | ||
== 技巧 == | == 技巧 == | ||
{| class="wikitable" | |||
|- | |||
| [[/忽略校验|忽略校验]] || [[/全局变量|全局变量]] || 示例 | |||
|- | |||
| 示例 || 示例 || 示例 | |||
|- | |||
| 示例 || 示例 || 示例 | |||
|} | |||
== 修复代码 == | == 修复代码 == | ||
{{hc|package.json|<syntaxhighlight lang="javascript"> | {{hc|package.json|<syntaxhighlight lang="javascript"> | ||
| 第112行: | 第173行: | ||
| 示例 || 示例 || 示例 | | 示例 || 示例 || 示例 | ||
|} | |} | ||
== .eslintignore == | |||
[[/.eslintignore|.eslintignore]] | |||
== 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"> | ||
| 第136行: | 第200行: | ||
} | } | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
*: 更改为如下 | |||
*: <syntaxhighlight lang="javascript"> | |||
computed: { | |||
renderDataList: { | |||
get() { | |||
const HSF = this.list | |||
if (!HSF[0].filters) { | |||
return [] | |||
} | |||
return { | |||
searchFilters: HSF[0].filters | |||
} | |||
}, | |||
set() { | |||
const param = this.renderDataList.searchFilters | |||
this.isCountry = param[0].key | |||
this.isDepartment = param[1].key | |||
this.isCountryValue = param[0].options[0].value | |||
this.isDepartmentValue = param[1].options[0].value | |||
} | |||
} | |||
},</syntaxhighlight> | |||
* Parsing error: setter must have exactly one formal parameter | |||
* 'util.isArray' was deprecated since v4.0.0. Use 'Array.isArray()' instead.(node/no-deprecated-api) | |||
* Arrow function has a complexity of 30. Maximum allowed is 20.(complexity) | |||
*: | |||
* Type of the default value for 'searchHotList' prop must be a function | |||
*: <syntaxhighlight lang="javascript"> | |||
props: { | |||
searchHotList: { | |||
type: Array, | |||
default: function () { return [] } | |||
} | |||
}</syntaxhighlight> | |||
*: <syntaxhighlight lang="javascript"> | |||
props: { | |||
searchHotList: { | |||
type: Array, | |||
default: () => [] // es6的箭头函数 | |||
} | |||
}</syntaxhighlight> | |||
* 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 | |||
== 雁阵规则 == | == 雁阵规则 == | ||