• vue项目中非工程化配置eslint


    1. vscode安装eslint插件;

    2.配置这三个文件

    .eslintrc.js

    1. // ESlint 检查配置
    2. module.exports = {
    3. root: true,
    4. parserOptions: {
    5. parser: "babel-eslint",
    6. sourceType: "module",
    7. },
    8. env: {
    9. browser: true,
    10. node: true,
    11. es6: true,
    12. },
    13. extends: ["plugin:vue/recommended", "eslint:recommended"],
    14. // add your custom rules here
    15. //it is base on https://github.com/vuejs/eslint-config-vue
    16. rules: {
    17. "vue/max-attributes-per-line": [
    18. 2,
    19. {
    20. singleline: 10,
    21. multiline: {
    22. max: 3,
    23. allowFirstLine: true,
    24. },
    25. },
    26. ],
    27. "vue/singleline-html-element-content-newline": "off",
    28. "vue/multiline-html-element-content-newline": "off",
    29. "vue/html-closing-bracket-newline": [
    30. "error",
    31. {
    32. singleline: "never",
    33. multiline: "never",
    34. },
    35. ],
    36. "vue/name-property-casing": ["error", "PascalCase"],
    37. "vue/no-v-html": "off",
    38. "accessor-pairs": 2,
    39. "arrow-spacing": [
    40. 2,
    41. {
    42. before: true,
    43. after: true,
    44. },
    45. ],
    46. "block-spacing": [2, "always"],
    47. "brace-style": [
    48. 2,
    49. "1tbs",
    50. {
    51. allowSingleLine: true,
    52. },
    53. ],
    54. camelcase: [
    55. 0,
    56. {
    57. properties: "always",
    58. },
    59. ],
    60. "comma-dangle": [2, "never"],
    61. "comma-spacing": [
    62. 2,
    63. {
    64. before: false,
    65. after: true,
    66. },
    67. ],
    68. "comma-style": [2, "last"],
    69. "constructor-super": 2,
    70. curly: [2, "multi-line"],
    71. "dot-location": [2, "property"],
    72. "eol-last": 2,
    73. eqeqeq: ["error", "always", { null: "ignore" }],
    74. "generator-star-spacing": [
    75. 2,
    76. {
    77. before: true,
    78. after: true,
    79. },
    80. ],
    81. "handle-callback-err": [2, "^(err|error)$"],
    82. indent: [
    83. 2,
    84. 2,
    85. {
    86. SwitchCase: 1,
    87. },
    88. ],
    89. "jsx-quotes": [2, "prefer-single"],
    90. "key-spacing": [
    91. 2,
    92. {
    93. beforeColon: false,
    94. afterColon: true,
    95. },
    96. ],
    97. "keyword-spacing": [
    98. 2,
    99. {
    100. before: true,
    101. after: true,
    102. },
    103. ],
    104. "new-cap": [
    105. 2,
    106. {
    107. newIsCap: true,
    108. capIsNew: false,
    109. },
    110. ],
    111. "new-parens": 2,
    112. "no-array-constructor": 2,
    113. "no-caller": 2,
    114. "no-console": "off",
    115. "no-class-assign": 2,
    116. "no-cond-assign": 2,
    117. "no-const-assign": 2,
    118. "no-control-regex": 0,
    119. "no-delete-var": 2,
    120. "no-dupe-args": 2,
    121. "no-dupe-class-members": 2,
    122. "no-dupe-keys": 2,
    123. "no-duplicate-case": 2,
    124. "no-empty-character-class": 2,
    125. "no-empty-pattern": 2,
    126. "no-eval": 2,
    127. "no-ex-assign": 2,
    128. "no-extend-native": 2,
    129. "no-extra-bind": 2,
    130. "no-extra-boolean-cast": 2,
    131. "no-extra-parens": [2, "functions"],
    132. "no-fallthrough": 2,
    133. "no-floating-decimal": 2,
    134. "no-func-assign": 2,
    135. "no-implied-eval": 2,
    136. "no-inner-declarations": [2, "functions"],
    137. "no-invalid-regexp": 2,
    138. "no-irregular-whitespace": 2,
    139. "no-iterator": 2,
    140. "no-label-var": 2,
    141. "no-labels": [
    142. 2,
    143. {
    144. allowLoop: false,
    145. allowSwitch: false,
    146. },
    147. ],
    148. "no-lone-blocks": 2,
    149. "no-mixed-spaces-and-tabs": 2,
    150. "no-multi-spaces": 2,
    151. "no-multi-str": 2,
    152. "no-multiple-empty-lines": [
    153. 2,
    154. {
    155. max: 1,
    156. },
    157. ],
    158. "no-native-reassign": 2,
    159. "no-negated-in-lhs": 2,
    160. "no-new-object": 2,
    161. "no-new-require": 2,
    162. "no-new-symbol": 2,
    163. "no-new-wrappers": 2,
    164. "no-obj-calls": 2,
    165. "no-octal": 2,
    166. "no-octal-escape": 2,
    167. "no-path-concat": 2,
    168. "no-proto": 2,
    169. "no-redeclare": 2,
    170. "no-regex-spaces": 2,
    171. "no-return-assign": [2, "except-parens"],
    172. "no-self-assign": 2,
    173. "no-self-compare": 2,
    174. "no-sequences": 2,
    175. "no-shadow-restricted-names": 2,
    176. "no-spaced-func": 2,
    177. "no-sparse-arrays": 2,
    178. "no-this-before-super": 2,
    179. "no-throw-literal": 2,
    180. "no-trailing-spaces": 2,
    181. "no-undef": 2,
    182. "no-undef-init": 2,
    183. "no-unexpected-multiline": 2,
    184. "no-unmodified-loop-condition": 2,
    185. "no-unneeded-ternary": [
    186. 2,
    187. {
    188. defaultAssignment: false,
    189. },
    190. ],
    191. "no-unreachable": 2,
    192. "no-unsafe-finally": 2,
    193. "no-unused-vars": [
    194. 2,
    195. {
    196. vars: "all",
    197. args: "none",
    198. },
    199. ],
    200. "no-useless-call": 2,
    201. "no-useless-computed-key": 2,
    202. "no-useless-constructor": 2,
    203. "no-useless-escape": 0,
    204. "no-whitespace-before-property": 2,
    205. "no-with": 2,
    206. "one-var": [
    207. 2,
    208. {
    209. initialized: "never",
    210. },
    211. ],
    212. "operator-linebreak": [
    213. 2,
    214. "after",
    215. {
    216. overrides: {
    217. "?": "before",
    218. ":": "before",
    219. },
    220. },
    221. ],
    222. "padded-blocks": [2, "never"],
    223. quotes: [
    224. 2,
    225. "single",
    226. {
    227. avoidEscape: true,
    228. allowTemplateLiterals: true,
    229. },
    230. ],
    231. semi: [2, "never"],
    232. "semi-spacing": [
    233. 2,
    234. {
    235. before: false,
    236. after: true,
    237. },
    238. ],
    239. "space-before-blocks": [2, "always"],
    240. "space-before-function-paren": [2, "never"],
    241. "space-in-parens": [2, "never"],
    242. "space-infix-ops": 2,
    243. "space-unary-ops": [
    244. 2,
    245. {
    246. words: true,
    247. nonwords: false,
    248. },
    249. ],
    250. "spaced-comment": [
    251. 2,
    252. "always",
    253. {
    254. markers: [
    255. "global",
    256. "globals",
    257. "eslint",
    258. "eslint-disable",
    259. "*package",
    260. "!",
    261. ",",
    262. ],
    263. },
    264. ],
    265. "template-curly-spacing": [2, "never"],
    266. "use-isnan": 2,
    267. "valid-typeof": 2,
    268. "wrap-iife": [2, "any"],
    269. "yield-star-spacing": [2, "both"],
    270. yoda: [2, "never"],
    271. "prefer-const": 2,
    272. "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0,
    273. "object-curly-spacing": [
    274. 2,
    275. "always",
    276. {
    277. objectsInObjects: false,
    278. },
    279. ],
    280. "array-bracket-spacing": [2, "never"],
    281. },
    282. };

    .eslintignore

    1. node_modules/
    2. # 忽略build目录下类型为js的文件的语法检查
    3. build_config/*.js
    4. # 忽略src/assets目录下文件的语法检查
    5. src/assets
    6. # 忽略public目录下文件的语法检查
    7. public/*
    8. # 忽略打包后的dist目录下文件的语法检查
    9. dist/
    10. # 忽略当前目录下为js的文件的语法检查
    11. /*.js
    12. # 忽略当前目录下为vue的文件的语法检查
    13. /*.vue

    .editorconfig

    1. # 告诉EditorConfig插件,这是根文件,不用继续往上查找
    2. root = true
    3. # 匹配全部文件
    4. [*]
    5. # 设置字符集
    6. charset = utf-8
    7. # 缩进风格,可选space、tab
    8. indent_style = space
    9. # 缩进的空格数
    10. indent_size = 2
    11. # 结尾换行符,可选lf、cr、crlf
    12. end_of_line = lf
    13. # 在文件结尾插入新行
    14. insert_final_newline = true
    15. # 删除一行中的前后空格
    16. trim_trailing_whitespace = true
    17. # 匹配md结尾的文件
    18. [*.md]
    19. insert_final_newline = false
    20. trim_trailing_whitespace = false

    3. .vscode-->setting.json文件配置

    1. {
    2. "editor.tabSize": 2,
    3. "editor.formatOnSave": true, // 在保存时自动格式化
    4. "editor.formatOnType": false, // 在键入一行后是否自动化格式
    5. "editor.formatOnPaste": false, // 在粘贴时自动格式化
    6. "editor.detectIndentation": false, // vscode 默认是启用根据文件类型自动设置 tabSize 的值
    7. // 保存时按照哪个规则进行格式化
    8. "editor.codeActionsOnSave": {
    9. "source.fixAll.eslint": true
    10. },
    11. // "editor.defaultFormatter": "octref.vetur", //这个不注释可能会影响配置的eslint规则
    12. "scss.lint.duplicateProperties": "warning",
    13. "less.lint.duplicateProperties": "warning",
    14. "css.lint.duplicateProperties": "warning",
    15. "scss.lint.float": "warning",
    16. "html.format.extraLiners": ""
    17. }

     ---------------------------------------

    eslint配置单引号失效

    我看eslintrc中有配置单引号

    是因为配置冲突了,去掉这个配置就可以了。

    参考:
    cvscode vue 格式化 ESLint 检查 单引号 双引号 函数括号报错问题 - JavaShuo

    ESLint在Vue中的使用详解_老哥二娃的博客-CSDN博客_vue的eslint

    干货!EsLint的自动修复设置!_徐飞不会喝酒的博客-CSDN博客_eslint 自动修复

  • 相关阅读:
    干货技巧分享:怎么把图片转文字?
    以下代码运行可外接设备串口摄像头COM5的一个静止图像,如何修改才能实现获取图像数据的刷新,让运行弹出窗口的图像有实时显示功能
    今天组里新入职一个31岁的校招生
    蓝桥杯嵌入式STM32G431RBT6知识点(主观题部分)
    【NAS 折腾】个人音乐库解决方案-Music-Tag-Web
    趁着中秋节来临之际,学学如何做好团队管理
    Android MediaCodec message机制分析
    linux————zabbix搭建
    算法:JavaScript语言描述
    nginx版本号隐藏(405 not allowed解决办法)
  • 原文地址:https://blog.csdn.net/u010856177/article/details/126850070