eslint-plugin-lube 0.2.5 → 0.3.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.
@@ -0,0 +1,240 @@
1
+ /**
2
+ * @param {keyof import("estree").ExpressionMap} type
3
+ * @param {string} value
4
+ * @returns {import("eslint").RuleTester.InvalidTestCase}
5
+ */
6
+ const test_case = (type, value) => ({
7
+ code: `
8
+ var value = /** @type {A} */(${value})
9
+ var value = /** @type {B} */(${value}) // comment...
10
+ var value = /** @type {C} */(
11
+ ${value} // comment...
12
+ )
13
+ var value = /** @type {D} */((${value}))
14
+ var value = ((/** @type {E} */(${value})))
15
+ `,
16
+ errors: [
17
+ {
18
+ line: 2,
19
+ column: 13,
20
+ type
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
+ }
42
+ ],
43
+ output: `
44
+ var value = /** @type {A} */(${value})/**/
45
+ var value = /** @type {B} */(${value})/**/ // comment...
46
+ var value =
47
+ /** @type {C} */(${value})/**/ // comment...
48
+
49
+ var value = /** @type {D} */((${value}))/**/
50
+ var value = ((/** @type {E} */(${value})/**/))
51
+ `,
52
+ parserOptions: { ecmaVersion: "latest" }
53
+ })
54
+
55
+ /**
56
+ * @param {import("eslint").RuleTester.ValidTestCase[]} valid
57
+ * @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
58
+ */
59
+ exports.module = (valid, invalid) => {
60
+ invalid.push(
61
+ test_case("ArrayExpression", "[a, b, c]"),
62
+ test_case("ArrowFunctionExpression", "(a, b) => c"),
63
+ test_case("AssignmentExpression", "a = b"),
64
+ {
65
+ code: `
66
+ async function a() {
67
+ /** @type {A} */(await b);
68
+ /** @type {B} */(await b); // comment...
69
+ /** @type {C} */(
70
+ await b // comment...
71
+ );
72
+ /** @type {D} */((await b));
73
+ ((/** @type {E} */(await b)));
74
+ }
75
+ `,
76
+ errors: [
77
+ {
78
+ line: 2,
79
+ column: 24,
80
+ type: "AwaitExpression"
81
+ },
82
+ {
83
+ line: 3,
84
+ column: 31,
85
+ type: "AwaitExpression"
86
+ },
87
+ {
88
+ line: 4,
89
+ column: 31,
90
+ type: "AwaitExpression"
91
+ },
92
+ {
93
+ line: 7,
94
+ column: 7,
95
+ type: "AwaitExpression"
96
+ },
97
+ {
98
+ line: 8,
99
+ column: 33,
100
+ type: "AwaitExpression"
101
+ }
102
+ ],
103
+ output: `
104
+ async function a() {
105
+ /** @type {A} */(await b)/**/;
106
+ /** @type {B} */(await b)/**/; // comment...
107
+
108
+ /** @type {C} */(await b)/**/ // comment...
109
+ ;
110
+ /** @type {D} */((await b))/**/;
111
+ ((/** @type {E} */(await b)/**/));
112
+ }
113
+ `,
114
+ parserOptions: { ecmaVersion: "latest" }
115
+ },
116
+ test_case("BinaryExpression", "a / b"),
117
+ test_case("CallExpression", "a(b, c)"),
118
+ test_case("ChainExpression", "a?.b?.c"),
119
+ test_case("ClassExpression", "class { b = c }"),
120
+ test_case("ConditionalExpression", "a ? b : c"),
121
+ test_case("FunctionExpression", "function(a, b) { return c }"),
122
+ test_case("Identifier", "a"),
123
+ test_case("ImportExpression", "import('a')"),
124
+ test_case("Literal", "'a'"),
125
+ test_case("LogicalExpression", "a ?? b"),
126
+ test_case("MemberExpression", "a.b"),
127
+ {
128
+ code: `
129
+ function a() {
130
+ /** @type {A} */(new.target);
131
+ /** @type {B} */(new.target); // comment...
132
+ /** @type {C} */(
133
+ new.target // comment...
134
+ );
135
+ /** @type {D} */((new.target));
136
+ ((/** @type {E} */(new.target)));
137
+ }
138
+ `,
139
+ errors: [
140
+ {
141
+ line: 2,
142
+ column: 18,
143
+ type: "MetaProperty"
144
+ },
145
+ {
146
+ line: 3,
147
+ column: 34,
148
+ type: "MetaProperty"
149
+ },
150
+ {
151
+ line: 4,
152
+ column: 34,
153
+ type: "MetaProperty"
154
+ },
155
+ {
156
+ line: 7,
157
+ column: 7,
158
+ type: "MetaProperty"
159
+ },
160
+ {
161
+ line: 8,
162
+ column: 36,
163
+ type: "MetaProperty"
164
+ }
165
+ ],
166
+ output: `
167
+ function a() {
168
+ /** @type {A} */(new.target)/**/;
169
+ /** @type {B} */(new.target)/**/; // comment...
170
+
171
+ /** @type {C} */(new.target)/**/ // comment...
172
+ ;
173
+ /** @type {D} */((new.target))/**/;
174
+ ((/** @type {E} */(new.target)/**/));
175
+ }
176
+ `,
177
+ parserOptions: { ecmaVersion: "latest" }
178
+ },
179
+ test_case("NewExpression", "new a(b, c)"),
180
+ test_case("ObjectExpression", "{ a: b, c }"),
181
+ test_case("SequenceExpression", "a, b, c"),
182
+ test_case("TaggedTemplateExpression", "a`b${c}`"),
183
+ test_case("TemplateLiteral", "`a${b}c`"),
184
+ test_case("ThisExpression", "this"),
185
+ test_case("UnaryExpression", "!a"),
186
+ test_case("UpdateExpression", "++a"),
187
+ {
188
+ code: `
189
+ function* a() {
190
+ /** @type {A} */(yield b);
191
+ /** @type {B} */(yield b); // comment...
192
+ /** @type {C} */(
193
+ yield b // comment...
194
+ );
195
+ /** @type {D} */((yield b));
196
+ ((/** @type {E} */(yield b)));
197
+ }
198
+ `,
199
+ errors: [
200
+ {
201
+ line: 2,
202
+ column: 19,
203
+ type: "YieldExpression"
204
+ },
205
+ {
206
+ line: 3,
207
+ column: 31,
208
+ type: "YieldExpression"
209
+ },
210
+ {
211
+ line: 4,
212
+ column: 31,
213
+ type: "YieldExpression"
214
+ },
215
+ {
216
+ line: 7,
217
+ column: 7,
218
+ type: "YieldExpression"
219
+ },
220
+ {
221
+ line: 8,
222
+ column: 33,
223
+ type: "YieldExpression"
224
+ }
225
+ ],
226
+ output: `
227
+ function* a() {
228
+ /** @type {A} */(yield b)/**/;
229
+ /** @type {B} */(yield b)/**/; // comment...
230
+
231
+ /** @type {C} */(yield b)/**/ // comment...
232
+ ;
233
+ /** @type {D} */((yield b))/**/;
234
+ ((/** @type {E} */(yield b)/**/));
235
+ }
236
+ `,
237
+ parserOptions: { ecmaVersion: "latest" }
238
+ }
239
+ )
240
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @param {import("eslint").RuleTester.ValidTestCase[]} valid
3
+ * @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
4
+ */
5
+ exports.module = (valid, invalid) => {
6
+ valid.push(
7
+ {
8
+ code: `var v = func(
9
+ a
10
+ )`
11
+ },
12
+ {
13
+ code: "var v = /** @type {A} */(/** @type {B} */(/** @type {C} */(a)/**/)/**/)/**/"
14
+ },
15
+ {
16
+ code: "var v = /** @type {A} */(a)/**/()"
17
+ },
18
+ {
19
+ code: "var v = { b: /** @type {A} */(a)/**/ }"
20
+ },
21
+ {
22
+ code: `var v = /** @type {V} */({
23
+ a: /** @type {A} */([/** @type {B} */(b)/**/, /** @type {C} */(c)/**/, /** @type {D} */(d)/**/])/**/,
24
+ e: /** @type {F} */(f)/**/(/** @type {G} */(g)/**/, /** @type {E} */(E)/**/, /** @type {I} */(i)/**/),
25
+ j: /** @type {K} */(k)/**/,
26
+ l: [.../** @type {M} */(m)/**/, .../** @type {N} */(n)/**/, .../** @type {O} */(o)/**/],
27
+ p: /** @type {Q} */(q.r)/**/,
28
+ s: /** @type {S} */(t())/**/,
29
+ u: /** @type {U} */({ v: /** @type {W} */(w)/**/ })/**/,
30
+ .../** @type {X} */(x)/**/
31
+ })/**/;
32
+ /** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)/**/])/**/)/**/`,
33
+ parserOptions: { ecmaVersion: "latest" }
34
+ }
35
+ )
36
+ invalid.push(
37
+ {
38
+ code: "var v = /**@type {A}*/(a)/**/",
39
+ errors: [{
40
+ column: 8,
41
+ line: 1
42
+ }],
43
+ output: "var v = /** @type {A} */(a)/**/"
44
+ },
45
+ {
46
+ code: "var v = /** @type {A} */( /** @type {B} */(/** @type {C} */((a) /* block... */))) // line...",
47
+ errors: [{
48
+ column: 8,
49
+ line: 1
50
+ }],
51
+ output: "var v = /** @type {A} */(/** @type {B} */(/** @type {C} */((a))/**/)/**/)/**/ /* block... */ // line..."
52
+ },
53
+ {
54
+ code: "var v = { b: /** @type {A} */(a) }",
55
+ errors: [{
56
+ column: 13,
57
+ line: 1
58
+ }],
59
+ output: "var v = { b: /** @type {A} */(a)/**/ }"
60
+ },
61
+ {
62
+ code: "var v = { b: /** @type {A} */(a) }",
63
+ errors: [{
64
+ column: 13,
65
+ line: 1
66
+ }],
67
+ output: "var v = { b: /** @type {A} */(a)/**/ }"
68
+ },
69
+ {
70
+ code: `var v = /** @type {V} */({
71
+ a: /** @type {A} */([/** @type {B} */(b), /** @type {C} */(c), /** @type {D} */(d)]),
72
+ e: /** @type {F} */(f)(/** @type {G} */(g), /** @type {E} */(E), /** @type {I} */(i)),
73
+ j: /** @type {K} */(k),
74
+ l: [.../** @type {M} */(m), .../** @type {N} */(n), .../** @type {O} */(o)],
75
+ p: /** @type {Q} */(q.r),
76
+ s: /** @type {S} */(t()),
77
+ u: /** @type {U} */({ v: /** @type {W} */(w) }),
78
+ .../** @type {X} */(x)
79
+ });
80
+ /** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)]))`,
81
+ errors: [...new Array(21).fill({})],
82
+ output: `var v = /** @type {V} */({
83
+ a: /** @type {A} */([/** @type {B} */(b)/**/, /** @type {C} */(c)/**/, /** @type {D} */(d)/**/])/**/,
84
+ e: /** @type {F} */(f)/**/(/** @type {G} */(g)/**/, /** @type {E} */(E)/**/, /** @type {I} */(i)/**/),
85
+ j: /** @type {K} */(k)/**/,
86
+ l: [.../** @type {M} */(m)/**/, .../** @type {N} */(n)/**/, .../** @type {O} */(o)/**/],
87
+ p: /** @type {Q} */(q.r)/**/,
88
+ s: /** @type {S} */(t())/**/,
89
+ u: /** @type {U} */({ v: /** @type {W} */(w)/**/ })/**/,
90
+ .../** @type {X} */(x)/**/
91
+ })/**/;
92
+ /** @type {Y} */(y, /** @type {Z} */(z[/** @type {123} */(123)/**/])/**/)/**/`,
93
+ parserOptions: { ecmaVersion: "latest" }
94
+ }
95
+ )
96
+ }
@@ -0,0 +1,19 @@
1
+ "use strict"
2
+ const { RuleTester } = require("eslint")
3
+
4
+ /** @type {RuleTester.ValidTestCase[]} */
5
+ const valid = []
6
+ /** @type {RuleTester.InvalidTestCase[]} */
7
+ const invalid = []
8
+
9
+ require("./pretty-jsdoc-casting/case_by_expression").module(valid, invalid)
10
+ require("./pretty-jsdoc-casting/nested_casting").module(valid, invalid)
11
+
12
+ new RuleTester().run(
13
+ "pretty-jsdoc-casting",
14
+ require("../rules/pretty-jsdoc-casting"),
15
+ {
16
+ valid,
17
+ invalid
18
+ }
19
+ )
@@ -1,7 +1,3 @@
1
- const error = {
2
- messageId: "not_match",
3
- type: "Identifier"
4
- }
5
1
  /**
6
2
  * @param {import("eslint").RuleTester.ValidTestCase[]} valid
7
3
  * @param {import("eslint").RuleTester.InvalidTestCase[]} invalid
@@ -24,7 +20,6 @@ exports.module = (valid, invalid) => {
24
20
  {
25
21
  code: "var camelCase = 'Hello'",
26
22
  errors: [{
27
- ...error,
28
23
  line: 1,
29
24
  column: 5
30
25
  }],
@@ -33,7 +28,6 @@ exports.module = (valid, invalid) => {
33
28
  {
34
29
  code: "var NO_SNAKE__CASE = 'Hello'",
35
30
  errors: [{
36
- ...error,
37
31
  line: 1,
38
32
  column: 5
39
33
  }],
@@ -42,7 +36,6 @@ exports.module = (valid, invalid) => {
42
36
  {
43
37
  code: "var NO_SNAKE_CASE_ = 'Hello'",
44
38
  errors: [{
45
- ...error,
46
39
  line: 1,
47
40
  column: 5
48
41
  }],