eslint-plugin-lube 0.3.5 → 0.4.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.
- package/README.md +1 -0
- package/docs/pretty-imports.md +11 -24
- package/docs/pretty-sequence.md +113 -0
- package/docs/svelte-naming-convention.md +7 -8
- package/index.js +61 -82
- package/package.json +33 -25
- package/private.d.ts +79 -42
- package/rules/pretty-imports.js +28 -42
- package/rules/pretty-jsdoc-casting.js +30 -22
- package/rules/pretty-sequence.js +417 -0
- package/rules/svelte-naming-convention.js +33 -29
- package/test/pretty-imports/ExportNamedDeclaration.js +6 -12
- package/test/pretty-imports/ImportDeclaration.js +6 -12
- package/test/pretty-imports.js +7 -6
- package/test/pretty-jsdoc-casting/case_by_expression.js +33 -32
- package/test/pretty-jsdoc-casting/{nested_casting.js → various_situations.js} +6 -28
- package/test/pretty-jsdoc-casting.js +10 -7
- package/test/pretty-sequence/case_by_node_type.js +328 -0
- package/test/pretty-sequence/case_by_option.js +111 -0
- package/test/pretty-sequence/various_situations.js +168 -0
- package/test/pretty-sequence.js +23 -0
- package/test/svelte-naming-convention/basic_snake_case.js +30 -27
- package/test/svelte-naming-convention/case_by_identifier.js +134 -549
- package/test/svelte-naming-convention/snake_case_with_symbols.js +16 -28
- package/test/svelte-naming-convention.js +13 -8
- package/tsconfig.json +1 -1
|
@@ -11,21 +11,20 @@ module.exports = {
|
|
|
11
11
|
messages: {
|
|
12
12
|
not_match: "Identifier '{{name}}' does not match for svelte's naming conventions."
|
|
13
13
|
},
|
|
14
|
-
schema: [
|
|
14
|
+
schema: [
|
|
15
15
|
{
|
|
16
16
|
properties: {
|
|
17
|
-
fixSameNames: {
|
|
18
|
-
type: "boolean",
|
|
19
|
-
default: true
|
|
20
|
-
}
|
|
17
|
+
fixSameNames: { type: "boolean", default: true }
|
|
21
18
|
},
|
|
22
19
|
type: "object"
|
|
23
|
-
}
|
|
20
|
+
}
|
|
24
21
|
],
|
|
25
22
|
type: "layout"
|
|
26
23
|
},
|
|
27
24
|
create(context) {
|
|
28
|
-
|
|
25
|
+
/** @type {import("../private").RuleOptions["svelte-naming-convention"]} */
|
|
26
|
+
const option = context.options[0]
|
|
27
|
+
const fix_same_names = option?.fixSameNames ?? true
|
|
29
28
|
|
|
30
29
|
// let name | const name | class name
|
|
31
30
|
const allow_regex = /^[_$]?[_$]?(?:[\da-z]+(?:_[\da-z]+)*\$?\$?)?$|^[A-Z](?:_?[\dA-Z]+)*$|^(?:[\dA-Z][\da-z]*)+$/
|
|
@@ -33,10 +32,10 @@ module.exports = {
|
|
|
33
32
|
const fix_regex = /([\da-z]?)([A-Z][\dA-Z]*)/g
|
|
34
33
|
const camel_case_regex = /^[\da-z]+([A-Z][\da-z]*)*$/
|
|
35
34
|
|
|
36
|
-
/** @type {Set<string>} */
|
|
37
|
-
const reported_declarations = new Set()
|
|
38
35
|
/** @type {Map<string, import("../private").AstNode[]>} */
|
|
39
36
|
const pending_usages = new Map()
|
|
37
|
+
/** @type {Set<string>} */
|
|
38
|
+
const reported_declarations = new Set()
|
|
40
39
|
/** @type {Set<import("../private").AstNode>} */
|
|
41
40
|
const shortand_properties = new Set()
|
|
42
41
|
|
|
@@ -58,42 +57,44 @@ module.exports = {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
60
|
/**
|
|
63
61
|
* @param {string} _
|
|
64
62
|
* @param {string} a
|
|
65
63
|
* @param {string} b
|
|
66
64
|
* @returns {string}
|
|
67
65
|
*/
|
|
68
|
-
function
|
|
66
|
+
function fix_handler(_, a, b) {
|
|
69
67
|
return a + (a ? "_" : "") + b.toLowerCase()
|
|
70
68
|
}
|
|
71
|
-
|
|
72
69
|
/**
|
|
73
70
|
* @param {import("../private").AstNode & import("estree").Identifier} node
|
|
74
71
|
* @returns {void}
|
|
75
72
|
*/
|
|
76
73
|
function report(node) {
|
|
77
74
|
const name = node.name
|
|
78
|
-
context.report(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
context.report(
|
|
76
|
+
{
|
|
77
|
+
data: { name },
|
|
78
|
+
fix(fixer) {
|
|
79
|
+
if (fixable_name_regex.test(name)) {
|
|
80
|
+
return fixer.replaceTextRange(
|
|
81
|
+
node.range,
|
|
82
|
+
(shortand_properties.has(node) ? node.name + ": " : "")
|
|
83
|
+
+ node.name.replace(fix_regex, fix_handler)
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
return null
|
|
87
|
+
},
|
|
88
|
+
messageId: "not_match",
|
|
89
|
+
node: /** @type {import("estree").Node} */(node)/**/
|
|
90
|
+
}
|
|
91
|
+
)
|
|
93
92
|
if (fix_same_names) {
|
|
94
93
|
const usages = pending_usages.get(name)
|
|
95
94
|
while (usages?.length) {
|
|
96
|
-
report(
|
|
95
|
+
report(
|
|
96
|
+
/** @type {import("../private").AstNode & import("estree").Identifier} */(usages.pop())/**/
|
|
97
|
+
)
|
|
97
98
|
}
|
|
98
99
|
reported_declarations.add(name)
|
|
99
100
|
}
|
|
@@ -264,7 +265,10 @@ module.exports = {
|
|
|
264
265
|
// var value = { key: value }
|
|
265
266
|
// var { key: value } = value
|
|
266
267
|
if (parent.value == node) {
|
|
267
|
-
if (
|
|
268
|
+
if (
|
|
269
|
+
parent.key.type == "Identifier"
|
|
270
|
+
&& parent.key.name == parent.value.name
|
|
271
|
+
) {
|
|
268
272
|
shortand_properties.add(node)
|
|
269
273
|
}
|
|
270
274
|
defer(node)
|
|
@@ -10,7 +10,7 @@ exports.module = (valid, invalid) => {
|
|
|
10
10
|
export { a, b as c, d } from 'module'
|
|
11
11
|
export { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
12
12
|
`,
|
|
13
|
-
options: [{ maxLength: 30 }],
|
|
13
|
+
options: [ { maxLength: 30 } ],
|
|
14
14
|
parserOptions: {
|
|
15
15
|
ecmaVersion: "latest",
|
|
16
16
|
sourceType: "module"
|
|
@@ -21,7 +21,7 @@ exports.module = (valid, invalid) => {
|
|
|
21
21
|
var a, b, c
|
|
22
22
|
export { a, b, c };
|
|
23
23
|
`,
|
|
24
|
-
options: [{ semicolon: true }],
|
|
24
|
+
options: [ { semicolon: true } ],
|
|
25
25
|
parserOptions: {
|
|
26
26
|
ecmaVersion: "latest",
|
|
27
27
|
sourceType: "module"
|
|
@@ -49,11 +49,8 @@ exports.module = (valid, invalid) => {
|
|
|
49
49
|
column: 7
|
|
50
50
|
}
|
|
51
51
|
],
|
|
52
|
-
options: [
|
|
53
|
-
{
|
|
54
|
-
maxLength: 10,
|
|
55
|
-
semicolon: true
|
|
56
|
-
}
|
|
52
|
+
options: [
|
|
53
|
+
{ maxLength: 10, semicolon: true }
|
|
57
54
|
],
|
|
58
55
|
output: `
|
|
59
56
|
|
|
@@ -93,11 +90,8 @@ exports.module = (valid, invalid) => {
|
|
|
93
90
|
column: 7
|
|
94
91
|
}
|
|
95
92
|
],
|
|
96
|
-
options: [
|
|
97
|
-
{
|
|
98
|
-
indent: " ",
|
|
99
|
-
maxLength: 10
|
|
100
|
-
}
|
|
93
|
+
options: [
|
|
94
|
+
{ indent: " ", maxLength: 10 }
|
|
101
95
|
],
|
|
102
96
|
output: `
|
|
103
97
|
|
|
@@ -10,7 +10,7 @@ exports.module = (valid, invalid) => {
|
|
|
10
10
|
import { a, b as c, d } from 'module'
|
|
11
11
|
import { fff, ggg, hhh, iii, jjj, kkk, lll } from 'module/2'
|
|
12
12
|
`,
|
|
13
|
-
options: [{ maxLength: 30 }],
|
|
13
|
+
options: [ { maxLength: 30 } ],
|
|
14
14
|
parserOptions: {
|
|
15
15
|
ecmaVersion: "latest",
|
|
16
16
|
sourceType: "module"
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
aaaaa_ccccc,
|
|
24
24
|
aaaaa_ddddd
|
|
25
25
|
} from "module";`,
|
|
26
|
-
options: [{ semicolon: true }],
|
|
26
|
+
options: [ { semicolon: true } ],
|
|
27
27
|
parserOptions: {
|
|
28
28
|
ecmaVersion: "latest",
|
|
29
29
|
sourceType: "module"
|
|
@@ -51,11 +51,8 @@ import {
|
|
|
51
51
|
column: 7
|
|
52
52
|
}
|
|
53
53
|
],
|
|
54
|
-
options: [
|
|
55
|
-
{
|
|
56
|
-
maxLength: 10,
|
|
57
|
-
semicolon: true
|
|
58
|
-
}
|
|
54
|
+
options: [
|
|
55
|
+
{ maxLength: 10, semicolon: true }
|
|
59
56
|
],
|
|
60
57
|
output: `
|
|
61
58
|
|
|
@@ -95,11 +92,8 @@ import {
|
|
|
95
92
|
column: 7
|
|
96
93
|
}
|
|
97
94
|
],
|
|
98
|
-
options: [
|
|
99
|
-
{
|
|
100
|
-
indent: " ",
|
|
101
|
-
maxLength: 10
|
|
102
|
-
}
|
|
95
|
+
options: [
|
|
96
|
+
{ indent: " ", maxLength: 10 }
|
|
103
97
|
],
|
|
104
98
|
output: `
|
|
105
99
|
|
package/test/pretty-imports.js
CHANGED
|
@@ -6,14 +6,15 @@ const valid = []
|
|
|
6
6
|
/** @type {RuleTester.InvalidTestCase[]} */
|
|
7
7
|
const invalid = []
|
|
8
8
|
|
|
9
|
-
require(
|
|
10
|
-
|
|
9
|
+
require(
|
|
10
|
+
"./pretty-imports/ExportNamedDeclaration"
|
|
11
|
+
).module(valid, invalid)
|
|
12
|
+
require(
|
|
13
|
+
"./pretty-imports/ImportDeclaration"
|
|
14
|
+
).module(valid, invalid)
|
|
11
15
|
|
|
12
16
|
new RuleTester().run(
|
|
13
17
|
"pretty-imports",
|
|
14
18
|
require("../rules/pretty-imports"),
|
|
15
|
-
{
|
|
16
|
-
valid,
|
|
17
|
-
invalid
|
|
18
|
-
}
|
|
19
|
+
{ valid, invalid }
|
|
19
20
|
)
|
|
@@ -14,31 +14,11 @@ const test_case = (type, value) => ({
|
|
|
14
14
|
var value = ((/** @type {E} */(${value})))
|
|
15
15
|
`,
|
|
16
16
|
errors: [
|
|
17
|
-
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
{
|
|
23
|
-
line: 3,
|
|
24
|
-
column: 13,
|
|
25
|
-
type
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
line: 4,
|
|
29
|
-
column: 13,
|
|
30
|
-
type
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
line: 7,
|
|
34
|
-
column: 13,
|
|
35
|
-
type
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
line: 8,
|
|
39
|
-
column: 13,
|
|
40
|
-
type
|
|
41
|
-
}
|
|
17
|
+
{ line: 2, column: 13, type },
|
|
18
|
+
{ line: 3, column: 13, type },
|
|
19
|
+
{ line: 4, column: 13, type },
|
|
20
|
+
{ line: 7, column: 13, type },
|
|
21
|
+
{ line: 8, column: 13, type }
|
|
42
22
|
],
|
|
43
23
|
output: `
|
|
44
24
|
var value = /** @type {A} */(${value})/**/
|
|
@@ -59,7 +39,10 @@ const test_case = (type, value) => ({
|
|
|
59
39
|
exports.module = (valid, invalid) => {
|
|
60
40
|
invalid.push(
|
|
61
41
|
test_case("ArrayExpression", "[a, b, c]"),
|
|
62
|
-
test_case(
|
|
42
|
+
test_case(
|
|
43
|
+
"ArrowFunctionExpression",
|
|
44
|
+
"(a, b) => c"
|
|
45
|
+
),
|
|
63
46
|
test_case("AssignmentExpression", "a = b"),
|
|
64
47
|
{
|
|
65
48
|
code: `
|
|
@@ -116,11 +99,23 @@ exports.module = (valid, invalid) => {
|
|
|
116
99
|
test_case("BinaryExpression", "a / b"),
|
|
117
100
|
test_case("CallExpression", "a(b, c)"),
|
|
118
101
|
test_case("ChainExpression", "a?.b?.c"),
|
|
119
|
-
test_case(
|
|
120
|
-
|
|
121
|
-
|
|
102
|
+
test_case(
|
|
103
|
+
"ClassExpression",
|
|
104
|
+
"class { b = c }"
|
|
105
|
+
),
|
|
106
|
+
test_case(
|
|
107
|
+
"ConditionalExpression",
|
|
108
|
+
"a ? b : c"
|
|
109
|
+
),
|
|
110
|
+
test_case(
|
|
111
|
+
"FunctionExpression",
|
|
112
|
+
"function(a, b) { return c }"
|
|
113
|
+
),
|
|
122
114
|
test_case("Identifier", "a"),
|
|
123
|
-
test_case(
|
|
115
|
+
test_case(
|
|
116
|
+
"ImportExpression",
|
|
117
|
+
"import('a')"
|
|
118
|
+
),
|
|
124
119
|
test_case("Literal", "'a'"),
|
|
125
120
|
test_case("LogicalExpression", "a ?? b"),
|
|
126
121
|
test_case("MemberExpression", "a.b"),
|
|
@@ -177,9 +172,15 @@ exports.module = (valid, invalid) => {
|
|
|
177
172
|
parserOptions: { ecmaVersion: "latest" }
|
|
178
173
|
},
|
|
179
174
|
test_case("NewExpression", "new a(b, c)"),
|
|
180
|
-
test_case(
|
|
175
|
+
test_case(
|
|
176
|
+
"ObjectExpression",
|
|
177
|
+
"{ a: b, c }"
|
|
178
|
+
),
|
|
181
179
|
test_case("SequenceExpression", "a, b, c"),
|
|
182
|
-
test_case(
|
|
180
|
+
test_case(
|
|
181
|
+
"TaggedTemplateExpression",
|
|
182
|
+
"a`b${c}`"
|
|
183
|
+
),
|
|
183
184
|
test_case("TemplateLiteral", "`a${b}c`"),
|
|
184
185
|
test_case("ThisExpression", "this"),
|
|
185
186
|
test_case("UnaryExpression", "!a"),
|
|
@@ -9,9 +9,7 @@ exports.module = (valid, invalid) => {
|
|
|
9
9
|
a
|
|
10
10
|
)`
|
|
11
11
|
},
|
|
12
|
-
{
|
|
13
|
-
code: "a((b - c) / d)"
|
|
14
|
-
},
|
|
12
|
+
{ code: "a((b - c) / d)" },
|
|
15
13
|
{
|
|
16
14
|
code: "var v = /** @type {{}} */(a)/**/"
|
|
17
15
|
},
|
|
@@ -45,42 +43,22 @@ exports.module = (valid, invalid) => {
|
|
|
45
43
|
invalid.push(
|
|
46
44
|
{
|
|
47
45
|
code: "var v = /**@type {A}*/(a)/**/",
|
|
48
|
-
errors: [
|
|
49
|
-
{
|
|
50
|
-
column: 8,
|
|
51
|
-
line: 1
|
|
52
|
-
}
|
|
53
|
-
],
|
|
46
|
+
errors: [ { column: 8, line: 1 } ],
|
|
54
47
|
output: "var v = /** @type {A} */(a)/**/"
|
|
55
48
|
},
|
|
56
49
|
{
|
|
57
50
|
code: "var v = /** @type {A} */( /** @type {B} */(/** @type {C} */((a) /* block... */))) // line...",
|
|
58
|
-
errors: [
|
|
59
|
-
{
|
|
60
|
-
column: 8,
|
|
61
|
-
line: 1
|
|
62
|
-
}
|
|
63
|
-
],
|
|
51
|
+
errors: [ { column: 8, line: 1 } ],
|
|
64
52
|
output: "var v = /** @type {A} */(/** @type {B} */(/** @type {C} */((a))/**/)/**/)/**/ /* block... */ // line..."
|
|
65
53
|
},
|
|
66
54
|
{
|
|
67
55
|
code: "var v = { b: /** @type {A} */(a) }",
|
|
68
|
-
errors: [
|
|
69
|
-
{
|
|
70
|
-
column: 13,
|
|
71
|
-
line: 1
|
|
72
|
-
}
|
|
73
|
-
],
|
|
56
|
+
errors: [ { column: 13, line: 1 } ],
|
|
74
57
|
output: "var v = { b: /** @type {A} */(a)/**/ }"
|
|
75
58
|
},
|
|
76
59
|
{
|
|
77
60
|
code: "var v = { b: /** @type {A} */(a) }",
|
|
78
|
-
errors: [
|
|
79
|
-
{
|
|
80
|
-
column: 13,
|
|
81
|
-
line: 1
|
|
82
|
-
}
|
|
83
|
-
],
|
|
61
|
+
errors: [ { column: 13, line: 1 } ],
|
|
84
62
|
output: "var v = { b: /** @type {A} */(a)/**/ }"
|
|
85
63
|
},
|
|
86
64
|
{
|
|
@@ -95,7 +73,7 @@ exports.module = (valid, invalid) => {
|
|
|
95
73
|
.../** @type {X} */(x)
|
|
96
74
|
});
|
|
97
75
|
/** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)]))`,
|
|
98
|
-
errors: [...new Array(21).fill({})],
|
|
76
|
+
errors: [ ...new Array(21).fill({}) ],
|
|
99
77
|
output: `var v = /** @type {V} */({
|
|
100
78
|
a: /** @type {A} */([/** @type {B} */(b)/**/, /** @type {C} */(c)/**/, /** @type {D} */(d)/**/])/**/,
|
|
101
79
|
e: /** @type {F} */(f)/**/(/** @type {G} */(g)/**/, /** @type {E} */(E)/**/, /** @type {I} */(i)/**/),
|
|
@@ -6,14 +6,17 @@ const valid = []
|
|
|
6
6
|
/** @type {RuleTester.InvalidTestCase[]} */
|
|
7
7
|
const invalid = []
|
|
8
8
|
|
|
9
|
-
require(
|
|
10
|
-
|
|
9
|
+
require(
|
|
10
|
+
"./pretty-jsdoc-casting/case_by_expression"
|
|
11
|
+
).module(valid, invalid)
|
|
12
|
+
require(
|
|
13
|
+
"./pretty-jsdoc-casting/various_situations"
|
|
14
|
+
).module(valid, invalid)
|
|
11
15
|
|
|
12
16
|
new RuleTester().run(
|
|
13
17
|
"pretty-jsdoc-casting",
|
|
14
|
-
require(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
18
|
+
require(
|
|
19
|
+
"../rules/pretty-jsdoc-casting"
|
|
20
|
+
),
|
|
21
|
+
{ valid, invalid }
|
|
19
22
|
)
|