@21st-digital/eslint-config 中文文档教程

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

Commitizen友好”></a> 
  <img src=

eslint-config-21st

这个包提供了 21st digital 的 ESLint 可共享配置 支持 Prettier。 它基于 JavaScript 标准样式

Install

  1. 如果您还没有 package.json 文件,请使用 npm init 创建一个。

  2. 然后我们需要安装配置所需的一切:

npx install-peerdeps --dev @21st-digital/eslint-config
  1. 您可以在 package.json 中看到现在有一​​大堆 devDependencies。

  2. 在项目目录的根目录中创建一个 .eslintrc 文件(它应该位于 package.json 所在的位置)。 您的 .eslintrc 文件应如下所示:

{
  "extends": ["@21st-digital"]
}

提示:您也可以将此对象放入 package.json 属性 "eslintConfig" 下: . 这会在您的项目中减少一个文件。

  1. You can add two scripts to your package.json to lint and/or fix:
"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},
  1. Now you can manually lint your code by running npm run lint and fix all fixable issues with npm run lint:fix. You probably want your editor to do this though.

VS Code

您可能希望您的编辑器为您检查和修复。 以下是 VS Code 的说明:

  1. Install the ESLint package
  2. Now we need to setup some VS Code settings via Code/FilePreferencesSettings. It's easier to enter these settings while editing the settings.json file, so click the Open (Open Settings) icon in the top right corner:
// These are all my auto-save configs
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript]": {
  "editor.formatOnSave": false
},
"[javascriptreact]": {
  "editor.formatOnSave": false
},
// show eslint icon at bottom toolbar
"eslint.alwaysShowStatus": true,
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
  "source.fixAll": true
},
// Optional BUT IMPORTANT: If you have the prettier extension enabled for other languages like CSS and HTML, turn it off for JS since we are doing it through Eslint already
"prettier.disableLanguages": ["javascript", "javascriptreact"],

第一次尝试对文件进行 lint 后,您可能需要单击右下角的“ESLint”并在警报窗口中选择“Allow Everywhere”。

最后,您通常需要重新启动 VS 代码。 他们说你不需要,但在我重新启动之前它对我没有用。

Commitizen friendly Pipeline

eslint-config-21st

This package provides 21st digital's ESLint Shareable Config with support for Prettier. It is based on JavaScript Standard Style.

Install

  1. If you don't already have a package.json file, create one with npm init.

  2. Then we need to install everything needed by the config:

npx install-peerdeps --dev @21st-digital/eslint-config
  1. You can see in your package.json there are now a big list of devDependencies.

  2. Create a .eslintrc file in the root of your project's directory (it should live where package.json does). Your .eslintrc file should look like this:

{
  "extends": ["@21st-digital"]
}

Tip: You can alternatively put this object in your package.json under the property "eslintConfig":. This makes one less file in your project.

  1. You can add two scripts to your package.json to lint and/or fix:
"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},
  1. Now you can manually lint your code by running npm run lint and fix all fixable issues with npm run lint:fix. You probably want your editor to do this though.

VS Code

You probably want your editor to lint and fix for you. Here are the instructions for VS Code:

  1. Install the ESLint package
  2. Now we need to setup some VS Code settings via Code/FilePreferencesSettings. It's easier to enter these settings while editing the settings.json file, so click the Open (Open Settings) icon in the top right corner:
// These are all my auto-save configs
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript]": {
  "editor.formatOnSave": false
},
"[javascriptreact]": {
  "editor.formatOnSave": false
},
// show eslint icon at bottom toolbar
"eslint.alwaysShowStatus": true,
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
  "source.fixAll": true
},
// Optional BUT IMPORTANT: If you have the prettier extension enabled for other languages like CSS and HTML, turn it off for JS since we are doing it through Eslint already
"prettier.disableLanguages": ["javascript", "javascriptreact"],

After attempting to lint your file for the first time, you may need to click on 'ESLint' in the bottom right and select 'Allow Everywhere' in the alert window.

Finally you'll usually need to restart VS code. They say you don't need to, but it's never worked for me until I restart.

更多

友情链接

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