@valbuild/eslint-plugin 0.63.5 → 0.65.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/dist/valbuild-eslint-plugin.cjs.dev.js +113 -2
- package/dist/valbuild-eslint-plugin.cjs.prod.js +113 -2
- package/dist/valbuild-eslint-plugin.esm.js +113 -2
- package/package.json +2 -1
- package/src/index.js +7 -1
- package/src/rules/defaultExportValModule.js +85 -0
- package/src/rules/noDefineWithVariable.js +43 -0
- package/src/rules/noIllegalImports.js +1 -1
- package/src/rules/noIllegalModulePaths.js +2 -2
- package/test/plugin.test.js +2 -2
- package/test/rules/defaultExportValModule.test.js +76 -0
- package/test/rules/noDefineWithVariable.test.js +42 -0
@@ -168,13 +168,122 @@ var exportContentMustBeValid = {
|
|
168
168
|
|
169
169
|
// @ts-check
|
170
170
|
|
171
|
+
/**
|
172
|
+
* @type {import('eslint').Rule.RuleModule}
|
173
|
+
*/
|
174
|
+
var noDefineWithVariable = {
|
175
|
+
meta: {
|
176
|
+
type: "problem",
|
177
|
+
docs: {
|
178
|
+
description: "Cannot c.define with a variable",
|
179
|
+
recommended: true
|
180
|
+
},
|
181
|
+
fixable: "code",
|
182
|
+
schema: []
|
183
|
+
},
|
184
|
+
create: function create(context) {
|
185
|
+
return {
|
186
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
187
|
+
var decl = node.declaration;
|
188
|
+
if (decl.type === "CallExpression") {
|
189
|
+
var callee = decl.callee;
|
190
|
+
var isDefine = callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "c" && callee.property.type === "Identifier" && callee.property.name === "define";
|
191
|
+
if (isDefine) {
|
192
|
+
var args = decl.arguments;
|
193
|
+
var valueArg = args[2];
|
194
|
+
if (valueArg.type === "Identifier") {
|
195
|
+
context.report({
|
196
|
+
node: valueArg,
|
197
|
+
message: "Val: third argument of c.define cannot be a variable"
|
198
|
+
});
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
};
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
// @ts-check
|
208
|
+
|
209
|
+
var message = "Val: c.define must be exported as default";
|
210
|
+
/**
|
211
|
+
* @type {import('eslint').Rule.RuleModule}
|
212
|
+
*/
|
213
|
+
var defaultExportValModule = {
|
214
|
+
meta: {
|
215
|
+
type: "problem",
|
216
|
+
docs: {
|
217
|
+
description: "c.define must be exported as default",
|
218
|
+
recommended: true
|
219
|
+
},
|
220
|
+
fixable: "code",
|
221
|
+
schema: []
|
222
|
+
},
|
223
|
+
create: function create(context) {
|
224
|
+
return {
|
225
|
+
CallExpression: function CallExpression(node) {
|
226
|
+
if (node.callee.type === "MemberExpression") {
|
227
|
+
var memberExpression = node.callee;
|
228
|
+
if (memberExpression.object.type === "Identifier") {
|
229
|
+
var object = memberExpression.object;
|
230
|
+
if (object.name === "c" && memberExpression.property.type === "Identifier") {
|
231
|
+
var property = memberExpression.property;
|
232
|
+
if (property.name === "define") {
|
233
|
+
var parent = node.parent;
|
234
|
+
if (parent.type === "ExportDefaultDeclaration") {
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
if (parent.type === "VariableDeclarator") {
|
238
|
+
var variableInit = parent.init;
|
239
|
+
if (variableInit && parent.parent.type === "VariableDeclaration") {
|
240
|
+
context.report({
|
241
|
+
node: node,
|
242
|
+
message: message,
|
243
|
+
fix: function fix(fixer) {
|
244
|
+
return fixer.replaceText(parent.parent, "export default ".concat(context.sourceCode.getText(variableInit)));
|
245
|
+
}
|
246
|
+
});
|
247
|
+
} else {
|
248
|
+
context.report({
|
249
|
+
node: node,
|
250
|
+
message: message
|
251
|
+
});
|
252
|
+
}
|
253
|
+
} else if (parent.type === "ExpressionStatement" && parent.parent.type === "Program") {
|
254
|
+
context.report({
|
255
|
+
node: node,
|
256
|
+
message: message,
|
257
|
+
fix: function fix(fixer) {
|
258
|
+
return fixer.replaceText(parent, "export default ".concat(context.sourceCode.getText(parent)));
|
259
|
+
}
|
260
|
+
});
|
261
|
+
} else {
|
262
|
+
context.report({
|
263
|
+
node: node,
|
264
|
+
message: message
|
265
|
+
});
|
266
|
+
}
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
};
|
273
|
+
}
|
274
|
+
};
|
275
|
+
|
276
|
+
// @ts-check
|
277
|
+
|
171
278
|
/**
|
172
279
|
* @type {Plugin["rules"]}
|
173
280
|
*/
|
174
281
|
var rules = {
|
175
282
|
"no-illegal-module-paths": noIllegalModulePaths,
|
176
283
|
"no-illegal-imports": noIllegalImports,
|
177
|
-
"export-content-must-be-valid": exportContentMustBeValid
|
284
|
+
"export-content-must-be-valid": exportContentMustBeValid,
|
285
|
+
"no-define-with-variable": noDefineWithVariable,
|
286
|
+
"default-export-val-module": defaultExportValModule
|
178
287
|
};
|
179
288
|
|
180
289
|
/**
|
@@ -191,7 +300,9 @@ var configs = {
|
|
191
300
|
rules: {
|
192
301
|
"@valbuild/no-illegal-module-paths": "error",
|
193
302
|
"@valbuild/no-illegal-imports": "error",
|
194
|
-
"@valbuild/export-content-must-be-valid": "error"
|
303
|
+
"@valbuild/export-content-must-be-valid": "error",
|
304
|
+
"@valbuild/no-define-with-variable": "error",
|
305
|
+
"@valbuild/default-export-val-module": "error"
|
195
306
|
}
|
196
307
|
}
|
197
308
|
};
|
@@ -168,13 +168,122 @@ var exportContentMustBeValid = {
|
|
168
168
|
|
169
169
|
// @ts-check
|
170
170
|
|
171
|
+
/**
|
172
|
+
* @type {import('eslint').Rule.RuleModule}
|
173
|
+
*/
|
174
|
+
var noDefineWithVariable = {
|
175
|
+
meta: {
|
176
|
+
type: "problem",
|
177
|
+
docs: {
|
178
|
+
description: "Cannot c.define with a variable",
|
179
|
+
recommended: true
|
180
|
+
},
|
181
|
+
fixable: "code",
|
182
|
+
schema: []
|
183
|
+
},
|
184
|
+
create: function create(context) {
|
185
|
+
return {
|
186
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
187
|
+
var decl = node.declaration;
|
188
|
+
if (decl.type === "CallExpression") {
|
189
|
+
var callee = decl.callee;
|
190
|
+
var isDefine = callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "c" && callee.property.type === "Identifier" && callee.property.name === "define";
|
191
|
+
if (isDefine) {
|
192
|
+
var args = decl.arguments;
|
193
|
+
var valueArg = args[2];
|
194
|
+
if (valueArg.type === "Identifier") {
|
195
|
+
context.report({
|
196
|
+
node: valueArg,
|
197
|
+
message: "Val: third argument of c.define cannot be a variable"
|
198
|
+
});
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
};
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
// @ts-check
|
208
|
+
|
209
|
+
var message = "Val: c.define must be exported as default";
|
210
|
+
/**
|
211
|
+
* @type {import('eslint').Rule.RuleModule}
|
212
|
+
*/
|
213
|
+
var defaultExportValModule = {
|
214
|
+
meta: {
|
215
|
+
type: "problem",
|
216
|
+
docs: {
|
217
|
+
description: "c.define must be exported as default",
|
218
|
+
recommended: true
|
219
|
+
},
|
220
|
+
fixable: "code",
|
221
|
+
schema: []
|
222
|
+
},
|
223
|
+
create: function create(context) {
|
224
|
+
return {
|
225
|
+
CallExpression: function CallExpression(node) {
|
226
|
+
if (node.callee.type === "MemberExpression") {
|
227
|
+
var memberExpression = node.callee;
|
228
|
+
if (memberExpression.object.type === "Identifier") {
|
229
|
+
var object = memberExpression.object;
|
230
|
+
if (object.name === "c" && memberExpression.property.type === "Identifier") {
|
231
|
+
var property = memberExpression.property;
|
232
|
+
if (property.name === "define") {
|
233
|
+
var parent = node.parent;
|
234
|
+
if (parent.type === "ExportDefaultDeclaration") {
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
if (parent.type === "VariableDeclarator") {
|
238
|
+
var variableInit = parent.init;
|
239
|
+
if (variableInit && parent.parent.type === "VariableDeclaration") {
|
240
|
+
context.report({
|
241
|
+
node: node,
|
242
|
+
message: message,
|
243
|
+
fix: function fix(fixer) {
|
244
|
+
return fixer.replaceText(parent.parent, "export default ".concat(context.sourceCode.getText(variableInit)));
|
245
|
+
}
|
246
|
+
});
|
247
|
+
} else {
|
248
|
+
context.report({
|
249
|
+
node: node,
|
250
|
+
message: message
|
251
|
+
});
|
252
|
+
}
|
253
|
+
} else if (parent.type === "ExpressionStatement" && parent.parent.type === "Program") {
|
254
|
+
context.report({
|
255
|
+
node: node,
|
256
|
+
message: message,
|
257
|
+
fix: function fix(fixer) {
|
258
|
+
return fixer.replaceText(parent, "export default ".concat(context.sourceCode.getText(parent)));
|
259
|
+
}
|
260
|
+
});
|
261
|
+
} else {
|
262
|
+
context.report({
|
263
|
+
node: node,
|
264
|
+
message: message
|
265
|
+
});
|
266
|
+
}
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
};
|
273
|
+
}
|
274
|
+
};
|
275
|
+
|
276
|
+
// @ts-check
|
277
|
+
|
171
278
|
/**
|
172
279
|
* @type {Plugin["rules"]}
|
173
280
|
*/
|
174
281
|
var rules = {
|
175
282
|
"no-illegal-module-paths": noIllegalModulePaths,
|
176
283
|
"no-illegal-imports": noIllegalImports,
|
177
|
-
"export-content-must-be-valid": exportContentMustBeValid
|
284
|
+
"export-content-must-be-valid": exportContentMustBeValid,
|
285
|
+
"no-define-with-variable": noDefineWithVariable,
|
286
|
+
"default-export-val-module": defaultExportValModule
|
178
287
|
};
|
179
288
|
|
180
289
|
/**
|
@@ -191,7 +300,9 @@ var configs = {
|
|
191
300
|
rules: {
|
192
301
|
"@valbuild/no-illegal-module-paths": "error",
|
193
302
|
"@valbuild/no-illegal-imports": "error",
|
194
|
-
"@valbuild/export-content-must-be-valid": "error"
|
303
|
+
"@valbuild/export-content-must-be-valid": "error",
|
304
|
+
"@valbuild/no-define-with-variable": "error",
|
305
|
+
"@valbuild/default-export-val-module": "error"
|
195
306
|
}
|
196
307
|
}
|
197
308
|
};
|
@@ -159,13 +159,122 @@ var exportContentMustBeValid = {
|
|
159
159
|
|
160
160
|
// @ts-check
|
161
161
|
|
162
|
+
/**
|
163
|
+
* @type {import('eslint').Rule.RuleModule}
|
164
|
+
*/
|
165
|
+
var noDefineWithVariable = {
|
166
|
+
meta: {
|
167
|
+
type: "problem",
|
168
|
+
docs: {
|
169
|
+
description: "Cannot c.define with a variable",
|
170
|
+
recommended: true
|
171
|
+
},
|
172
|
+
fixable: "code",
|
173
|
+
schema: []
|
174
|
+
},
|
175
|
+
create: function create(context) {
|
176
|
+
return {
|
177
|
+
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
178
|
+
var decl = node.declaration;
|
179
|
+
if (decl.type === "CallExpression") {
|
180
|
+
var callee = decl.callee;
|
181
|
+
var isDefine = callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "c" && callee.property.type === "Identifier" && callee.property.name === "define";
|
182
|
+
if (isDefine) {
|
183
|
+
var args = decl.arguments;
|
184
|
+
var valueArg = args[2];
|
185
|
+
if (valueArg.type === "Identifier") {
|
186
|
+
context.report({
|
187
|
+
node: valueArg,
|
188
|
+
message: "Val: third argument of c.define cannot be a variable"
|
189
|
+
});
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
};
|
195
|
+
}
|
196
|
+
};
|
197
|
+
|
198
|
+
// @ts-check
|
199
|
+
|
200
|
+
var message = "Val: c.define must be exported as default";
|
201
|
+
/**
|
202
|
+
* @type {import('eslint').Rule.RuleModule}
|
203
|
+
*/
|
204
|
+
var defaultExportValModule = {
|
205
|
+
meta: {
|
206
|
+
type: "problem",
|
207
|
+
docs: {
|
208
|
+
description: "c.define must be exported as default",
|
209
|
+
recommended: true
|
210
|
+
},
|
211
|
+
fixable: "code",
|
212
|
+
schema: []
|
213
|
+
},
|
214
|
+
create: function create(context) {
|
215
|
+
return {
|
216
|
+
CallExpression: function CallExpression(node) {
|
217
|
+
if (node.callee.type === "MemberExpression") {
|
218
|
+
var memberExpression = node.callee;
|
219
|
+
if (memberExpression.object.type === "Identifier") {
|
220
|
+
var object = memberExpression.object;
|
221
|
+
if (object.name === "c" && memberExpression.property.type === "Identifier") {
|
222
|
+
var property = memberExpression.property;
|
223
|
+
if (property.name === "define") {
|
224
|
+
var parent = node.parent;
|
225
|
+
if (parent.type === "ExportDefaultDeclaration") {
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
if (parent.type === "VariableDeclarator") {
|
229
|
+
var variableInit = parent.init;
|
230
|
+
if (variableInit && parent.parent.type === "VariableDeclaration") {
|
231
|
+
context.report({
|
232
|
+
node: node,
|
233
|
+
message: message,
|
234
|
+
fix: function fix(fixer) {
|
235
|
+
return fixer.replaceText(parent.parent, "export default ".concat(context.sourceCode.getText(variableInit)));
|
236
|
+
}
|
237
|
+
});
|
238
|
+
} else {
|
239
|
+
context.report({
|
240
|
+
node: node,
|
241
|
+
message: message
|
242
|
+
});
|
243
|
+
}
|
244
|
+
} else if (parent.type === "ExpressionStatement" && parent.parent.type === "Program") {
|
245
|
+
context.report({
|
246
|
+
node: node,
|
247
|
+
message: message,
|
248
|
+
fix: function fix(fixer) {
|
249
|
+
return fixer.replaceText(parent, "export default ".concat(context.sourceCode.getText(parent)));
|
250
|
+
}
|
251
|
+
});
|
252
|
+
} else {
|
253
|
+
context.report({
|
254
|
+
node: node,
|
255
|
+
message: message
|
256
|
+
});
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
};
|
264
|
+
}
|
265
|
+
};
|
266
|
+
|
267
|
+
// @ts-check
|
268
|
+
|
162
269
|
/**
|
163
270
|
* @type {Plugin["rules"]}
|
164
271
|
*/
|
165
272
|
var rules = {
|
166
273
|
"no-illegal-module-paths": noIllegalModulePaths,
|
167
274
|
"no-illegal-imports": noIllegalImports,
|
168
|
-
"export-content-must-be-valid": exportContentMustBeValid
|
275
|
+
"export-content-must-be-valid": exportContentMustBeValid,
|
276
|
+
"no-define-with-variable": noDefineWithVariable,
|
277
|
+
"default-export-val-module": defaultExportValModule
|
169
278
|
};
|
170
279
|
|
171
280
|
/**
|
@@ -182,7 +291,9 @@ var configs = {
|
|
182
291
|
rules: {
|
183
292
|
"@valbuild/no-illegal-module-paths": "error",
|
184
293
|
"@valbuild/no-illegal-imports": "error",
|
185
|
-
"@valbuild/export-content-must-be-valid": "error"
|
294
|
+
"@valbuild/export-content-must-be-valid": "error",
|
295
|
+
"@valbuild/no-define-with-variable": "error",
|
296
|
+
"@valbuild/default-export-val-module": "error"
|
186
297
|
}
|
187
298
|
}
|
188
299
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/eslint-plugin",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.65.0",
|
4
4
|
"description": "ESLint rules for val",
|
5
5
|
"keywords": [
|
6
6
|
"eslint",
|
@@ -33,6 +33,7 @@
|
|
33
33
|
"minimatch": "^3.0.4"
|
34
34
|
},
|
35
35
|
"scripts": {
|
36
|
+
"test": "jest",
|
36
37
|
"typecheck": "tsc -p jsconfig.json"
|
37
38
|
}
|
38
39
|
}
|
package/src/index.js
CHANGED
@@ -9,14 +9,18 @@
|
|
9
9
|
import noIllegalModulePaths from "./rules/noIllegalModulePaths";
|
10
10
|
import noIllegalImports from "./rules/noIllegalImports";
|
11
11
|
import exportContentMustBeValid from "./rules/exportContentMustBeValid";
|
12
|
+
import noDefineWithVariable from "./rules/noDefineWithVariable";
|
13
|
+
import defaultExportValModule from "./rules/defaultExportValModule";
|
12
14
|
|
13
15
|
/**
|
14
16
|
* @type {Plugin["rules"]}
|
15
17
|
*/
|
16
|
-
export
|
18
|
+
export const rules = {
|
17
19
|
"no-illegal-module-paths": noIllegalModulePaths,
|
18
20
|
"no-illegal-imports": noIllegalImports,
|
19
21
|
"export-content-must-be-valid": exportContentMustBeValid,
|
22
|
+
"no-define-with-variable": noDefineWithVariable,
|
23
|
+
"default-export-val-module": defaultExportValModule,
|
20
24
|
};
|
21
25
|
|
22
26
|
/**
|
@@ -34,6 +38,8 @@ export const configs = {
|
|
34
38
|
"@valbuild/no-illegal-module-paths": "error",
|
35
39
|
"@valbuild/no-illegal-imports": "error",
|
36
40
|
"@valbuild/export-content-must-be-valid": "error",
|
41
|
+
"@valbuild/no-define-with-variable": "error",
|
42
|
+
"@valbuild/default-export-val-module": "error",
|
37
43
|
},
|
38
44
|
},
|
39
45
|
};
|
@@ -0,0 +1,85 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
const message = "Val: c.define must be exported as default";
|
4
|
+
/**
|
5
|
+
* @type {import('eslint').Rule.RuleModule}
|
6
|
+
*/
|
7
|
+
export default {
|
8
|
+
meta: {
|
9
|
+
type: "problem",
|
10
|
+
docs: {
|
11
|
+
description: "c.define must be exported as default",
|
12
|
+
recommended: true,
|
13
|
+
},
|
14
|
+
fixable: "code",
|
15
|
+
schema: [],
|
16
|
+
},
|
17
|
+
create: function (context) {
|
18
|
+
return {
|
19
|
+
CallExpression(node) {
|
20
|
+
if (node.callee.type === "MemberExpression") {
|
21
|
+
const memberExpression = node.callee;
|
22
|
+
if (memberExpression.object.type === "Identifier") {
|
23
|
+
const object = memberExpression.object;
|
24
|
+
if (
|
25
|
+
object.name === "c" &&
|
26
|
+
memberExpression.property.type === "Identifier"
|
27
|
+
) {
|
28
|
+
const property = memberExpression.property;
|
29
|
+
if (property.name === "define") {
|
30
|
+
const parent = node.parent;
|
31
|
+
if (parent.type === "ExportDefaultDeclaration") {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
if (parent.type === "VariableDeclarator") {
|
35
|
+
const variableInit = parent.init;
|
36
|
+
if (
|
37
|
+
variableInit &&
|
38
|
+
parent.parent.type === "VariableDeclaration"
|
39
|
+
) {
|
40
|
+
context.report({
|
41
|
+
node: node,
|
42
|
+
message,
|
43
|
+
fix: function (fixer) {
|
44
|
+
return fixer.replaceText(
|
45
|
+
parent.parent,
|
46
|
+
`export default ${context.sourceCode.getText(
|
47
|
+
variableInit,
|
48
|
+
)}`,
|
49
|
+
);
|
50
|
+
},
|
51
|
+
});
|
52
|
+
} else {
|
53
|
+
context.report({
|
54
|
+
node: node,
|
55
|
+
message,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
} else if (
|
59
|
+
parent.type === "ExpressionStatement" &&
|
60
|
+
parent.parent.type === "Program"
|
61
|
+
) {
|
62
|
+
context.report({
|
63
|
+
node: node,
|
64
|
+
message,
|
65
|
+
fix: function (fixer) {
|
66
|
+
return fixer.replaceText(
|
67
|
+
parent,
|
68
|
+
`export default ${context.sourceCode.getText(parent)}`,
|
69
|
+
);
|
70
|
+
},
|
71
|
+
});
|
72
|
+
} else {
|
73
|
+
context.report({
|
74
|
+
node: node,
|
75
|
+
message,
|
76
|
+
});
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
},
|
83
|
+
};
|
84
|
+
},
|
85
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @type {import('eslint').Rule.RuleModule}
|
5
|
+
*/
|
6
|
+
export default {
|
7
|
+
meta: {
|
8
|
+
type: "problem",
|
9
|
+
docs: {
|
10
|
+
description: "Cannot c.define with a variable",
|
11
|
+
recommended: true,
|
12
|
+
},
|
13
|
+
fixable: "code",
|
14
|
+
schema: [],
|
15
|
+
},
|
16
|
+
create: function (context) {
|
17
|
+
return {
|
18
|
+
ExportDefaultDeclaration(node) {
|
19
|
+
const decl = node.declaration;
|
20
|
+
if (decl.type === "CallExpression") {
|
21
|
+
const callee = decl.callee;
|
22
|
+
const isDefine =
|
23
|
+
callee.type === "MemberExpression" &&
|
24
|
+
callee.object.type === "Identifier" &&
|
25
|
+
callee.object.name === "c" &&
|
26
|
+
callee.property.type === "Identifier" &&
|
27
|
+
callee.property.name === "define";
|
28
|
+
|
29
|
+
if (isDefine) {
|
30
|
+
const args = decl.arguments;
|
31
|
+
const valueArg = args[2];
|
32
|
+
if (valueArg.type === "Identifier") {
|
33
|
+
context.report({
|
34
|
+
node: valueArg,
|
35
|
+
message: "Val: third argument of c.define cannot be a variable",
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
},
|
41
|
+
};
|
42
|
+
},
|
43
|
+
};
|
@@ -35,7 +35,7 @@ export default {
|
|
35
35
|
"importKind" in node &&
|
36
36
|
node["importKind"] !== "type" &&
|
37
37
|
!node.specifiers.every(
|
38
|
-
(s) => "importKind" in s && s["importKind"] === "type"
|
38
|
+
(s) => "importKind" in s && s["importKind"] === "type",
|
39
39
|
)
|
40
40
|
) {
|
41
41
|
const message = `Val: can only 'import type' or import from source that is either: a .val.{j,t}s file, a @valbuild package, or val.config.{j,t}s.`;
|
@@ -35,7 +35,7 @@ export default {
|
|
35
35
|
n.source.value.endsWith("val.config.ts") ||
|
36
36
|
n.source.value.endsWith("val.config.js"))
|
37
37
|
? n.source.value
|
38
|
-
: false
|
38
|
+
: false,
|
39
39
|
);
|
40
40
|
if (
|
41
41
|
maybeValConfigImportDeclaration?.type === "ImportDeclaration" &&
|
@@ -99,7 +99,7 @@ export default {
|
|
99
99
|
fix: (fixer) =>
|
100
100
|
fixer.replaceText(
|
101
101
|
firstArg,
|
102
|
-
`${rawArg}${expectedValue}${rawArg}
|
102
|
+
`${rawArg}${expectedValue}${rawArg}`,
|
103
103
|
),
|
104
104
|
});
|
105
105
|
}
|
package/test/plugin.test.js
CHANGED
@@ -13,7 +13,7 @@ function initESLint(fixtureConfigName) {
|
|
13
13
|
overrideConfigFile: path.resolve(
|
14
14
|
__dirname,
|
15
15
|
"../fixtures/",
|
16
|
-
fixtureConfigName
|
16
|
+
fixtureConfigName,
|
17
17
|
),
|
18
18
|
});
|
19
19
|
}
|
@@ -64,7 +64,7 @@ export default c.define(
|
|
64
64
|
expect(results).toHaveLength(1);
|
65
65
|
expect(results[0].messages).toHaveLength(1);
|
66
66
|
expect(results[0].messages[0].fix?.text).toEqual(
|
67
|
-
'"/content/stuff/with/all/test.val.ts"'
|
67
|
+
'"/content/stuff/with/all/test.val.ts"',
|
68
68
|
);
|
69
69
|
});
|
70
70
|
// TODO: we can't test this anymore because we do not know the root dir - perhaps the
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { RuleTester } from "eslint";
|
2
|
+
import { rules as valRules } from "@valbuild/eslint-plugin";
|
3
|
+
import path from "path";
|
4
|
+
|
5
|
+
const rule = valRules["default-export-val-module"];
|
6
|
+
|
7
|
+
RuleTester.setDefaultConfig({
|
8
|
+
parserOptions: {
|
9
|
+
ecmaVersion: 2018,
|
10
|
+
sourceType: "module",
|
11
|
+
ecmaFeatures: {
|
12
|
+
jsx: true,
|
13
|
+
},
|
14
|
+
},
|
15
|
+
});
|
16
|
+
|
17
|
+
const ruleTester = new RuleTester();
|
18
|
+
|
19
|
+
ruleTester.run("default-export-val-module", rule, {
|
20
|
+
valid: [
|
21
|
+
{
|
22
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
23
|
+
code: `import { c, s } from '../val.config.ts';
|
24
|
+
export const schema = s.string();
|
25
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
26
|
+
},
|
27
|
+
],
|
28
|
+
invalid: [
|
29
|
+
{
|
30
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
31
|
+
code: `import { c, s } from '../val.config.ts';
|
32
|
+
export const schema = s.string();
|
33
|
+
const a = c.define('/foo/test.val.ts', schema, 'String')`,
|
34
|
+
errors: [
|
35
|
+
{
|
36
|
+
message: "Val: c.define must be exported as default",
|
37
|
+
},
|
38
|
+
],
|
39
|
+
output: `import { c, s } from '../val.config.ts';
|
40
|
+
export const schema = s.string();
|
41
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
45
|
+
code: `import { c, s } from '../val.config.ts';
|
46
|
+
export const schema = s.string();
|
47
|
+
{
|
48
|
+
c.define('/foo/test.val.ts', schema, 'String')
|
49
|
+
}`,
|
50
|
+
errors: [
|
51
|
+
{
|
52
|
+
message: "Val: c.define must be exported as default",
|
53
|
+
},
|
54
|
+
],
|
55
|
+
output: `import { c, s } from '../val.config.ts';
|
56
|
+
export const schema = s.string();
|
57
|
+
{
|
58
|
+
c.define('/foo/test.val.ts', schema, 'String')
|
59
|
+
}`,
|
60
|
+
},
|
61
|
+
{
|
62
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
63
|
+
code: `import { c, s } from '../val.config.ts';
|
64
|
+
export const schema = s.string();
|
65
|
+
c.define('/foo/test.val.ts', schema, 'String')`,
|
66
|
+
errors: [
|
67
|
+
{
|
68
|
+
message: "Val: c.define must be exported as default",
|
69
|
+
},
|
70
|
+
],
|
71
|
+
output: `import { c, s } from '../val.config.ts';
|
72
|
+
export const schema = s.string();
|
73
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
74
|
+
},
|
75
|
+
],
|
76
|
+
});
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { RuleTester } from "eslint";
|
2
|
+
import { rules as valRules } from "@valbuild/eslint-plugin";
|
3
|
+
import path from "path";
|
4
|
+
|
5
|
+
const rule = valRules["no-define-with-variable"];
|
6
|
+
|
7
|
+
RuleTester.setDefaultConfig({
|
8
|
+
parserOptions: {
|
9
|
+
ecmaVersion: 2018,
|
10
|
+
sourceType: "module",
|
11
|
+
ecmaFeatures: {
|
12
|
+
jsx: true,
|
13
|
+
},
|
14
|
+
},
|
15
|
+
});
|
16
|
+
|
17
|
+
const ruleTester = new RuleTester();
|
18
|
+
|
19
|
+
ruleTester.run("no-define-with-variable", rule, {
|
20
|
+
valid: [
|
21
|
+
{
|
22
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
23
|
+
code: `import { c, s } from '../val.config.ts';
|
24
|
+
export const schema = s.string();
|
25
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
26
|
+
},
|
27
|
+
],
|
28
|
+
invalid: [
|
29
|
+
{
|
30
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
31
|
+
code: `import { c, s } from '../val.config.ts';
|
32
|
+
export const schema = s.string();
|
33
|
+
const str = 'String'
|
34
|
+
export default c.define('/foo/test.val.ts', schema, str)`,
|
35
|
+
errors: [
|
36
|
+
{
|
37
|
+
message: "Val: third argument of c.define cannot be a variable",
|
38
|
+
},
|
39
|
+
],
|
40
|
+
},
|
41
|
+
],
|
42
|
+
});
|