ESLint:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的11个中间版本)
第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>
== 命令 ==
== 命令 ==
初始化和生成.eslintrc.*文件
<syntaxhighlight lang="bash">
eslint --init</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]]
|}
|}


第125行: 第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">
第190行: 第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


== 雁阵规则 ==
== 雁阵规则 ==