eslint-plugin-lube 0.5.1 → 0.7.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 (88) hide show
  1. package/CHANGELOG.md +283 -0
  2. package/LICENSE +21 -0
  3. package/README.md +123 -9
  4. package/docs/ascii-order.md +81 -0
  5. package/docs/prefer-type-tag.md +45 -0
  6. package/docs/pretty-imports.md +70 -59
  7. package/docs/pretty-jsdoc-casting.md +31 -23
  8. package/docs/pretty-sequence.md +129 -117
  9. package/docs/pretty-ternary.md +55 -0
  10. package/docs/svelte-naming-convention.md +59 -46
  11. package/package.json +60 -38
  12. package/src/index.js +308 -0
  13. package/src/rules/ascii-order.js +1032 -0
  14. package/src/rules/prefer-type-tag.js +165 -0
  15. package/src/rules/pretty-imports.js +188 -0
  16. package/src/rules/pretty-jsdoc-casting.js +325 -0
  17. package/src/rules/pretty-sequence.js +562 -0
  18. package/src/rules/pretty-ternary.js +255 -0
  19. package/src/rules/svelte-naming-convention.js +1062 -0
  20. package/src/utils/fix_recorder.js +50 -0
  21. package/src/utils/keep_body_comments.js +53 -0
  22. package/src/utils/keep_comments.js +103 -0
  23. package/src/utils/keep_line_breaks.js +58 -0
  24. package/src/utils/skip_hole_commas.js +34 -0
  25. package/src/utils/skip_optional_patterns.js +29 -0
  26. package/src/utils/skip_unchanged_fixes.js +37 -0
  27. package/src/utils/source_text.js +476 -0
  28. package/src/utils/split_declarations.js +75 -0
  29. package/src/utils/text_width.js +9 -0
  30. package/types/index.d.ts +27 -13
  31. package/types/index.d.ts.map +1 -1
  32. package/index.js +0 -126
  33. package/private.d.ts +0 -168
  34. package/rules/pretty-imports.js +0 -147
  35. package/rules/pretty-jsdoc-casting.js +0 -236
  36. package/rules/pretty-sequence.js +0 -441
  37. package/rules/svelte-naming-convention.js +0 -361
  38. package/test/pretty-imports/ExportNamedDeclaration.js +0 -123
  39. package/test/pretty-imports/ImportDeclaration.js +0 -125
  40. package/test/pretty-imports.js +0 -20
  41. package/test/pretty-jsdoc-casting/case_by_expression.js +0 -289
  42. package/test/pretty-jsdoc-casting/various_situations.js +0 -111
  43. package/test/pretty-jsdoc-casting.js +0 -22
  44. package/test/pretty-sequence/case_by_node_type.js +0 -360
  45. package/test/pretty-sequence/case_by_option.js +0 -142
  46. package/test/pretty-sequence/various_situations.js +0 -204
  47. package/test/pretty-sequence.js +0 -23
  48. package/test/svelte-naming-convention/basic_snake_case.js +0 -67
  49. package/test/svelte-naming-convention/case_by_identifier.js +0 -1394
  50. package/test/svelte-naming-convention/snake_case_with_symbols.js +0 -67
  51. package/test/svelte-naming-convention.js +0 -25
  52. package/tsconfig.json +0 -21
  53. package/types/rules/pretty-imports.d.ts +0 -3
  54. package/types/rules/pretty-imports.d.ts.map +0 -1
  55. package/types/rules/pretty-jsdoc-casting.d.ts +0 -3
  56. package/types/rules/pretty-jsdoc-casting.d.ts.map +0 -1
  57. package/types/rules/pretty-sequence.d.ts +0 -3
  58. package/types/rules/pretty-sequence.d.ts.map +0 -1
  59. package/types/rules/svelte-naming-convention.d.ts +0 -3
  60. package/types/rules/svelte-naming-convention.d.ts.map +0 -1
  61. package/types/test/pretty-imports/ExportNamedDeclaration.d.ts +0 -2
  62. package/types/test/pretty-imports/ExportNamedDeclaration.d.ts.map +0 -1
  63. package/types/test/pretty-imports/ImportDeclaration.d.ts +0 -2
  64. package/types/test/pretty-imports/ImportDeclaration.d.ts.map +0 -1
  65. package/types/test/pretty-imports.d.ts +0 -2
  66. package/types/test/pretty-imports.d.ts.map +0 -1
  67. package/types/test/pretty-jsdoc-casting/case_by_expression.d.ts +0 -2
  68. package/types/test/pretty-jsdoc-casting/case_by_expression.d.ts.map +0 -1
  69. package/types/test/pretty-jsdoc-casting/various_situations.d.ts +0 -2
  70. package/types/test/pretty-jsdoc-casting/various_situations.d.ts.map +0 -1
  71. package/types/test/pretty-jsdoc-casting.d.ts +0 -2
  72. package/types/test/pretty-jsdoc-casting.d.ts.map +0 -1
  73. package/types/test/pretty-sequence/case_by_node_type.d.ts +0 -2
  74. package/types/test/pretty-sequence/case_by_node_type.d.ts.map +0 -1
  75. package/types/test/pretty-sequence/case_by_option.d.ts +0 -2
  76. package/types/test/pretty-sequence/case_by_option.d.ts.map +0 -1
  77. package/types/test/pretty-sequence/various_situations.d.ts +0 -2
  78. package/types/test/pretty-sequence/various_situations.d.ts.map +0 -1
  79. package/types/test/pretty-sequence.d.ts +0 -2
  80. package/types/test/pretty-sequence.d.ts.map +0 -1
  81. package/types/test/svelte-naming-convention/basic_snake_case.d.ts +0 -2
  82. package/types/test/svelte-naming-convention/basic_snake_case.d.ts.map +0 -1
  83. package/types/test/svelte-naming-convention/case_by_identifier.d.ts +0 -2
  84. package/types/test/svelte-naming-convention/case_by_identifier.d.ts.map +0 -1
  85. package/types/test/svelte-naming-convention/snake_case_with_symbols.d.ts +0 -2
  86. package/types/test/svelte-naming-convention/snake_case_with_symbols.d.ts.map +0 -1
  87. package/types/test/svelte-naming-convention.d.ts +0 -2
  88. package/types/test/svelte-naming-convention.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,40 +1,62 @@
1
1
  {
2
- "author": "artxe2",
3
- "bugs": {
4
- "url": "https://github.com/Artxe2/lube-series/issues"
5
- },
6
- "description": "Full fixable rules for auto-formatting with ESLint only without Prettier",
7
- "devDependencies": {
8
- "@types/eslint": "^9.6.1",
9
- "@types/estree": "^1.0.8",
10
- "@typescript-eslint/parser": "^8.35.0",
11
- "eslint": "^9.29.0",
12
- "mocha": "^11.7.0",
13
- "typescript": "^5.8.3"
14
- },
15
- "keywords": [
16
- "eslint-plugin",
17
- "lube",
18
- "eslint-plugin-lube",
19
- "prettier",
20
- "jsdoc"
21
- ],
22
- "license": "MIT",
23
- "main": "index.js",
24
- "name": "eslint-plugin-lube",
25
- "peerDependencies": {
26
- "eslint": ">=9.0.0"
27
- },
28
- "repository": {
29
- "directory": "packages/eslint-plugin-lube",
30
- "type": "git",
31
- "url": "https://github.com/Artxe2/lube-series"
32
- },
33
- "scripts": {
34
- "dts": "node ../../scripts/tsc_with_clean.js eslint-plugin-lube",
35
- "test": "mocha"
36
- },
37
- "type": "commonjs",
38
- "types": "types/index.d.ts",
39
- "version": "0.5.1"
2
+ "author": "artxe",
3
+ "bugs": {
4
+ "url": "https://github.com/artxe/lube-series/issues"
5
+ },
6
+ "dependencies": {
7
+ "@stylistic/eslint-plugin": "^5.10.0"
8
+ },
9
+ "description": "Fixable ESLint rules that format code without Prettier",
10
+ "devDependencies": {
11
+ "@types/estree": "^1.0.9",
12
+ "@typescript/native": "npm:typescript@^7.0.2",
13
+ "eslint": "^10.10.0"
14
+ },
15
+ "engines": {
16
+ "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "types": "./types/index.d.ts",
21
+ "default": "./src/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "CHANGELOG.md",
26
+ "docs",
27
+ "src",
28
+ "types/index.*"
29
+ ],
30
+ "homepage": "https://github.com/artxe/lube-series/tree/master/packages/eslint-plugin-lube#readme",
31
+ "keywords": [
32
+ "eslint",
33
+ "eslint-plugin",
34
+ "eslint-plugin-lube",
35
+ "eslintplugin",
36
+ "formatting",
37
+ "jsdoc",
38
+ "lube",
39
+ "prettier",
40
+ "sort",
41
+ "svelte"
42
+ ],
43
+ "license": "MIT",
44
+ "main": "src/index.js",
45
+ "name": "eslint-plugin-lube",
46
+ "peerDependencies": {
47
+ "eslint": ">=9.0.0"
48
+ },
49
+ "repository": {
50
+ "directory": "packages/eslint-plugin-lube",
51
+ "type": "git",
52
+ "url": "https://github.com/artxe/lube-series"
53
+ },
54
+ "type": "module",
55
+ "types": "types/index.d.ts",
56
+ "version": "0.7.0",
57
+ "scripts": {
58
+ "dts": "node ../../scripts/tsc_with_clean.js eslint-plugin-lube",
59
+ "lint": "pnpm -w lint",
60
+ "test": "pnpm -w exec vitest run --coverage test/eslint-plugin-lube"
61
+ }
40
62
  }
package/src/index.js ADDED
@@ -0,0 +1,308 @@
1
+ import ascii_order from "./rules/ascii-order.js"
2
+ import prefer_type_tag from "./rules/prefer-type-tag.js"
3
+ import pretty_imports from "./rules/pretty-imports.js"
4
+ import pretty_jsdoc_casting from "./rules/pretty-jsdoc-casting.js"
5
+ import pretty_sequence from "./rules/pretty-sequence.js"
6
+ import pretty_ternary from "./rules/pretty-ternary.js"
7
+ import svelte_naming_convention from "./rules/svelte-naming-convention.js"
8
+ import { keep_body_comments } from "./utils/keep_body_comments.js"
9
+ import {
10
+ keep_comment_order,
11
+ keep_comments
12
+ } from "./utils/keep_comments.js"
13
+ import { keep_line_breaks } from "./utils/keep_line_breaks.js"
14
+ import { skip_hole_commas } from "./utils/skip_hole_commas.js"
15
+ import { skip_optional_patterns } from "./utils/skip_optional_patterns.js"
16
+ import { skip_unchanged_fixes } from "./utils/skip_unchanged_fixes.js"
17
+ import { split_declarations } from "./utils/split_declarations.js"
18
+ import stylistic_plugin from "@stylistic/eslint-plugin"
19
+ import { builtinRules } from "eslint/use-at-your-own-risk"
20
+ import { readFileSync } from "node:fs"
21
+ /** @type {import("eslint").ESLint.Plugin} */
22
+ const stylistic = stylistic_plugin
23
+ /** @type {{ version: string }} */
24
+ const manifest = JSON.parse(
25
+ readFileSync(
26
+ new URL(
27
+ "../package.json",
28
+ import.meta.url
29
+ ),
30
+ "utf8"
31
+ )
32
+ )
33
+ const brace_rules = /** @type {const} */([
34
+ "object-curly-newline",
35
+ "object-curly-spacing"
36
+ ])/**/
37
+ const spacing_rules = /** @type {const} */([
38
+ "generator-star-spacing",
39
+ "key-spacing",
40
+ "rest-spread-spacing",
41
+ "semi-spacing",
42
+ "space-unary-ops",
43
+ "yield-star-spacing"
44
+ ])/**/
45
+ /** @type {import("eslint").Linter.RulesRecord} */
46
+ const strict_rules = {
47
+ "@stylistic/array-bracket-newline": [ "error", "consistent" ],
48
+ "@stylistic/array-element-newline": [ "error", "consistent" ],
49
+ "@stylistic/arrow-parens": [ "error", "as-needed" ],
50
+ "@stylistic/arrow-spacing": [
51
+ "error",
52
+ { "after": true, "before": true }
53
+ ],
54
+ "@stylistic/block-spacing": [ "error", "always" ],
55
+ "@stylistic/brace-style": [ "error", "1tbs" ],
56
+ "@stylistic/comma-dangle": [ "error", "never" ],
57
+ "@stylistic/comma-spacing": [
58
+ "error",
59
+ { "after": true, "before": false }
60
+ ],
61
+ "@stylistic/comma-style": [ "error", "last" ],
62
+ "@stylistic/computed-property-spacing": [ "error", "never" ],
63
+ "@stylistic/dot-location": [ "error", "property" ],
64
+ "@stylistic/eol-last": [ "error", "never" ],
65
+ "@stylistic/function-call-argument-newline": [ "error", "consistent" ],
66
+ "@stylistic/function-call-spacing": [ "error", "never" ],
67
+ "@stylistic/generator-star-spacing": [ "error", "after" ],
68
+ "@stylistic/indent": [
69
+ "error",
70
+ "tab",
71
+ { "SwitchCase": 0 }
72
+ ],
73
+ "@stylistic/jsx-quotes": [ "error", "prefer-double" ],
74
+ "@stylistic/key-spacing": [
75
+ "error",
76
+ {
77
+ "afterColon": true,
78
+ "beforeColon": false
79
+ }
80
+ ],
81
+ "@stylistic/keyword-spacing": [
82
+ "error",
83
+ { "after": true, "before": true }
84
+ ],
85
+ "@stylistic/max-statements-per-line": [ "error", { "max": 1 } ],
86
+ "@stylistic/multiline-ternary": [ "error", "always-multiline" ],
87
+ "@stylistic/new-parens": "error",
88
+ "@stylistic/newline-per-chained-call": [
89
+ "error",
90
+ { "ignoreChainWithDepth": 2 }
91
+ ],
92
+ "@stylistic/no-extra-semi": "error",
93
+ "@stylistic/no-multi-spaces": "error",
94
+ "@stylistic/no-multiple-empty-lines": [
95
+ "error",
96
+ { "max": 0, "maxBOF": 0, "maxEOF": 0 }
97
+ ],
98
+ "@stylistic/no-trailing-spaces": [
99
+ "error",
100
+ {
101
+ "ignoreComments": false,
102
+ "skipBlankLines": false
103
+ }
104
+ ],
105
+ "@stylistic/object-curly-newline": [ "error", { "consistent": true } ],
106
+ "@stylistic/object-curly-spacing": [ "error", "always" ],
107
+ "@stylistic/operator-linebreak": [
108
+ "error",
109
+ "before",
110
+ { "overrides": { "=": "after" } }
111
+ ],
112
+ "@stylistic/quotes": [ "error", "double" ],
113
+ "@stylistic/rest-spread-spacing": [ "error", "never" ],
114
+ "@stylistic/semi": [ "error", "never" ],
115
+ "@stylistic/semi-spacing": [
116
+ "error",
117
+ { "after": true, "before": false }
118
+ ],
119
+ "@stylistic/semi-style": [ "error", "first" ],
120
+ "@stylistic/space-before-blocks": [ "error", "always" ],
121
+ "@stylistic/space-before-function-paren": [
122
+ "error",
123
+ {
124
+ "anonymous": "never",
125
+ "asyncArrow": "always",
126
+ "named": "never"
127
+ }
128
+ ],
129
+ "@stylistic/space-in-parens": [ "error", "never" ],
130
+ "@stylistic/space-infix-ops": [ "error", { "int32Hint": true } ],
131
+ "@stylistic/space-unary-ops": [
132
+ "error",
133
+ { "nonwords": false, "words": true }
134
+ ],
135
+ "@stylistic/switch-colon-spacing": [
136
+ "error",
137
+ { "after": true, "before": false }
138
+ ],
139
+ "@stylistic/template-curly-spacing": [ "error", "never" ],
140
+ "@stylistic/template-tag-spacing": [ "error", "never" ],
141
+ "@stylistic/yield-star-spacing": [ "error", "after" ],
142
+ "arrow-body-style": [ "error", "as-needed" ],
143
+ "func-style": [ "error", "declaration" ],
144
+ "lube/ascii-order": [
145
+ "error",
146
+ {
147
+ checkDeclarations: true,
148
+ checkImports: true,
149
+ checkKeys: true,
150
+ checkNames: true,
151
+ checkTests: true
152
+ }
153
+ ],
154
+ "lube/curly": [ "error", "all" ],
155
+ "lube/prefer-type-tag": "error",
156
+ "lube/pretty-imports": "error",
157
+ "lube/pretty-jsdoc-casting": "error",
158
+ "lube/pretty-sequence": "error",
159
+ "lube/pretty-ternary": "error",
160
+ "lube/svelte-naming-convention": "error",
161
+ "no-case-declarations": "off",
162
+ "no-console": "warn",
163
+ "no-duplicate-imports": [
164
+ "error",
165
+ {
166
+ "allowSeparateTypeImports": true
167
+ }
168
+ ],
169
+ "no-extra-boolean-cast": "error",
170
+ "no-lonely-if": "error",
171
+ "no-new-native-nonconstructor": "error",
172
+ "no-self-compare": "error",
173
+ "no-shadow": "error",
174
+ "no-shadow-restricted-names": "error",
175
+ "no-unneeded-ternary": "error",
176
+ "no-useless-computed-key": "error",
177
+ "no-useless-rename": "error",
178
+ "no-useless-return": "error",
179
+ "one-var": [ "error", "never" ],
180
+ "prefer-const": [
181
+ "warn",
182
+ {
183
+ "destructuring": "all",
184
+ "ignoreReadBeforeAssign": false
185
+ }
186
+ ],
187
+ "prefer-exponentiation-operator": "error",
188
+ "prefer-object-spread": "error",
189
+ "yoda": "error"
190
+ }
191
+ /** @type {import("eslint").Linter.RulesRecord} */
192
+ const recommended_rules = {
193
+ ...Object.fromEntries(
194
+ Object.entries(strict_rules).filter(
195
+ ([ name ]) => name.startsWith("@stylistic/") && name != "@stylistic/max-statements-per-line"
196
+ )
197
+ ),
198
+ "@stylistic/eol-last": [ "error", "always" ],
199
+ "@stylistic/no-multiple-empty-lines": [
200
+ "error",
201
+ { max: 1, maxBOF: 0, maxEOF: 0 }
202
+ ],
203
+ "lube/ascii-order": [
204
+ "error",
205
+ {
206
+ checkDeclarations: false,
207
+ checkImports: false,
208
+ checkKeys: false,
209
+ checkNames: true,
210
+ checkTests: false
211
+ }
212
+ ],
213
+ "lube/pretty-imports": [ "error", { maxLength: 80 } ],
214
+ "lube/pretty-jsdoc-casting": "error",
215
+ "lube/pretty-sequence": [ "error", { maxLength: 80 } ],
216
+ "lube/pretty-ternary": "error"
217
+ }
218
+ /**
219
+ * @type {import("eslint").ESLint.Plugin & {
220
+ * configs: {
221
+ * recommended: import("eslint").Linter.Config & {
222
+ * plugins: Record<string, import("eslint").ESLint.Plugin>
223
+ * rules: import("eslint").Linter.RulesRecord
224
+ * }
225
+ * strict: import("eslint").Linter.Config & {
226
+ * plugins: Record<string, import("eslint").ESLint.Plugin>
227
+ * rules: import("eslint").Linter.RulesRecord
228
+ * }
229
+ * }
230
+ * }}
231
+ */
232
+ const plugin = {
233
+ configs: {
234
+ recommended: {
235
+ plugins: {},
236
+ rules: recommended_rules
237
+ },
238
+ strict: { plugins: {}, rules: strict_rules }
239
+ },
240
+ meta: {
241
+ name: "eslint-plugin-lube",
242
+ version: manifest.version
243
+ },
244
+ rules: {
245
+ "ascii-order": ascii_order,
246
+ "curly": keep_body_comments(
247
+ /** @type {import("eslint").Rule.RuleModule} */(builtinRules.get("curly"))/**/
248
+ ),
249
+ "prefer-type-tag": prefer_type_tag,
250
+ "pretty-imports": pretty_imports,
251
+ "pretty-jsdoc-casting": pretty_jsdoc_casting,
252
+ "pretty-sequence": pretty_sequence,
253
+ "pretty-ternary": pretty_ternary,
254
+ "svelte-naming-convention": svelte_naming_convention
255
+ }
256
+ }
257
+ /** @type {Record<string, import("eslint").Rule.RuleModule>} */
258
+ const stylistic_rules = {
259
+ ...stylistic.rules,
260
+ "comma-style": skip_hole_commas(
261
+ /** @type {import("eslint").Rule.RuleModule} */(stylistic.rules?.["comma-style"])/**/
262
+ ),
263
+ "max-statements-per-line": split_declarations(
264
+ /** @type {import("eslint").Rule.RuleModule} */(stylistic.rules?.["max-statements-per-line"])/**/
265
+ ),
266
+ "operator-linebreak": keep_comment_order(
267
+ /** @type {import("eslint").Rule.RuleModule} */(stylistic.rules?.["operator-linebreak"])/**/
268
+ ),
269
+ ...Object.fromEntries(
270
+ brace_rules.map(
271
+ name => [
272
+ name,
273
+ skip_optional_patterns(
274
+ /** @type {Record<typeof brace_rules[number], import("eslint").Rule.RuleModule>} */(stylistic.rules)/**/[name]
275
+ )
276
+ ]
277
+ )
278
+ ),
279
+ ...Object.fromEntries(
280
+ spacing_rules.map(
281
+ name => [
282
+ name,
283
+ keep_comments(
284
+ /** @type {Record<typeof spacing_rules[number], import("eslint").Rule.RuleModule>} */(stylistic.rules)/**/[name]
285
+ )
286
+ ]
287
+ )
288
+ )
289
+ }
290
+ /** @type {Record<string, import("eslint").ESLint.Plugin>} */
291
+ const plugins = {
292
+ "@stylistic": {
293
+ ...stylistic,
294
+ rules: Object.fromEntries(
295
+ Object.entries(stylistic_rules).map(
296
+ ([ name, rule ]) => [
297
+ name,
298
+ skip_unchanged_fixes(keep_line_breaks(rule))
299
+ ]
300
+ )
301
+ )
302
+ },
303
+ "lube": plugin
304
+ }
305
+ plugin.configs.recommended.plugins = plugins
306
+ plugin.configs.strict.plugins = plugins
307
+ export default plugin
308
+ export { plugin as "module.exports" }