@20i/eslint-config 中文文档教程

发布于 3年前 浏览 22 项目主页 更新于 3年前

eslint-config-20i

Auto Install

使用 mrm 安装所有依赖项并添加配置文件

npx mrm eslint --preset @20i/mrm-preset

Manual Install

  1. Install dev dependencies:
yarn add -D eslint prettier typescript @20i/eslint-config
# or
npm i -D eslint prettier typescript @20i/eslint-config
  1. Create a new file .eslintrc.js in the directory of your project.
  2. Add the following code to the file.
module.exports = {
  extends: ["@20i/eslint-config"],
  parserOptions: {
    project: ["./tsconfig.eslint.json"],
  },
  ignorePatterns: [],
}

对于 React 项目,请改用 @20i/eslint-config/react

  1. Add a special tsconfig.json file to your project: tsconfig.eslint.json to enable full type checking.
{
  // extend your base config to share compilerOptions, etc
  "extends": "./tsconfig.json",
  "compilerOptions": {
    // ensure that nobody can accidentally use this config for a build
    "noEmit": true
  },
  "include": [
    "**/*",
    "**/.*"
  ],
}
  1. Add the following to your .prettierrc file:
{
  "endOfLine": "auto",
  "semi": false,
  "trailingComma": "es5"
}

Configure VS Code

  1. Install the extension eslint-vscode
  2. Install the extension prettier-vscode
  3. Add the following to your .vscode/settings.json file:
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },

  // format on save for everything but what prettier will handle through eslint
  "editor.formatOnSave": true,
  "[javascriptreact]": {
    "editor.formatOnSave": false,
  },
  "[javascript]": {
    "editor.formatOnSave": false,
  },

  "[typescript]": {
    "editor.formatOnSave": false,
  },
  "[typescriptreact]": {
    "editor.formatOnSave": false,
  },
  1. Restart VS Code

深受 eslint-config-wesbos 启发

eslint-config-20i

Auto Install

Use mrm to install all dependencies and add config files

npx mrm eslint --preset @20i/mrm-preset

Manual Install

  1. Install dev dependencies:
yarn add -D eslint prettier typescript @20i/eslint-config
# or
npm i -D eslint prettier typescript @20i/eslint-config
  1. Create a new file .eslintrc.js in the directory of your project.
  2. Add the following code to the file.
module.exports = {
  extends: ["@20i/eslint-config"],
  parserOptions: {
    project: ["./tsconfig.eslint.json"],
  },
  ignorePatterns: [],
}

For React projects, use @20i/eslint-config/react instead.

  1. Add a special tsconfig.json file to your project: tsconfig.eslint.json to enable full type checking.
{
  // extend your base config to share compilerOptions, etc
  "extends": "./tsconfig.json",
  "compilerOptions": {
    // ensure that nobody can accidentally use this config for a build
    "noEmit": true
  },
  "include": [
    "**/*",
    "**/.*"
  ],
}
  1. Add the following to your .prettierrc file:
{
  "endOfLine": "auto",
  "semi": false,
  "trailingComma": "es5"
}

Configure VS Code

  1. Install the extension eslint-vscode
  2. Install the extension prettier-vscode
  3. Add the following to your .vscode/settings.json file:
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },

  // format on save for everything but what prettier will handle through eslint
  "editor.formatOnSave": true,
  "[javascriptreact]": {
    "editor.formatOnSave": false,
  },
  "[javascript]": {
    "editor.formatOnSave": false,
  },

  "[typescript]": {
    "editor.formatOnSave": false,
  },
  "[typescriptreact]": {
    "editor.formatOnSave": false,
  },
  1. Restart VS Code

Inspired heavily by eslint-config-wesbos

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文