@3angletech/eslint-config 中文文档教程
@3angletech/eslint-config
由 3angleTech 团队维护的可共享 lint 配置库。
Usage in Node.js projects
安装所需对等依赖项的最新兼容版本:
npm install --save-dev @typescript-eslint/eslint-plugin@4 @typescript-eslint/parser@4 eslint@7 eslint-config-standard@16 eslint-plugin-import@2 eslint-plugin-jsdoc@36 eslint-plugin-node@11 eslint-plugin-promise@5 eslint-plugin-security@1 eslint-plugin-sonarjs@0 typescript@4
在 tsconfig.json
文件旁边创建一个新的 .eslintrc.json
:
{
"root": true,
"extends": [
"@3angletech/lint/node"
],
"rules": {
"___IDE_OVERRIDES_GO_HERE___": true
}
}
注意:包含 ___
是用于文档目的的注释。
提供一个新的 .eslintrc.ci.json
文件:
{
"extends": [
".eslintrc.json"
],
"rules": {
"___CI_OVERRIDES_GO_HERE___": true
}
}
.eslintrc.ci.json
可能包含规则覆盖,以便 lint 命令在过渡到更严格的规则时通过。
Lint 使用:
```json 行 { “脚本”:{ "lint": "eslint --ext=.js,.ts ./src", "lint:ci": "eslint --config=.eslintrc.ci.json --no-eslintrc --ext=.js,.ts ./src", "lint:fix": "eslint --ext=.js,.ts --fix ./src", } }
## Usage in Angular projects
Install latest compatible version of required peer dependencies:
npm install --save-dev @typescript-eslint/eslint-plugin@4 @typescript-eslint/parser@4 eslint@7 eslint-config-standard@16 eslint-plugin-import@2 eslint-plugin-jsdoc@36 eslint-plugin-node@11 eslint-plugin-promise@5 eslint-plugin-security@1 eslint-plugin-sonarjs@0 typescript@4 npm install --save-dev @angular-eslint/eslint-plugin@12 @angular-eslint/eslint-plugin-template@12 @angular-eslint/template-parser@12 eslint-plugin-rxjs@3 stylelint@13 stylelint -config-sass-guidelines@8 stylelint-config-standard@22
Update your project ($NAME) in `angular.json` to include a `project.$NAME.architect.lint` path with:
json 行 { “项目”:{ “$NAME”:{ “建筑师”:{ “皮棉”:{ “建造者”:“@angular-eslint/建造者:林特”, “选项”: { "eslintConfig": ".eslintrc.json", "lintFilePatterns": [ "src//.ts", "src//.html" ] }, “配置”:{ “修复”:{“修复”:真} } } } } } }
Provide a new `.eslintrc.json` file:
JSON { “根”:是的, “延伸”:[ “@3angletech/eslint-config/angular” ], “规则”:{ “COMMONJSANDTSOVERRIDESGOHERE”:true }, “覆盖”:[ { “文件”:[“.ts”], "OPTIONALTSCONFIGOVERRIDEparserOptions": { "project": [ "tsconfig.json" ] }, “规则”:{ "TSONLYOVERRIDESGOHERE": true } }, { "文件": [ ".html" ], “规则”:{ "TEMPLATEONLYOVERRIDESGOHERE": true } } ] }
NOTE: Rules that don't apply to all file types should be included in "overrides" and contain a file extension filter.
To use the StyleLint rules, update `.stylelintrc` to include:
JSON { “延伸”:[ “@3angletech/lint/style” ], “规则”:{ } }
Lint using:
npx ng lint && npx stylelint 'src/**/*.*css'
Or add some extra `package.json` scripts:
JSON { “脚本”:{ "lint": "npm run lint:code; npm run lint:style", “lint:代码”:“ng lint”, "lint:code:fix": "ng lint --configuration=fix", "lint:style": "stylelint 'src//.css'", "lint:style:fix": "stylelint --fix 'src//.css'" } } ```
More information
- ESLint
- stylelint
- Any property can be overridden, for example:
"parserOptions": { "project": "tsconfig.json" }
- ESLint Docs: Configuration Files
- Using a configuration from a plugin
- Extending Configuration Files
- eslint-formatter-summary
@3angletech/eslint-config
Shareable lint configuration library maintained by the 3angleTech team.
Usage in Node.js projects
Install latest compatible version of required peer dependencies:
npm install --save-dev @typescript-eslint/eslint-plugin@4 @typescript-eslint/parser@4 eslint@7 eslint-config-standard@16 eslint-plugin-import@2 eslint-plugin-jsdoc@36 eslint-plugin-node@11 eslint-plugin-promise@5 eslint-plugin-security@1 eslint-plugin-sonarjs@0 typescript@4
Create a new .eslintrc.json
next to the tsconfig.json
file:
{
"root": true,
"extends": [
"@3angletech/lint/node"
],
"rules": {
"___IDE_OVERRIDES_GO_HERE___": true
}
}
NOTE: The keys containing ___
are comments for documentation purposes.
Provide a new .eslintrc.ci.json
file:
{
"extends": [
".eslintrc.json"
],
"rules": {
"___CI_OVERRIDES_GO_HERE___": true
}
}
The .eslintrc.ci.json
may contain rule overrides for the lint command to pass while transitioning to stricter rules.
Lint using:
```json lines { "scripts": { "lint": "eslint --ext=.js,.ts ./src", "lint:ci": "eslint --config=.eslintrc.ci.json --no-eslintrc --ext=.js,.ts ./src", "lint:fix": "eslint --ext=.js,.ts --fix ./src", } }
## Usage in Angular projects
Install latest compatible version of required peer dependencies:
npm install --save-dev @typescript-eslint/eslint-plugin@4 @typescript-eslint/parser@4 eslint@7 eslint-config-standard@16 eslint-plugin-import@2 eslint-plugin-jsdoc@36 eslint-plugin-node@11 eslint-plugin-promise@5 eslint-plugin-security@1 eslint-plugin-sonarjs@0 typescript@4 npm install --save-dev @angular-eslint/eslint-plugin@12 @angular-eslint/eslint-plugin-template@12 @angular-eslint/template-parser@12 eslint-plugin-rxjs@3 stylelint@13 stylelint-config-sass-guidelines@8 stylelint-config-standard@22
Update your project ($NAME) in `angular.json` to include a `project.$NAME.architect.lint` path with:
json lines { "projects": { "$NAME": { "architect": { "lint": { "builder": "@angular-eslint/builder:lint", "options": { "eslintConfig": ".eslintrc.json", "lintFilePatterns": [ "src//.ts", "src//.html" ] }, "configurations": { "fix": { "fix": true } } } } } } }
Provide a new `.eslintrc.json` file:
json { "root": true, "extends": [ "@3angletech/eslint-config/angular" ], "rules": { "COMMONJSANDTSOVERRIDESGOHERE": true }, "overrides": [ { "files": [ ".ts" ], "OPTIONALTSCONFIGOVERRIDEparserOptions": { "project": [ "tsconfig.json" ] }, "rules": { "TSONLYOVERRIDESGOHERE": true } }, { "files": [ ".html" ], "rules": { "TEMPLATEONLYOVERRIDESGOHERE": true } } ] }
NOTE: Rules that don't apply to all file types should be included in "overrides" and contain a file extension filter.
To use the StyleLint rules, update `.stylelintrc` to include:
json { "extends": [ "@3angletech/lint/style" ], "rules": { } }
Lint using:
npx ng lint && npx stylelint 'src/**/*.*css'
Or add some extra `package.json` scripts:
json { "scripts": { "lint": "npm run lint:code; npm run lint:style", "lint:code": "ng lint", "lint:code:fix": "ng lint --configuration=fix", "lint:style": "stylelint 'src//.css'", "lint:style:fix": "stylelint --fix 'src//.css'" } } ```
More information
- ESLint
- stylelint
- Any property can be overridden, for example:
"parserOptions": { "project": "tsconfig.json" }
- ESLint Docs: Configuration Files
- Using a configuration from a plugin
- Extending Configuration Files
- eslint-formatter-summary