Visual Studio Code - איך פותרים חוקים מתנגשים של linting ב-VSCode בין eslint ו-typescript-eslint
יש לי את כללי ה-eslint שלי כך
module.exports = {
env: {
es6: true,
node: true,
mocha: true
},
extends: [
"standard-with-typescript"
],
parser: '@typescript-eslint/parser',
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
project: "./tsconfig.json"
},
rules: {
"quotes": ["warn", "single"],
"indent": ["warn", "tab", { "ignoreComments": true }],
"no-tabs": 0,
"padded-blocks": 0,
"semi": 0,
"no-trailing-spaces": 0,
"spaced-comment": 0,
"no-multiple-empty-lines": 0,
"space-before-function-paren": 0,
"camelcase": 0,
"prefer-const": "warn",
"space-infix-ops": "warn",
"@typescript-eslint/strict-boolean-expressions": ["warn", {"allowNullable": true}]
},
plugins: [
'@typescript-eslint',
],
}
כאשר אני פותח קובץ חדש שאינו מעוצב כראוי עם טאבים, אני מקבל:
הגיוני, אז אני משנה את ההזחה לטאבים באמצעות VScode ועכשיו אני מקבל:
???
יש לי את ההגדרות שלי מוגדרות כך שכל ההרחבות יקראו רק מקובץ eslintrc אחד שנמצא בשורש הפרויקט...
תשובה #1
מכיוון שלא פרסמת את כל קובץ .eslintrc.js שלך, אני יכול רק להניח שהוספת הרחבות לכמה מהקבוצות המומלצות של חוקים, מה שמוביל להתנהגות הלא רצויה שלך שבה מספר חוקים רצים...
בהתאם לאיזה אחד משני הכללים הללו אתה רוצה, אתה יכול פשוט לבטל את השני על ידי הוספת זה לכללים שלך לדוגמה:
"@typescript-eslint/indent": "כבוי"
זה ינטרל את הכלל @typescript-eslint/indent עבור הפרויקט שלך.
תשובה #2
הפתרון המועדף עלי היה לבטל את כלל ה-indent הבסיסי ולהגדיר כלל @typescript-eslint/indent מחליף כפי שהומלץ כאן: https://github.com/typescript-eslint/typescript-eslint/blob/87b7dbbc8d25d059e34888ec28026bfb4ade2215/packages/eslint-plugin/docs/rules/indent.md
"rules": {
"indent": "off",
"@typescript-eslint/indent": ["error", 2]
}
גיליתי שהשבתת כלל @typescript-eslint/indent לטובת כלל הבסיס indent פשוט מסתירה את השגיאות בעורך הקוד, בעוד שעדיין גורמת לכישלון הקימפול!

