新手上路

ESLint 是一种用于识别和报告在 ECMAScript/JavaScript 代码中发现的模式的工具,其目标是使代码更加一致并避免错误。在许多方面,它类似于 JSLint 和 JSHint,但有一些例外:

  • ESLint 使用 Espree 进行 JavaScript 解析。
  • ESLint 使用 AST 来评估代码中的模式。
  • ESLint 是完全可插拔的,每一条规则都是一个插件,你可以在运行时添加更多。

安装与使用

先决条件:Node.js^12.22.0^14.17.0>=16.0.0)内置 SSL 支持。(如果您使用的是官方 Node.js 发行版,则始终内置 SSL。)

您可以使用以下命令安装和配置 ESLint:

npm init @eslint/config

注意:npm init @eslint/config 假设您已经有一个 package.json 文件。如果没有,请确保事先运行 npm inityarn init

Q3AZQmRhyw0mi0Saq5sdxPLIZLF/72tkhiUjrRhLppR+8PyZkDmQwngLBqVWqbi28oVGT+RWoYlLVgc5Eq9gXKlwOF0mknwqtlh2gs5TGSM=

npx eslint yourfile.js

# or

yarn run eslint yourfile.js

JVj6K7ZzMJWEW++P9VU4OJIYOregBJDR43NpsZf2OmmH7Eo4zAyPho3gixLe8l1D8W5mMAg8qS/Y5W1xXOMhLcU4WSwTukUzQIvT9YU7K3syDHgnQacozB8/CIFJQOTS4DtluOiaH1k8tecx3xvRBU3MEjR0mXF+4YZUTiTyi+TIuYMn/KzY/4lIceJ4mpTzOeT8dztBHeRyU3uSCAwqUkA9cAslWcoYAEFzUG/KrO1zB6dGIiTgMz4SIa8xHwsrbuKKyhPgXLapnT7FKcCNsPYtIgTwy6PY2/XMgQzMqS4y5KBNVJJv0RGJtQcmji7i

配置

vAalFFDKMkNpIMn8Zb6xSN+o6f2lrnZfongiUlUQHdHhaoqVvT0bt2nP6zJsuJ8GOep1VUb1uSoTbLsnSld4rqcpYfE8gE+iYQwsLqHmBQzjTLwXQOjcpOjKa809K5ky+F5kToOojCM8Hkrov+VLrE4TpoehEDHijjv9l++YkykGrneHOTFY1cty2K52Hcbn

dMoyDxIXWQsP72c6THgTLbcgVese3KMTs79FXu1HFHBCCg794TjGXTco9gORI1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