@houheaven/eslint-config-helper 1.4.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +149 -28
  3. package/lib/format-es5.js +23 -0
  4. package/lib/format-es6.js +25 -0
  5. package/lib/format-html.js +23 -0
  6. package/lib/format-import.js +23 -0
  7. package/lib/format-typescript.js +28 -0
  8. package/lib/format-vue2.js +23 -0
  9. package/lib/format-vue3.js +23 -0
  10. package/lib/html.js +16 -22
  11. package/lib/import.js +26 -0
  12. package/lib/javascript-es5.js +25 -0
  13. package/lib/javascript-es6.js +28 -0
  14. package/lib/support/es5-support.js +29 -0
  15. package/lib/support/es6-support.js +39 -0
  16. package/lib/support/html-support.js +38 -0
  17. package/lib/support/import-bugfix.js +65 -0
  18. package/lib/support/import-support.js +25 -0
  19. package/lib/support/typescript-support.js +27 -0
  20. package/lib/support/vue2-support.js +43 -0
  21. package/lib/support/vue3-support.js +43 -0
  22. package/lib/support/vue3-ts-support.js +51 -0
  23. package/lib/typescript.js +27 -32
  24. package/lib/utils/utils.js +2 -0
  25. package/lib/vue2.js +19 -22
  26. package/lib/vue3-ts.js +32 -0
  27. package/lib/vue3.js +16 -17
  28. package/node_modules/@houheaven/eslint-config-helper-core/package.json +7 -0
  29. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_deprecated.js +132 -0
  30. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/_removed.js +25 -0
  31. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/es6.js +365 -0
  32. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/layout-formatting.js +441 -0
  33. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/possible-errors.js +199 -0
  34. package/node_modules/@houheaven/eslint-config-helper-core/rules/eslint/suggestions.js +666 -0
  35. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/accessibility.js +68 -0
  36. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/best-practice.js +150 -0
  37. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/seo.js +29 -0
  38. package/node_modules/@houheaven/eslint-config-helper-core/rules/html/style.js +70 -0
  39. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/import/helpful-warnings.js +23 -18
  40. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/module-systems.js +33 -0
  41. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/static-analysis.js +85 -0
  42. package/node_modules/@houheaven/eslint-config-helper-core/rules/import/style-guide.js +125 -0
  43. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/_deprecated.js +57 -0
  44. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/conflict.js +16 -0
  45. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/deprecated.js +41 -0
  46. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/extension.js +207 -0
  47. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/fixable.js +215 -0
  48. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/other.js +125 -0
  49. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/stylistic.js +34 -0
  50. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/suggestion.js +53 -0
  51. package/node_modules/@houheaven/eslint-config-helper-core/rules/typescript/type-checked.js +263 -0
  52. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/_deprecated.js +37 -0
  53. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-base.js +1 -11
  54. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-essential.js +25 -38
  55. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-extension.js +321 -0
  56. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-recommended.js +64 -31
  57. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/common-strongly-recommended.js +37 -20
  58. package/{lib/rules/vue/common-extra.js → node_modules/@houheaven/eslint-config-helper-core/rules/vue/common-uncategorized.js} +141 -52
  59. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue2-essential.js +16 -14
  60. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue2-uncategorized.js +15 -0
  61. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-essential.js +54 -24
  62. package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vue/vue3-strongly-recommended.js +8 -10
  63. package/node_modules/@houheaven/eslint-config-helper-core/rules/vue/vue3-uncategorized.js +115 -0
  64. package/node_modules/@houheaven/eslint-config-helper-core/summary.js +57 -0
  65. package/node_modules/@houheaven/eslint-config-helper-core/utils/utils.js +160 -0
  66. package/package.json +59 -25
  67. package/lib/configs/eslint-es5.js +0 -24
  68. package/lib/configs/eslint.js +0 -23
  69. package/lib/configs/format-html.js +0 -22
  70. package/lib/configs/format-js.js +0 -134
  71. package/lib/configs/format-vue.js +0 -278
  72. package/lib/configs/html.js +0 -20
  73. package/lib/configs/import-bugfix.js +0 -36
  74. package/lib/configs/import.js +0 -44
  75. package/lib/configs/typescript.js +0 -10
  76. package/lib/configs/vue2.js +0 -28
  77. package/lib/configs/vue3.js +0 -28
  78. package/lib/eslint.js +0 -18
  79. package/lib/format.js +0 -40
  80. package/lib/rules/eslint/best-practices.js +0 -422
  81. package/lib/rules/eslint/es6.js +0 -196
  82. package/lib/rules/eslint/node.js +0 -48
  83. package/lib/rules/eslint/possible-errors.js +0 -190
  84. package/lib/rules/eslint/strict-mode.js +0 -12
  85. package/lib/rules/eslint/stylistic-issues.js +0 -578
  86. package/lib/rules/eslint/variables.js +0 -73
  87. package/lib/rules/html/accessibility.js +0 -44
  88. package/lib/rules/html/best-practice.js +0 -64
  89. package/lib/rules/html/seo.js +0 -24
  90. package/lib/rules/html/style.js +0 -32
  91. package/lib/rules/import/module-systems.js +0 -34
  92. package/lib/rules/import/static-analysis.js +0 -69
  93. package/lib/rules/import/style-guide.js +0 -97
  94. package/lib/rules/typescript/all.js +0 -193
  95. package/lib/rules/typescript/base.js +0 -10
  96. package/lib/rules/typescript/eslint-recommended.js +0 -36
  97. package/lib/rules/typescript/recommended-requiring-type-checking.js +0 -26
  98. package/lib/rules/typescript/recommended.js +0 -36
  99. package/lib/rules/typescript/strict.js +0 -47
  100. package/lib/rules/vue/common-eslint.js +0 -220
  101. package/lib/rules/vue/vue2-recommended.js +0 -17
  102. package/lib/rules/vue/vue2-strongly-recommended.js +0 -16
  103. package/lib/rules/vue/vue3-recommended.js +0 -17
  104. /package/{lib → node_modules/@houheaven/eslint-config-helper-core}/rules/vuejs-accessibility/index.js +0 -0
@@ -0,0 +1,68 @@
1
+
2
+ // ==========================================================
3
+ // 可访问性(Accessibility)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 禁止使用抽象的 role 属性
9
+ // https://html-eslint.org/docs/rules/no-abstract-roles
10
+ "@html-eslint/no-abstract-roles": "error",
11
+
12
+ // 禁止使用 accesskey 属性(为元素分配键盘快捷键)
13
+ // https://html-eslint.org/docs/rules/no-accesskey-attrs
14
+ "@html-eslint/no-accesskey-attrs": "error",
15
+
16
+ // 禁止在 body 标签上使用 aria-hidden 属性
17
+ // https://html-eslint.org/docs/rules/no-aria-hidden-body
18
+ "@html-eslint/no-aria-hidden-body": "error",
19
+
20
+ // 禁止在可聚焦元素上使用 aria-hidden="true"
21
+ // https://html-eslint.org/docs/rules/no-aria-hidden-on-focusable
22
+ "@html-eslint/no-aria-hidden-on-focusable": "error",
23
+
24
+ // 要求所有标题元素(h1–h6)以及具有“heading”角色的元素都必须有可访问的文本内容
25
+ // https://html-eslint.org/docs/rules/no-empty-headings
26
+ "@html-eslint/no-empty-headings": "off",
27
+
28
+ // 禁止在 <button> 内使用标题元素
29
+ // https://html-eslint.org/docs/rules/no-heading-inside-button
30
+ "@html-eslint/no-heading-inside-button": "error",
31
+
32
+ // 禁止在元素上使用无效的 ARIA role
33
+ // https://html-eslint.org/docs/rules/no-invalid-role
34
+ "@html-eslint/no-invalid-role": "error",
35
+
36
+ // 禁止 <meta name="viewport"> 使用 user-scalable=no
37
+ // https://html-eslint.org/docs/rules/no-non-scalable-viewport
38
+ "@html-eslint/no-non-scalable-viewport": "off",
39
+
40
+ // 禁止 tabindex 属性值为正数
41
+ // https://html-eslint.org/docs/rules/no-positive-tabindex
42
+ "@html-eslint/no-positive-tabindex": "off",
43
+
44
+ // 禁止 h1-h6 越级显示
45
+ // https://html-eslint.org/docs/rules/no-skip-heading-levels
46
+ "@html-eslint/no-skip-heading-levels": "error",
47
+
48
+ // 强制要求在 <form> 元素上使用有效的 method 属性
49
+ // https://html-eslint.org/docs/rules/require-form-method
50
+ "@html-eslint/require-form-method": "off",
51
+
52
+ // 要求 frame、iframe 标签设置 title 属性
53
+ // https://html-eslint.org/docs/rules/require-frame-title
54
+ "@html-eslint/require-frame-title": "error",
55
+
56
+ // 要求 img 标签必须设置 alt 属性
57
+ // https://html-eslint.org/docs/rules/require-img-alt
58
+ "@html-eslint/require-img-alt": "error",
59
+
60
+ // 强制要求为输入元素(如<input type="text">, <select>和<textarea>)提供无障碍标签
61
+ // https://html-eslint.org/docs/rules/require-input-label
62
+ "@html-eslint/require-input-label": "off",
63
+
64
+ // 要求 <head> 中必须设置 <meta name="viewport">
65
+ // https://html-eslint.org/docs/rules/require-meta-viewport
66
+ "@html-eslint/require-meta-viewport": "error",
67
+ },
68
+ };
@@ -0,0 +1,150 @@
1
+
2
+ // ==========================================================
3
+ // 最佳实践(Best Practice)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 强制规定 HTML 元素嵌套的最大允许深度
9
+ // https://html-eslint.org/docs/rules/max-element-depth
10
+ "@html-eslint/max-element-depth": ["error", {
11
+ max: 8,
12
+ }],
13
+
14
+ // 禁止使用重复的属性
15
+ // https://html-eslint.org/docs/rules/no-duplicate-attrs
16
+ "@html-eslint/no-duplicate-attrs": "error",
17
+
18
+ // 禁止 class 属性中的类名重复
19
+ // https://html-eslint.org/docs/rules/no-duplicate-class
20
+ "@html-eslint/no-duplicate-class": "warn",
21
+
22
+ // 禁止 id 属性重复
23
+ // https://html-eslint.org/docs/rules/no-duplicate-id
24
+ "@html-eslint/no-duplicate-id": "error",
25
+
26
+ // <head> 标签中禁止使用重复的元素(<title>、<base>、<meta charset>、<meta name="viewport">、<link rel="canonical">)
27
+ // https://html-eslint.org/docs/rules/no-duplicate-in-head
28
+ "@html-eslint/no-duplicate-in-head": "error",
29
+
30
+ // 禁止使用行内样式
31
+ // https://html-eslint.org/docs/rules/no-inline-styles
32
+ "@html-eslint/no-inline-styles": "error",
33
+
34
+ // 禁止使用无效的 HTML 实体
35
+ // https://html-eslint.org/docs/rules/no-invalid-entity
36
+ "@html-eslint/no-invalid-entity": "error",
37
+
38
+ // 禁止交互元素之间相互嵌套
39
+ // https://html-eslint.org/docs/rules/no-nested-interactive
40
+ "@html-eslint/no-nested-interactive": "error",
41
+
42
+ // 禁止在 HTML5 中使用过时的标签
43
+ // applet, acronym, bgsound, dir, frame, frameset, noframes, isindex, keygen, listing, menuitem, nextid, noembed,
44
+ // plaintext, rb, rtc, strike, xmp, basefont, big, blink, center, font, marquee, multicol, nobr, spacer, tt
45
+ // https://html-eslint.org/docs/rules/no-obsolete-tags
46
+ "@html-eslint/no-obsolete-tags": "error",
47
+
48
+ // 禁止使用指定的属性值
49
+ // https://html-eslint.org/docs/rules/no-restricted-attr-values
50
+ "@html-eslint/no-restricted-attr-values": [
51
+ "error",
52
+ {
53
+ attrPatterns: ["class", "alt"],
54
+ attrValuePatterns: ["data-test-.*"],
55
+ message: "'data-test-x' is restricted.",
56
+ },
57
+ {
58
+ attrPatterns: [".*"],
59
+ attrValuePatterns: ["^fooooo$"],
60
+ message: "'fooooo' is restricted.",
61
+ },
62
+ ],
63
+
64
+ // 禁用特定的属性
65
+ // https://html-eslint.org/docs/rules/no-restricted-attrs
66
+ "@html-eslint/no-restricted-attrs": [
67
+ "error",
68
+ {
69
+ tagPatterns: ["^div$", "^img$"],
70
+ attrPatterns: ["test-.*"],
71
+ message: "'test-x' is restricted.",
72
+ },
73
+ {
74
+ tagPatterns: ["^p$"],
75
+ attrPatterns: ["^test$"],
76
+ message: "'test' is restricted.",
77
+ },
78
+ ],
79
+
80
+ // 禁止在 <style> 中使用类型属性(除非不使用CSS),以及在 <script> 中使用类型属性(除非使用的语言与CSS/JavaScript不同)
81
+ // HTML5 默认值如下:
82
+ // <script> - type="text/javascript"
83
+ // <style>, <link> - type="text/css"
84
+ // https://html-eslint.org/docs/rules/no-script-style-type
85
+ "@html-eslint/no-script-style-type": "off",
86
+
87
+ // 禁止使用不安全的 target='_blank' 属性(需要加上 rel="noreferrer")
88
+ // https://html-eslint.org/docs/rules/no-target-blank
89
+ "@html-eslint/no-target-blank": "off",
90
+
91
+ // 强制要求使用 HTTPS 处理嵌入的资源(image、media、style、script)
92
+ // https://html-eslint.org/docs/rules/prefer-https
93
+ "@html-eslint/prefer-https": "off",
94
+
95
+ // 强制要求使用指定属性
96
+ // https://html-eslint.org/docs/rules/require-attrs
97
+ "@html-eslint/require-attrs": [
98
+ "error",
99
+ {
100
+ tag: "img",
101
+ attr: "alt",
102
+ },
103
+ {
104
+ tag: "test-svg",
105
+ attr: "viewBox",
106
+ value: "0 0 100 100",
107
+ },
108
+ ],
109
+
110
+ // 强制要求 button 标签设置一个有效的 type 属性
111
+ // https://html-eslint.org/docs/rules/require-button-type
112
+ "@html-eslint/require-button-type": "off",
113
+
114
+ // 强制要求标签闭合
115
+ // https://html-eslint.org/docs/rules/require-closing-tags
116
+ "@html-eslint/require-closing-tags": ["warn", {
117
+ selfClosing: "always",
118
+ selfClosingCustomPatterns: ["-"],
119
+ }],
120
+
121
+ // 强制要求设置 <!DOCTYPE html> 文档申明
122
+ // https://html-eslint.org/docs/rules/require-doctype
123
+ "@html-eslint/require-doctype": "warn",
124
+
125
+ // 强制要求某些元素(如 img 和 iframe)必须明确设置宽度和高度属性
126
+ // https://html-eslint.org/docs/rules/require-explicit-size
127
+ "@html-eslint/require-explicit-size": ["off", {
128
+ allowClass: ["has-size-class"],
129
+ allowId: ["has-size-id", "has-size-id2"],
130
+ }],
131
+
132
+ // 强制 <li> 必须包裹在 <ul>、<ol>、<menu> 中
133
+ // https://html-eslint.org/docs/rules/require-li-container
134
+ "@html-eslint/require-li-container": "error",
135
+
136
+ // 强制在 <head> 中使用 <meta charset="..."> 文件编码
137
+ // https://html-eslint.org/docs/rules/require-meta-charset
138
+ "@html-eslint/require-meta-charset": "error",
139
+
140
+ // 该规则强制使用基线特征
141
+ // 新推出(Newly available):该功能适用于最新的设备和浏览器版本,该功能可能在较旧设备或浏览器上无法使用
142
+ // 广泛可用(Widely available):该功能已确立并得到广泛支持,适用于多种设备和浏览器版本,它已经在多个浏览器中提供至少两年半(30个月)了
143
+ // https://html-eslint.org/docs/rules/use-baseline
144
+ "@html-eslint/use-baseline": ["error", {
145
+ // available: "newly",
146
+ available: "widely",
147
+ // available: 2020,
148
+ }],
149
+ },
150
+ };
@@ -0,0 +1,29 @@
1
+
2
+ // ==========================================================
3
+ // 搜索引擎优化(SEO)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 禁止多个 <h1> 标签
9
+ // https://html-eslint.org/docs/rules/no-multiple-h1
10
+ "@html-eslint/no-multiple-h1": "error",
11
+
12
+ // 强制要求 <html> 标签必须有 lang 属性
13
+ // https://html-eslint.org/docs/rules/require-lang
14
+ "@html-eslint/require-lang": "off",
15
+
16
+ // 强制要求 <head> 标签中必须有 <meta name="description" ...>
17
+ // https://html-eslint.org/docs/rules/require-meta-description
18
+ "@html-eslint/require-meta-description": "error",
19
+
20
+ // 强制要求使用指定的元标签以实现开放图协议
21
+ // 默认值:["og:title", "og:type", "og:url", "og:image"]
22
+ // https://html-eslint.org/docs/rules/require-open-graph-protocol
23
+ "@html-eslint/require-open-graph-protocol": "off",
24
+
25
+ // 强制要求 <head> 标签中必须有 <title> 标签
26
+ // https://html-eslint.org/docs/rules/require-title
27
+ "@html-eslint/require-title": "error",
28
+ },
29
+ };
@@ -0,0 +1,70 @@
1
+
2
+ // ==========================================================
3
+ // 样式(Style)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 元素属性数量超过指定数量时,强制在属性之间添加换行符
9
+ // https://html-eslint.org/docs/rules/attrs-newline
10
+ "@html-eslint/attrs-newline": ["warn", {
11
+ ifAttrsMoreThan: 6,
12
+ closeStyle: "newline",
13
+ }],
14
+
15
+ // 要求标签之间使用换行
16
+ // https://html-eslint.org/docs/rules/element-newline
17
+ "@html-eslint/element-newline": ["warn", {
18
+ skip: ["pre", "code", "tr", "label", "h1"],
19
+ // 行内元素可以不用换行
20
+ inline: ["$inline"],
21
+ }],
22
+
23
+ // 强制 id 属性命名规范
24
+ // 取值:camelCase、snake_case、PascalCase、kebab-case
25
+ // https://html-eslint.org/docs/rules/id-naming-convention
26
+ "@html-eslint/id-naming-convention": ["error", "kebab-case"],
27
+
28
+ // 强制使用一致的缩进
29
+ // https://html-eslint.org/docs/rules/indent
30
+ "@html-eslint/indent": ["warn", 2, {
31
+ Attribute: 1,
32
+ tagChildrenIndent: {
33
+ html: 0,
34
+ },
35
+ }],
36
+
37
+ // 强制标签和属性名称使用小写
38
+ // https://html-eslint.org/docs/rules/lowercase
39
+ "@html-eslint/lowercase": "warn",
40
+
41
+ // 禁止标签属性周围出现多余的空格
42
+ // https://html-eslint.org/docs/rules/no-extra-spacing-attrs
43
+ "@html-eslint/no-extra-spacing-attrs": ["warn", {
44
+ enforceBeforeSelfClose: true,
45
+ disallowMissing: true,
46
+ disallowTabs: true,
47
+ disallowInAssignment: true,
48
+ }],
49
+
50
+ // 禁止文本和注释中有多个连续的空格或 tab
51
+ // https://html-eslint.org/docs/rules/no-extra-spacing-text
52
+ "@html-eslint/no-extra-spacing-text": ["warn", {
53
+ skip: ["pre"],
54
+ }],
55
+
56
+ // 禁止出现多个空行
57
+ // https://html-eslint.org/docs/rules/no-multiple-empty-lines
58
+ "@html-eslint/no-multiple-empty-lines": ["warn", { max: 2 }],
59
+
60
+ // 禁止出现行末空格
61
+ // https://html-eslint.org/docs/rules/no-trailing-spaces
62
+ "@html-eslint/no-trailing-spaces": "warn",
63
+
64
+ // 强制使用一致的引号
65
+ // https://html-eslint.org/docs/rules/quotes
66
+ "@html-eslint/quotes": ["warn", "double", {
67
+ enforceTemplatedAttrValue: true,
68
+ }],
69
+ },
70
+ };
@@ -6,25 +6,21 @@
6
6
  module.exports = {
7
7
  rules: {
8
8
  // 禁止无效的导出(重复导出名称或默认值)
9
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
9
+ // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/export.md
10
10
  "import/export": "error",
11
11
 
12
- // do not allow a default import name to match a named export
13
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
14
- "import/no-named-as-default": "error",
12
+ // 禁止导入被 JSDoc(@deprecated)、TomDoc(Deprecated:)标记为废弃的函数
13
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-deprecated.md
14
+ "import/no-deprecated": "error",
15
15
 
16
- // warn on accessing default export property names that are also named exports
17
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
18
- "import/no-named-as-default-member": "error",
19
-
20
- // 禁止使用 jsdoc-marked-deprecated 导入
21
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
22
- "import/no-deprecated": "off",
16
+ // 禁止空的命名导入块
17
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-empty-named-blocks.md
18
+ "import/no-empty-named-blocks": "warn",
23
19
 
24
20
  // 禁止使用无关的包
25
- // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
21
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-extraneous-dependencies.md
26
22
  // paths are treated both as absolute paths, and relative to process.cwd()
27
- "import/no-extraneous-dependencies": ["error", {
23
+ "import/no-extraneous-dependencies": ["off", {
28
24
  devDependencies: [
29
25
  "test/**", // tape, common npm pattern
30
26
  "tests/**", // also common npm pattern
@@ -55,14 +51,23 @@ module.exports = {
55
51
  // 禁止使用易变的导出(var、let)
56
52
  // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
57
53
  "import/no-mutable-exports": "error",
54
+
55
+ // 禁止命名后的变量、函数作为默认导入的名称
56
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-as-default.md
57
+ "import/no-named-as-default": "error",
58
+
59
+ // warn on accessing default export property names that are also named exports
60
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-as-default-member.md
61
+ "import/no-named-as-default-member": "error",
58
62
 
59
- // Reports modules without any exports, or with unused exports
60
- // https://github.com/benmosher/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
61
- // TODO: enable once it supports CJS
63
+ // 模块没有任何导出,或者导出后,没有被项目其他文件所使用
64
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unused-modules.md
62
65
  "import/no-unused-modules": ["off", {
66
+ missingExports: false, // 文件中没有任何导出 export
67
+ unusedExports: true, // 文件导出后,没有被项目其他文件所使用
68
+ ignoreUnusedTypeExports: false, // 是否忽略 TS 中未使用的类型声明
63
69
  ignoreExports: [],
64
- missingExports: true,
65
- unusedExports: true,
70
+ // src: [],
66
71
  }],
67
72
  },
68
73
  };
@@ -0,0 +1,33 @@
1
+
2
+ // ==========================================================
3
+ // 模块系统(Module Systems)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 禁用 AMD require/define
9
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-amd.md
10
+ "import/no-amd": "error",
11
+
12
+ // 禁用 commonjs require()
13
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-commonjs.md
14
+ "import/no-commonjs": "off",
15
+
16
+ // 除了主模块以外,在使用 CommonJS 导出的任何文件中都不能使用 import 声明
17
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-import-module-exports.md
18
+ "import/no-import-module-exports": ["error", {
19
+ exceptions: [],
20
+ }],
21
+
22
+ // 禁用 Node.js 内置模块
23
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-nodejs-modules.md
24
+ "import/no-nodejs-modules": ["off", {
25
+ "allow": ["path"],
26
+ }],
27
+
28
+ // 强制导入模块时使用绝对路径或相对路径,而不是别名或别名路径
29
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/unambiguous.md
30
+ "import/unambiguous": "off",
31
+
32
+ },
33
+ };
@@ -0,0 +1,85 @@
1
+
2
+ // ==========================================================
3
+ // 静态分析(Static Analysis)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 确保默认导入时,原模块中存在默认导出
9
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/default.md
10
+ "import/default": "error",
11
+
12
+ // 在导入 Node.js 内置模块时,可以强制使用或省略 "node:" 协议。
13
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/enforce-node-protocol-usage.md
14
+ "import/enforce-node-protocol-usage": ["warn", "never"],
15
+
16
+ // 确保命名导入时,原模块中存在导出的值
17
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/named.md
18
+ "import/named": "error",
19
+
20
+ // 确保命名空间导入时,原模块中存在导出的值
21
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/namespace.md
22
+ "import/namespace": ["error", {
23
+ allowComputed: false,
24
+ }],
25
+
26
+ // 禁止使用绝对路径导入模块
27
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-absolute-path.md
28
+ "import/no-absolute-path": "warn",
29
+
30
+ // 禁止模块间的死循环相互导入
31
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-cycle.md
32
+ "import/no-cycle": ["error", {
33
+ maxDepth: "∞",
34
+ ignoreExternal: true,
35
+ }],
36
+
37
+ // 禁止 require() 使用表达式调用
38
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-dynamic-require.md
39
+ "import/no-dynamic-require": "error",
40
+
41
+ // 防止导入其他模块的子模块
42
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-internal-modules.md
43
+ "import/no-internal-modules": ["off", {
44
+ allow: [],
45
+ }],
46
+
47
+ // 防止通过相对路径导入包
48
+ // 适用于类似 monorepo 仓库中,不能通过相对路径来引入包
49
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-relative-packages.md
50
+ "import/no-relative-packages": "off",
51
+
52
+ // 防止导入到相对父路径中的文件夹
53
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-relative-parent-imports.md
54
+ "import/no-relative-parent-imports": "off",
55
+
56
+ // 限制特定文件夹中的文件不能被导入
57
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
58
+ "import/no-restricted-paths": "off",
59
+
60
+ // 禁止模块导入自身
61
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-self-import.md
62
+ "import/no-self-import": "error",
63
+
64
+ // 确保导入的文件/模块必须存在
65
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unresolved.md
66
+ "import/no-unresolved": ["error", {
67
+ amd: true,
68
+ commonjs: true,
69
+ caseSensitive: true,
70
+ caseSensitiveStrict: true,
71
+ // ignore: [],
72
+ }],
73
+
74
+ // 导入时防止出现不必要的路径部分
75
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-useless-path-segments.md
76
+ "import/no-useless-path-segments": ["warn", {
77
+ commonjs: true,
78
+ noUselessIndex: false,
79
+ }],
80
+
81
+ // 禁止在导入时使用 webpack loader 语法
82
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-webpack-loader-syntax.md
83
+ "import/no-webpack-loader-syntax": "error",
84
+ },
85
+ };
@@ -0,0 +1,125 @@
1
+
2
+ // ==========================================================
3
+ // 风格指南(Style Guide)
4
+ // ==========================================================
5
+
6
+ module.exports = {
7
+ rules: {
8
+ // 一致的导入类型指定符样式
9
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/consistent-type-specifier-style.md
10
+ "import/consistent-type-specifier-style": ["warn", "prefer-top-level"],
11
+
12
+ // 动态导入时要求携带 webpackChunkName 注释
13
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/dynamic-import-chunkname.md
14
+ "import/dynamic-import-chunkname": ["error", {
15
+ importFunctions: [],
16
+ webpackChunknameFormat: "[0-9a-zA-Z-_/.]+",
17
+ allowEmpty: true,
18
+ }],
19
+
20
+ // export 要放在文件最后面
21
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/exports-last.md
22
+ "import/exports-last": "error",
23
+
24
+ // 文件后缀名
25
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/extensions.md
26
+ "import/extensions": ["error", "always", {
27
+ ignorePackages: true,
28
+ pattern: {
29
+ ts: "never",
30
+ },
31
+ }],
32
+
33
+ // import 要放在文件最前面
34
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/first.md
35
+ "import/first": "warn",
36
+
37
+ // 一个文件中保留一个导出出口(易辨识、易维护)
38
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/group-exports.md
39
+ "import/group-exports": "error",
40
+
41
+ // import 要放在文件最前面(已废弃)
42
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
43
+ // deprecated: use `import/first`
44
+ // "import/imports-first": "off",
45
+
46
+ // 禁止模块有太多的依赖
47
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/max-dependencies.md
48
+ "import/max-dependencies": ["off", {
49
+ max: 10,
50
+ ignoreTypeImports: true,
51
+ }],
52
+
53
+ // 强制在最后一个顶级导入 import 语句或 require 调用之后有一个或多个空行
54
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/newline-after-import.md
55
+ "import/newline-after-import": ["off", {
56
+ count: 1,
57
+ exactCount: true,
58
+ considerComments: false,
59
+ }],
60
+
61
+ // 要求默认导出的值必须先定义
62
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-anonymous-default-export.md
63
+ "import/no-anonymous-default-export": ["off", {
64
+ allowArray: false,
65
+ allowArrowFunction: false,
66
+ allowAnonymousClass: false,
67
+ allowAnonymousFunction: false,
68
+ allowLiteral: false,
69
+ allowObject: false,
70
+ }],
71
+
72
+ // 禁止默认导出
73
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-default-export.md
74
+ "import/no-default-export": "off",
75
+
76
+ // 禁止在多个地方重复导入同一模块
77
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md
78
+ "import/no-duplicates": ["warn", {
79
+ "considerQueryString": true,
80
+ "prefer-inline": false,
81
+ }],
82
+
83
+ // import 时不能使用 default 关键字
84
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-default.md
85
+ "import/no-named-default": "error",
86
+
87
+ // 禁止命名导出
88
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-named-export.md
89
+ "import/no-named-export": "off",
90
+
91
+ // 禁止命名空间(又名“通配符” *)导入
92
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-namespace.md
93
+ "import/no-namespace": "warn",
94
+
95
+ // 禁止未分配的导入
96
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-unassigned-import.md
97
+ // importing for side effects is perfectly acceptable, if you need side effects.
98
+ "import/no-unassigned-import": ["error", {
99
+ allow: [
100
+ "**/*.css",
101
+ "**/*.less",
102
+ "**/*.styl",
103
+ "echarts/**/*.*",
104
+ ],
105
+ }],
106
+
107
+ // import 导入排序
108
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/order.md
109
+ "import/order": ["warn", {
110
+ groups: [
111
+ "builtin",
112
+ ["external", "internal"],
113
+ // "parent",
114
+ // "sibling",
115
+ // "index",
116
+ // "object",
117
+ // "type",
118
+ ],
119
+ }],
120
+
121
+ // 当一个模块只有一个导出时,更喜欢使用默认导出而不是命名导出
122
+ // https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/prefer-default-export.md
123
+ "import/prefer-default-export": "error",
124
+ },
125
+ };