当前位置:   article > 正文

VScode配置ESLint检测语法_vscode设置eslint检验不报错

vscode设置eslint检验不报错

eslint失效:导致两种效果:
1.格式错误不报红,列如:代码前多空格。
2.no quick fix,缺少eslint fix 指令,快速寻找并解决问题。
在根目录下的.vscode下的settings.jsonCtrl + Shift + P”打开命令面板选择“Preferences: Open Settings (JSON)”中加入如下代码可以解决

  1. "eslint.validate": [
  2. "vue",
  3. "html",
  4. "javascript",
  5. "typescript",
  6. "javascriptreact",
  7. "typescriptreact"
  8. ],
  1. {
  2. "editor.codeActionsOnSave": {
  3. "source.fixAll.eslint": true, // 明确保存时自动修复 ESLint 问题
  4. "source.fixAll.stylelint": "explicit" // 对于 Stylelint,保存时提示是否修复
  5. },
  6. "files.autoSaveDelay": 10000,
  7. "editor.inlineSuggest.enabled": true,
  8. "update.mode": "none",
  9. "update.enableWindowsBackgroundUpdates": false,
  10. "workbench.iconTheme": "vs-minimal",
  11. "[vue]": {
  12. "editor.defaultFormatter": "esbenp.prettier-vscode" // Vue 文件使用 Prettier 格式化
  13. },
  14. "javascript.updateImportsOnFileMove.enabled": "always",
  15. "explorer.confirmDelete": false,
  16. "[javascript]": {
  17. "editor.defaultFormatter": "esbenp.prettier-vscode" // JavaScript 文件使用 Prettier 格式化
  18. },
  19. "window.zoomLevel": -1,
  20. "git.enableSmartCommit": true,
  21. "git.confirmSync": false,
  22. "workbench.colorTheme": "After Dark",
  23. "eslint.validate": [
  24. "vue",
  25. "html",
  26. "javascript",
  27. "typescript",
  28. "javascriptreact",
  29. "typescriptreact"
  30. ],
  31. "eslint.run": "onSave",
  32. "editor.formatOnSave": true,
  33. "eslint.autoFixOnSave": true,
  34. "javascript.format.semicolons": "ignore",
  35. // 如果您不希望 ESLint 作为全局默认格式化器,可以移除以下行
  36. // "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  37. }

 

.eslintrc.js配置

  1. const INDENT = 4;
  2. const MAX_DEEP = 3;
  3. const MAX_LENGTH = 120;
  4. module.exports = {
  5. 'globals': {
  6. __dirname: true,
  7. process: true
  8. },
  9. 'env': {
  10. 'browser': true,
  11. 'es6': true,
  12. 'commonjs': true,
  13. },
  14. 'extends': [
  15. 'eslint:recommended',
  16. 'plugin:vue/essential'
  17. ],
  18. 'parserOptions': {
  19. 'ecmaVersion': 2018,
  20. 'sourceType': 'module'
  21. },
  22. 'plugins': [
  23. 'vue'
  24. ],
  25. 'rules': {
  26. 'indent': ['error', 4],
  27. 'vue/html-indent': ['error', INDENT, {
  28. attribute: 1,
  29. baseIndent: 1,
  30. closeBracket: 0,
  31. alignAttributesVertically: true,
  32. ignores: [],
  33. }],
  34. 'vue/html-quotes': ['error', 'double', { avoidEscape: false }],
  35. 'vue/attribute-hyphenation': ['off'],
  36. 'accessor-pairs': 'error',
  37. 'array-bracket-newline': 'off',
  38. 'array-bracket-spacing': [
  39. 'error',
  40. 'never',
  41. ],
  42. 'array-callback-return': 'off',
  43. 'array-element-newline': 'off',
  44. 'arrow-body-style': 'off',
  45. 'arrow-parens': 'off',
  46. 'arrow-spacing': 'error',
  47. 'block-scoped-var': 'off',
  48. 'block-spacing': 'off',
  49. 'brace-style': 'off',
  50. 'camelcase': 'error',
  51. 'capitalized-comments': 'off',
  52. 'class-methods-use-this': 'off',
  53. 'comma-dangle': ['error', 'always-multiline'],
  54. 'comma-spacing': 'error',
  55. 'comma-style': [
  56. 'error',
  57. 'last',
  58. ],
  59. 'complexity': ['error', 10],
  60. 'computed-property-spacing': 'off',
  61. 'consistent-return': 'off',
  62. 'consistent-this': 'off',
  63. 'curly': 'off',
  64. 'default-case': 'off',
  65. 'default-param-last': 'error',
  66. 'dot-location': 'off',
  67. 'dot-notation': 'off',
  68. 'eol-last': ['warn', 'always'],
  69. 'eqeqeq': 'error',
  70. 'func-call-spacing': ['error', 'never'],
  71. 'func-name-matching': 'off',
  72. 'func-names': 'off',
  73. 'func-style': 'off',
  74. 'function-call-argument-newline': 'off',
  75. 'function-paren-newline': 'off',
  76. 'generator-star-spacing': 'error',
  77. 'grouped-accessor-pairs': 'error',
  78. 'guard-for-in': 'error',
  79. 'id-length': 'off',
  80. 'id-match': 'error',
  81. 'implicit-arrow-linebreak': [
  82. 'error',
  83. 'beside',
  84. ],
  85. 'indent': ['error', INDENT],
  86. 'init-declarations': 'off',
  87. 'jsx-quotes': 'error',
  88. 'key-spacing': 'error',
  89. 'keyword-spacing': 'error',
  90. 'line-comment-position': 'off',
  91. 'linebreak-style': 'off',
  92. 'lines-around-comment': 'off',
  93. 'lines-between-class-members': 'off',
  94. 'max-classes-per-file': 'error',
  95. 'max-depth': ['error', MAX_DEEP],
  96. 'max-len': ['error', MAX_LENGTH],
  97. 'max-lines': ['error', {
  98. max: 600,
  99. skipBlankLines: true,
  100. skipComments: true,
  101. }],
  102. 'max-lines-per-function': ['error', {
  103. max: 50,
  104. skipBlankLines: true,
  105. skipComments: true,
  106. }],
  107. 'max-nested-callbacks': 'error',
  108. 'max-params': 'off',
  109. 'max-statements': 'off',
  110. 'max-statements-per-line': 'off',
  111. 'multiline-comment-style': ['error', 'starred-block'],
  112. 'multiline-ternary': 'off',
  113. 'new-parens': 'off',
  114. 'newline-per-chained-call': 'off',
  115. 'no-alert': 'error',
  116. 'no-array-constructor': 'off',
  117. 'no-await-in-loop': 'error',
  118. 'no-bitwise': 'off',
  119. 'no-caller': 'error',
  120. 'no-confusing-arrow': [
  121. 'error',
  122. {
  123. allowParens: true,
  124. },
  125. ],
  126. 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
  127. 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'warn',
  128. 'no-constructor-return': 'error',
  129. 'no-continue': 'off',
  130. 'no-div-regex': 'off',
  131. 'no-duplicate-imports': 'error',
  132. 'no-else-return': 'off',
  133. 'no-empty-function': 'off',
  134. 'no-eq-null': 'off',
  135. 'no-eval': 'error',
  136. 'no-extend-native': 'off',
  137. 'no-extra-bind': 'error',
  138. 'no-extra-label': 'error',
  139. 'no-extra-parens': 'off',
  140. 'no-floating-decimal': 'off',
  141. 'no-implicit-globals': 'error',
  142. 'no-implied-eval': 'error',
  143. 'no-inline-comments': 'off',
  144. 'no-invalid-this': 'off',
  145. 'no-iterator': 'error',
  146. 'no-label-var': 'error',
  147. 'no-labels': 'error',
  148. 'no-lone-blocks': 'off',
  149. 'no-lonely-if': 'off',
  150. 'no-loop-func': 'warn',
  151. 'no-magic-numbers': ['error', {
  152. ignore: [1, -1, 0, 2, 7, 24, 60, 10, 100, 1000],
  153. ignoreArrayIndexes: true,
  154. }],
  155. 'no-mixed-operators': 'off',
  156. 'no-multi-assign': 'off',
  157. 'no-multi-spaces': 'off',
  158. 'no-multi-str': 'error',
  159. 'no-multiple-empty-lines': 'off',
  160. 'no-negated-condition': 'off',
  161. 'no-nested-ternary': 'off',
  162. 'no-new': 'off',
  163. 'no-new-func': 'off',
  164. 'no-new-object': 'error',
  165. 'no-new-wrappers': 'error',
  166. 'no-octal-escape': 'error',
  167. 'no-param-reassign': 'off',
  168. 'no-plusplus': 'off',
  169. 'no-promise-executor-return': 'off',
  170. 'no-proto': 'off',
  171. 'no-restricted-globals': 'error',
  172. 'no-restricted-imports': 'error',
  173. 'no-restricted-properties': 'error',
  174. 'no-restricted-syntax': 'error',
  175. 'no-return-assign': 'off',
  176. 'no-return-await': 'error',
  177. 'no-script-url': 'error',
  178. 'no-self-compare': 'off',
  179. 'no-sequences': 'off',
  180. 'no-shadow': 'off',
  181. 'no-tabs': 'off',
  182. 'no-template-curly-in-string': 'error',
  183. 'no-ternary': 'off',
  184. 'no-throw-literal': 'error',
  185. 'no-trailing-spaces': 'error',
  186. 'no-undef-init': 'error',
  187. 'no-undefined': 'off',
  188. 'no-underscore-dangle': 'off',
  189. 'no-unmodified-loop-condition': 'error',
  190. 'no-unneeded-ternary': 'error',
  191. 'no-unreachable-loop': 'off',
  192. 'no-unused-expressions': 'off',
  193. 'no-use-before-define': 'off',
  194. 'no-useless-call': 'error',
  195. 'no-useless-computed-key': 'error',
  196. 'no-useless-concat': 'off',
  197. 'no-useless-constructor': 'error',
  198. 'no-useless-rename': 'error',
  199. 'no-useless-return': 'off',
  200. 'no-var': 'error',
  201. 'no-void': 'off',
  202. 'no-warning-comments': 'off',
  203. 'no-whitespace-before-property': 'error',
  204. 'nonblock-statement-body-position': [
  205. 'error',
  206. 'any',
  207. ],
  208. 'object-curly-newline': 'error',
  209. 'object-curly-spacing': 'off',
  210. 'object-property-newline': 'off',
  211. 'object-shorthand': 'off',
  212. 'one-var': 'off',
  213. 'one-var-declaration-per-line': 'off',
  214. 'operator-assignment': 'off',
  215. 'operator-linebreak': ['error', 'before'],
  216. 'padded-blocks': 'off',
  217. 'padding-line-between-statements': 'error',
  218. 'prefer-arrow-callback': 'off',
  219. 'prefer-const': ['error', {
  220. destructuring: 'all',
  221. ignoreReadBeforeAssign: false,
  222. }],
  223. 'prefer-destructuring': 'off',
  224. 'prefer-exponentiation-operator': 'off',
  225. 'prefer-named-capture-group': 'off',
  226. 'prefer-numeric-literals': 'error',
  227. 'prefer-object-spread': 'off',
  228. 'prefer-promise-reject-errors': 'off',
  229. 'prefer-regex-literals': 'off',
  230. 'prefer-rest-params': 'off',
  231. 'prefer-spread': 'off',
  232. 'prefer-template': 'off',
  233. 'quote-props': ['error', 'consistent-as-needed'],
  234. 'quotes': ['error', 'single', {
  235. allowTemplateLiterals: true,
  236. }],
  237. 'radix': 'off',
  238. 'require-atomic-updates': 'error',
  239. 'require-await': 'error',
  240. 'require-unicode-regexp': 'off',
  241. 'rest-spread-spacing': [
  242. 'error',
  243. 'never',
  244. ],
  245. 'semi': ['error', 'always'],
  246. 'semi-spacing': 'error',
  247. 'semi-style': 'off',
  248. 'sort-keys': 'off',
  249. 'sort-vars': 'off',
  250. 'space-before-blocks': 'error',
  251. 'space-before-function-paren': ['error', 'never'],
  252. 'space-in-parens': 'off',
  253. 'space-infix-ops': 'error',
  254. 'space-unary-ops': 'off',
  255. 'spaced-comment': 'error',
  256. 'strict': 'off',
  257. 'switch-colon-spacing': [
  258. 'error',
  259. {
  260. after: false,
  261. before: false,
  262. },
  263. ],
  264. 'symbol-description': 'error',
  265. 'template-curly-spacing': [
  266. 'error',
  267. 'never',
  268. ],
  269. 'template-tag-spacing': 'error',
  270. 'unicode-bom': [
  271. 'error',
  272. 'never',
  273. ],
  274. 'valid-typeof': [
  275. 'error',
  276. {
  277. requireStringLiterals: false,
  278. },
  279. ],
  280. 'vars-on-top': 'off',
  281. 'wrap-iife': 'off',
  282. 'wrap-regex': 'off',
  283. 'yield-star-spacing': 'error',
  284. 'yoda': 'off',
  285. 'vue/multi-word-component-names': 'off',
  286. }
  287. };

 .eslintignore配置

  1. .eslintrc.js
  2. /dist
  3. /modules
  4. /node_modules
  5. /src/iconfont
VSCode 默认保存时格式化配置

ESLint官网

Prettier官网

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号