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