我已經在 VSCode 上安裝了 Eslint-Prettier 擴展。我已經有一個 .eslintrc.js 并且我的默認格式化程式(Eslint-prettier)沒有根據我的 eslint 規則進行格式化。
例如:當我輸入 npm run eslint 。--fix 它洗掉所有分號,但在我按下 CTRL V 后,更漂亮的再次添加分號..
在我格式化計算機之前,它一直運行良好。誰能幫我?
我的 .eslintrc.js 檔案內容是
module.exports = {
env: {
node: true,
es6: true,
browser: true
},
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
modules: true,
experimentalObjectRestSpread: true
}
},
rules: {
"no-console": "off",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
// Best Practices
eqeqeq: "error",
"no-invalid-this": "error",
"no-return-assign": "error",
"no-unused-expressions": ["error", { allowTernary: true }],
"no-useless-concat": "error",
"no-useless-return": "error",
// Variable
// 'init-declarations': 'error',
"no-use-before-define": "error",
// Stylistic Issues
"array-bracket-newline": ["error", { multiline: true, minItems: null }],
"array-bracket-spacing": "error",
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
"block-spacing": "error",
"comma-dangle": "error",
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"func-call-spacing": "error",
"implicit-arrow-linebreak": ["error", "beside"],
// indent: ['error', 4],
"keyword-spacing": "error",
"multiline-ternary": ["error", "never"],
// 'no-lonely-if': 'error',
"no-mixed-operators": "error",
"no-multiple-empty-lines": ["error", { max: 2, maxEOF: 1 }],
"no-tabs": "error",
"no-unneeded-ternary": "error",
"no-whitespace-before-property": "error",
"nonblock-statement-body-position": "error",
"object-property-newline": [
"error",
{ allowAllPropertiesOnSameLine: true }
],
"quote-props": ["error", "as-needed"],
// quotes: ['error', 'prefer-single'],
semi: ["error", "never"],
"semi-spacing": "error",
"space-before-blocks": "error",
// 'space-before-function-paren': 'error',
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
// ES6
"arrow-spacing": "error",
"no-confusing-arrow": "error",
"no-duplicate-imports": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-template": "error"
}
}

您可以看到 eslint 說沒有尾隨昏迷,在我右鍵單擊其中一個并修復所有可自動修復的問題后,問題消失了,但在我保存檔案后,更漂亮的擴展名又將它們放回原處。
uj5u.com熱心網友回復:
- 安裝 eslint:
npm i --save-dev eslint - 初始化 eslint:
對于某些選項,您需要選擇下一步:npx eslint --init- 你想如何使用 ESLint?
- 檢查語法并發現問題
- 您希望組態檔采用什么格式?
- JavaScript
- 安裝更漂亮:
npm i --save-dev eslint-config-prettier eslint-plugin-prettier prettier - 創建
.prettierrc組態檔:{ "printWidth": 80, "singleQuote": true, "trailingComma": "es5" }
現在您可以使用 eslint 檢查樣式并從命令列使用更漂亮的修復樣式。
對于與 eslint 和 prettier 的 VSCode 集成,您需要安裝以下之一:
eslint 輸出

如果我保存檔案,所有更漂亮的問題都將得到修復(應打開保存時的自動格式化)
Eslint 插件不會自動應用位于
.prettierrc. 請參閱github 上的問題。要解決此問題,您可以:.prettierrc在 .eslint 中移動內容(不推薦,因為漂亮的插件有時不會讀取這個檔案);ESLint: Restart ESLint server編輯后從 VSCode 中的命令面板運行。prettierrc檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/343836.html標籤:javascript 反应 视觉工作室代码 eslint 更漂亮
