typescript - eslint lỗi thụt lề "Đã mong đợi thụt lề 2 khoảng trắng nhưng tìm thấy 4.", angular 14
Tôi đang sử dụng "eslint": "^8.23.0" trong Angular 14
Mọi thứ đều ổn khi tôi sử dụng "eslint": "^8.22.0", nhưng sau khi cập nhật lên 8.23.0 tôi nhận được lỗi sau:
Cấu hình eslint của tôi:
{
"root": true,
"ignorePatterns": [
"projects/**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.js",
"*.tsx"
],
"parserOptions": {
"project": [
"tsconfig.json"
],
"createDefaultProgram": true
},
"extends": [
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"indent": [
"error",
2,
{
"SwitchCase": 1,
"ArrayExpression": "first"
}
],
"@angular-eslint/template/eqeqeq": "off",
"@typescript-eslint/naming-convention": "error",
"quotes": "error",
"semi": "error",
"no-multiple-empty-lines": "error",
"comma-dangle": "error"
}
},
{
"files": [
"*.html",
"*.css"
],
"extends": [
"plugin:@angular-eslint/template/recommended"
],
"rules": {
"@angular-eslint/template/eqeqeq": "off",
"@angular-eslint/template/accessibility-elements-content": "error",
"no-multiple-empty-lines": "error"
}
}
]
}
như bạn có thể thấy đây là cấu hình indent:
"indent": [
"error",
2,
{
"SwitchCase": 1
}
]
Tôi đã thử cấu hình sau
"indent": [
"error",
2,
{
"SwitchCase": 1,
"ArrayExpression": "first"
}
]
Tôi cũng thay đổi cấu hình eslint thành như sau:
"indent": "off",
"@typescript-eslint/indent": [
"error",
2,
{
"SwitchCase": 1
}
],
nhưng chẳng có gì thay đổi!
Câu trả lời #1
Sau khi cập nhật gói sau, vấn đề đã biến mất!
@typescript-eslint/eslint-plugin 5.36.0 → 5.36.1
@typescript-eslint/parser 5.36.0 → 5.36.1
Câu trả lời số 2
Đã giải quyết với các phụ thuộc này (trong dự án Angular 16):
...
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/eslint-plugin-tslint": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.52.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
...

