@valbuild/eslint-plugin 0.61.0 → 0.62.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 +11 -11
- package/dist/valbuild-eslint-plugin.cjs.prod.js +11 -11
- package/dist/valbuild-eslint-plugin.esm.js +11 -11
- package/fixtures/eslintrc.json +1 -1
- package/package.json +1 -1
- package/src/index.js +3 -3
- package/src/rules/exportContentMustBeValid.js +6 -1
- package/src/rules/noIllegalImports.js +6 -3
- package/src/rules/{noIllegalModuleIds.js → noIllegalModulePaths.js} +7 -6
- package/test/plugin.test.js +5 -5
- package/test/rules/{noIllegalModuleIds.test.js → noIllegalModulePaths.test.js} +12 -12
@@ -20,11 +20,11 @@ var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs o
|
|
20
20
|
/**
|
21
21
|
* @type {import('eslint').Rule.RuleModule}
|
22
22
|
*/
|
23
|
-
var
|
23
|
+
var noIllegalModulePaths = {
|
24
24
|
meta: {
|
25
25
|
type: "problem",
|
26
26
|
docs: {
|
27
|
-
description: "
|
27
|
+
description: "Module path must match filename",
|
28
28
|
recommended: true
|
29
29
|
},
|
30
30
|
fixable: "code",
|
@@ -43,7 +43,7 @@ var noIllegalModuleIds = {
|
|
43
43
|
});
|
44
44
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
45
45
|
var filename = context.filename || context.getFilename();
|
46
|
-
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
46
|
+
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx")) {
|
47
47
|
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)];
|
48
48
|
if (!packageJsonDir) {
|
49
49
|
var runtimeRoot = path__default["default"].resolve(context.cwd || process.cwd());
|
@@ -54,7 +54,7 @@ var noIllegalModuleIds = {
|
|
54
54
|
PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)] = packageJsonDir;
|
55
55
|
}
|
56
56
|
var relativePath = path__default["default"].relative(packageJsonDir, filename);
|
57
|
-
expectedValue = "/".concat(relativePath
|
57
|
+
expectedValue = "/".concat(relativePath);
|
58
58
|
}
|
59
59
|
}
|
60
60
|
} else {
|
@@ -68,7 +68,7 @@ var noIllegalModuleIds = {
|
|
68
68
|
if (firstArg.type === "TemplateLiteral") {
|
69
69
|
context.report({
|
70
70
|
node: firstArg,
|
71
|
-
message: "Val: c.define
|
71
|
+
message: "Val: c.define path should not be a template literal",
|
72
72
|
fix: function fix(fixer) {
|
73
73
|
return fixer.replaceText(firstArg, "\"".concat(expectedValue, "\""));
|
74
74
|
}
|
@@ -81,7 +81,7 @@ var noIllegalModuleIds = {
|
|
81
81
|
if (rawArg) {
|
82
82
|
context.report({
|
83
83
|
node: firstArg,
|
84
|
-
message: "Val: c.define
|
84
|
+
message: "Val: c.define path must match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
85
85
|
fix: function fix(fixer) {
|
86
86
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
87
87
|
}
|
@@ -114,9 +114,9 @@ var noIllegalImports = {
|
|
114
114
|
ImportDeclaration: function ImportDeclaration(node) {
|
115
115
|
var importSource = node.source.value;
|
116
116
|
var filename = context.filename || context.getFilename();
|
117
|
-
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
117
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js") || filename.endsWith(".val.tsx") || filename.endsWith(".val.jsx");
|
118
118
|
// only allow: .val files, @valbuild packages, and val config
|
119
|
-
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
119
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|\.tsx|\.jsx|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|\.tsx|\.jsx|)$/)) {
|
120
120
|
if ("importKind" in node && node["importKind"] !== "type" && !node.specifiers.every(function (s) {
|
121
121
|
return "importKind" in s && s["importKind"] === "type";
|
122
122
|
})) {
|
@@ -154,7 +154,7 @@ var exportContentMustBeValid = {
|
|
154
154
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
155
155
|
if (node.declaration && node.declaration.type === "CallExpression" && node.declaration.callee.type === "MemberExpression" && node.declaration.callee.object.type === "Identifier" && node.declaration.callee.object.name === "c" && node.declaration.callee.property.type === "Identifier" && node.declaration.callee.property.name === "define") {
|
156
156
|
var filename = context.filename || context.getFilename();
|
157
|
-
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js"))) {
|
157
|
+
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx"))) {
|
158
158
|
context.report({
|
159
159
|
node: node.declaration.callee,
|
160
160
|
messageId: "val/export-content-must-be-valid"
|
@@ -172,7 +172,7 @@ var exportContentMustBeValid = {
|
|
172
172
|
* @type {Plugin["rules"]}
|
173
173
|
*/
|
174
174
|
var rules = {
|
175
|
-
"no-illegal-module-
|
175
|
+
"no-illegal-module-paths": noIllegalModulePaths,
|
176
176
|
"no-illegal-imports": noIllegalImports,
|
177
177
|
"export-content-must-be-valid": exportContentMustBeValid
|
178
178
|
};
|
@@ -189,7 +189,7 @@ var configs = {
|
|
189
189
|
recommended: {
|
190
190
|
plugins: ["@valbuild"],
|
191
191
|
rules: {
|
192
|
-
"@valbuild/no-illegal-module-
|
192
|
+
"@valbuild/no-illegal-module-paths": "error",
|
193
193
|
"@valbuild/no-illegal-imports": "error",
|
194
194
|
"@valbuild/export-content-must-be-valid": "error"
|
195
195
|
}
|
@@ -20,11 +20,11 @@ var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs o
|
|
20
20
|
/**
|
21
21
|
* @type {import('eslint').Rule.RuleModule}
|
22
22
|
*/
|
23
|
-
var
|
23
|
+
var noIllegalModulePaths = {
|
24
24
|
meta: {
|
25
25
|
type: "problem",
|
26
26
|
docs: {
|
27
|
-
description: "
|
27
|
+
description: "Module path must match filename",
|
28
28
|
recommended: true
|
29
29
|
},
|
30
30
|
fixable: "code",
|
@@ -43,7 +43,7 @@ var noIllegalModuleIds = {
|
|
43
43
|
});
|
44
44
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
45
45
|
var filename = context.filename || context.getFilename();
|
46
|
-
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
46
|
+
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx")) {
|
47
47
|
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)];
|
48
48
|
if (!packageJsonDir) {
|
49
49
|
var runtimeRoot = path__default["default"].resolve(context.cwd || process.cwd());
|
@@ -54,7 +54,7 @@ var noIllegalModuleIds = {
|
|
54
54
|
PACKAGE_JSON_DIRS_CACHE[path__default["default"].dirname(filename)] = packageJsonDir;
|
55
55
|
}
|
56
56
|
var relativePath = path__default["default"].relative(packageJsonDir, filename);
|
57
|
-
expectedValue = "/".concat(relativePath
|
57
|
+
expectedValue = "/".concat(relativePath);
|
58
58
|
}
|
59
59
|
}
|
60
60
|
} else {
|
@@ -68,7 +68,7 @@ var noIllegalModuleIds = {
|
|
68
68
|
if (firstArg.type === "TemplateLiteral") {
|
69
69
|
context.report({
|
70
70
|
node: firstArg,
|
71
|
-
message: "Val: c.define
|
71
|
+
message: "Val: c.define path should not be a template literal",
|
72
72
|
fix: function fix(fixer) {
|
73
73
|
return fixer.replaceText(firstArg, "\"".concat(expectedValue, "\""));
|
74
74
|
}
|
@@ -81,7 +81,7 @@ var noIllegalModuleIds = {
|
|
81
81
|
if (rawArg) {
|
82
82
|
context.report({
|
83
83
|
node: firstArg,
|
84
|
-
message: "Val: c.define
|
84
|
+
message: "Val: c.define path must match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
85
85
|
fix: function fix(fixer) {
|
86
86
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
87
87
|
}
|
@@ -114,9 +114,9 @@ var noIllegalImports = {
|
|
114
114
|
ImportDeclaration: function ImportDeclaration(node) {
|
115
115
|
var importSource = node.source.value;
|
116
116
|
var filename = context.filename || context.getFilename();
|
117
|
-
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
117
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js") || filename.endsWith(".val.tsx") || filename.endsWith(".val.jsx");
|
118
118
|
// only allow: .val files, @valbuild packages, and val config
|
119
|
-
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
119
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|\.tsx|\.jsx|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|\.tsx|\.jsx|)$/)) {
|
120
120
|
if ("importKind" in node && node["importKind"] !== "type" && !node.specifiers.every(function (s) {
|
121
121
|
return "importKind" in s && s["importKind"] === "type";
|
122
122
|
})) {
|
@@ -154,7 +154,7 @@ var exportContentMustBeValid = {
|
|
154
154
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
155
155
|
if (node.declaration && node.declaration.type === "CallExpression" && node.declaration.callee.type === "MemberExpression" && node.declaration.callee.object.type === "Identifier" && node.declaration.callee.object.name === "c" && node.declaration.callee.property.type === "Identifier" && node.declaration.callee.property.name === "define") {
|
156
156
|
var filename = context.filename || context.getFilename();
|
157
|
-
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js"))) {
|
157
|
+
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx"))) {
|
158
158
|
context.report({
|
159
159
|
node: node.declaration.callee,
|
160
160
|
messageId: "val/export-content-must-be-valid"
|
@@ -172,7 +172,7 @@ var exportContentMustBeValid = {
|
|
172
172
|
* @type {Plugin["rules"]}
|
173
173
|
*/
|
174
174
|
var rules = {
|
175
|
-
"no-illegal-module-
|
175
|
+
"no-illegal-module-paths": noIllegalModulePaths,
|
176
176
|
"no-illegal-imports": noIllegalImports,
|
177
177
|
"export-content-must-be-valid": exportContentMustBeValid
|
178
178
|
};
|
@@ -189,7 +189,7 @@ var configs = {
|
|
189
189
|
recommended: {
|
190
190
|
plugins: ["@valbuild"],
|
191
191
|
rules: {
|
192
|
-
"@valbuild/no-illegal-module-
|
192
|
+
"@valbuild/no-illegal-module-paths": "error",
|
193
193
|
"@valbuild/no-illegal-imports": "error",
|
194
194
|
"@valbuild/export-content-must-be-valid": "error"
|
195
195
|
}
|
@@ -11,11 +11,11 @@ var PACKAGE_JSON_DIRS_CACHE = {}; // we cache to avoid having to do as many fs o
|
|
11
11
|
/**
|
12
12
|
* @type {import('eslint').Rule.RuleModule}
|
13
13
|
*/
|
14
|
-
var
|
14
|
+
var noIllegalModulePaths = {
|
15
15
|
meta: {
|
16
16
|
type: "problem",
|
17
17
|
docs: {
|
18
|
-
description: "
|
18
|
+
description: "Module path must match filename",
|
19
19
|
recommended: true
|
20
20
|
},
|
21
21
|
fixable: "code",
|
@@ -34,7 +34,7 @@ var noIllegalModuleIds = {
|
|
34
34
|
});
|
35
35
|
if ((maybeValConfigImportDeclaration === null || maybeValConfigImportDeclaration === void 0 ? void 0 : maybeValConfigImportDeclaration.type) === "ImportDeclaration" && typeof maybeValConfigImportDeclaration.source.value === "string") {
|
36
36
|
var filename = context.filename || context.getFilename();
|
37
|
-
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js")) {
|
37
|
+
if (filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx")) {
|
38
38
|
var packageJsonDir = PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)];
|
39
39
|
if (!packageJsonDir) {
|
40
40
|
var runtimeRoot = path.resolve(context.cwd || process.cwd());
|
@@ -45,7 +45,7 @@ var noIllegalModuleIds = {
|
|
45
45
|
PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)] = packageJsonDir;
|
46
46
|
}
|
47
47
|
var relativePath = path.relative(packageJsonDir, filename);
|
48
|
-
expectedValue = "/".concat(relativePath
|
48
|
+
expectedValue = "/".concat(relativePath);
|
49
49
|
}
|
50
50
|
}
|
51
51
|
} else {
|
@@ -59,7 +59,7 @@ var noIllegalModuleIds = {
|
|
59
59
|
if (firstArg.type === "TemplateLiteral") {
|
60
60
|
context.report({
|
61
61
|
node: firstArg,
|
62
|
-
message: "Val: c.define
|
62
|
+
message: "Val: c.define path should not be a template literal",
|
63
63
|
fix: function fix(fixer) {
|
64
64
|
return fixer.replaceText(firstArg, "\"".concat(expectedValue, "\""));
|
65
65
|
}
|
@@ -72,7 +72,7 @@ var noIllegalModuleIds = {
|
|
72
72
|
if (rawArg) {
|
73
73
|
context.report({
|
74
74
|
node: firstArg,
|
75
|
-
message: "Val: c.define
|
75
|
+
message: "Val: c.define path must match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
76
76
|
fix: function fix(fixer) {
|
77
77
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
78
78
|
}
|
@@ -105,9 +105,9 @@ var noIllegalImports = {
|
|
105
105
|
ImportDeclaration: function ImportDeclaration(node) {
|
106
106
|
var importSource = node.source.value;
|
107
107
|
var filename = context.filename || context.getFilename();
|
108
|
-
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
108
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js") || filename.endsWith(".val.tsx") || filename.endsWith(".val.jsx");
|
109
109
|
// only allow: .val files, @valbuild packages, and val config
|
110
|
-
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
110
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|\.tsx|\.jsx|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|\.tsx|\.jsx|)$/)) {
|
111
111
|
if ("importKind" in node && node["importKind"] !== "type" && !node.specifiers.every(function (s) {
|
112
112
|
return "importKind" in s && s["importKind"] === "type";
|
113
113
|
})) {
|
@@ -145,7 +145,7 @@ var exportContentMustBeValid = {
|
|
145
145
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
146
146
|
if (node.declaration && node.declaration.type === "CallExpression" && node.declaration.callee.type === "MemberExpression" && node.declaration.callee.object.type === "Identifier" && node.declaration.callee.object.name === "c" && node.declaration.callee.property.type === "Identifier" && node.declaration.callee.property.name === "define") {
|
147
147
|
var filename = context.filename || context.getFilename();
|
148
|
-
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js"))) {
|
148
|
+
if (!(filename !== null && filename !== void 0 && filename.endsWith(".val.ts") || filename !== null && filename !== void 0 && filename.endsWith(".val.js") || filename !== null && filename !== void 0 && filename.endsWith(".val.tsx") || filename !== null && filename !== void 0 && filename.endsWith(".val.jsx"))) {
|
149
149
|
context.report({
|
150
150
|
node: node.declaration.callee,
|
151
151
|
messageId: "val/export-content-must-be-valid"
|
@@ -163,7 +163,7 @@ var exportContentMustBeValid = {
|
|
163
163
|
* @type {Plugin["rules"]}
|
164
164
|
*/
|
165
165
|
var rules = {
|
166
|
-
"no-illegal-module-
|
166
|
+
"no-illegal-module-paths": noIllegalModulePaths,
|
167
167
|
"no-illegal-imports": noIllegalImports,
|
168
168
|
"export-content-must-be-valid": exportContentMustBeValid
|
169
169
|
};
|
@@ -180,7 +180,7 @@ var configs = {
|
|
180
180
|
recommended: {
|
181
181
|
plugins: ["@valbuild"],
|
182
182
|
rules: {
|
183
|
-
"@valbuild/no-illegal-module-
|
183
|
+
"@valbuild/no-illegal-module-paths": "error",
|
184
184
|
"@valbuild/no-illegal-imports": "error",
|
185
185
|
"@valbuild/export-content-must-be-valid": "error"
|
186
186
|
}
|
package/fixtures/eslintrc.json
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
* @typedef {import('eslint').Linter } RuleModule
|
7
7
|
*/
|
8
8
|
|
9
|
-
import
|
9
|
+
import noIllegalModulePaths from "./rules/noIllegalModulePaths";
|
10
10
|
import noIllegalImports from "./rules/noIllegalImports";
|
11
11
|
import exportContentMustBeValid from "./rules/exportContentMustBeValid";
|
12
12
|
|
@@ -14,7 +14,7 @@ import exportContentMustBeValid from "./rules/exportContentMustBeValid";
|
|
14
14
|
* @type {Plugin["rules"]}
|
15
15
|
*/
|
16
16
|
export let rules = {
|
17
|
-
"no-illegal-module-
|
17
|
+
"no-illegal-module-paths": noIllegalModulePaths,
|
18
18
|
"no-illegal-imports": noIllegalImports,
|
19
19
|
"export-content-must-be-valid": exportContentMustBeValid,
|
20
20
|
};
|
@@ -31,7 +31,7 @@ export const configs = {
|
|
31
31
|
recommended: {
|
32
32
|
plugins: ["@valbuild"],
|
33
33
|
rules: {
|
34
|
-
"@valbuild/no-illegal-module-
|
34
|
+
"@valbuild/no-illegal-module-paths": "error",
|
35
35
|
"@valbuild/no-illegal-imports": "error",
|
36
36
|
"@valbuild/export-content-must-be-valid": "error",
|
37
37
|
},
|
@@ -30,7 +30,12 @@ export default {
|
|
30
30
|
) {
|
31
31
|
const filename = context.filename || context.getFilename();
|
32
32
|
if (
|
33
|
-
!(
|
33
|
+
!(
|
34
|
+
filename?.endsWith(".val.ts") ||
|
35
|
+
filename?.endsWith(".val.js") ||
|
36
|
+
filename?.endsWith(".val.tsx") ||
|
37
|
+
filename?.endsWith(".val.jsx")
|
38
|
+
)
|
34
39
|
) {
|
35
40
|
context.report({
|
36
41
|
node: node.declaration.callee,
|
@@ -19,14 +19,17 @@ export default {
|
|
19
19
|
const filename = context.filename || context.getFilename();
|
20
20
|
|
21
21
|
const isValFile =
|
22
|
-
filename.endsWith(".val.ts") ||
|
22
|
+
filename.endsWith(".val.ts") ||
|
23
|
+
filename.endsWith(".val.js") ||
|
24
|
+
filename.endsWith(".val.tsx") ||
|
25
|
+
filename.endsWith(".val.jsx");
|
23
26
|
// only allow: .val files, @valbuild packages, and val config
|
24
27
|
if (
|
25
28
|
isValFile &&
|
26
29
|
typeof importSource === "string" &&
|
27
|
-
!importSource.match(/\.val(\.ts|\.js|)$/) &&
|
30
|
+
!importSource.match(/\.val(\.ts|\.js|\.tsx|\.jsx|)$/) &&
|
28
31
|
!importSource.match(/^@valbuild/) &&
|
29
|
-
!importSource.match(/val\.config(\.ts|\.js|)$/)
|
32
|
+
!importSource.match(/val\.config(\.ts|\.js|\.tsx|\.jsx|)$/)
|
30
33
|
) {
|
31
34
|
if (
|
32
35
|
"importKind" in node &&
|
@@ -14,8 +14,7 @@ export default {
|
|
14
14
|
meta: {
|
15
15
|
type: "problem",
|
16
16
|
docs: {
|
17
|
-
description:
|
18
|
-
"Check that the first argument of export default declaration matches the string from val.config.{j,t}s file.",
|
17
|
+
description: "Module path must match filename",
|
19
18
|
recommended: true,
|
20
19
|
},
|
21
20
|
fixable: "code",
|
@@ -45,7 +44,9 @@ export default {
|
|
45
44
|
const filename = context.filename || context.getFilename();
|
46
45
|
if (
|
47
46
|
filename?.endsWith(".val.ts") ||
|
48
|
-
filename?.endsWith(".val.
|
47
|
+
filename?.endsWith(".val.tsx") ||
|
48
|
+
filename?.endsWith(".val.js") ||
|
49
|
+
filename?.endsWith(".val.jsx")
|
49
50
|
) {
|
50
51
|
let packageJsonDir =
|
51
52
|
PACKAGE_JSON_DIRS_CACHE[path.dirname(filename)];
|
@@ -62,7 +63,7 @@ export default {
|
|
62
63
|
packageJsonDir;
|
63
64
|
}
|
64
65
|
const relativePath = path.relative(packageJsonDir, filename);
|
65
|
-
expectedValue = `/${relativePath
|
66
|
+
expectedValue = `/${relativePath}`;
|
66
67
|
}
|
67
68
|
}
|
68
69
|
} else {
|
@@ -81,7 +82,7 @@ export default {
|
|
81
82
|
if (firstArg.type === "TemplateLiteral") {
|
82
83
|
context.report({
|
83
84
|
node: firstArg,
|
84
|
-
message: "Val: c.define
|
85
|
+
message: "Val: c.define path should not be a template literal",
|
85
86
|
fix: (fixer) => fixer.replaceText(firstArg, `"${expectedValue}"`),
|
86
87
|
});
|
87
88
|
}
|
@@ -94,7 +95,7 @@ export default {
|
|
94
95
|
if (rawArg) {
|
95
96
|
context.report({
|
96
97
|
node: firstArg,
|
97
|
-
message: `Val: c.define
|
98
|
+
message: `Val: c.define path must match the filename. Expected: '${expectedValue}'. Found: '${firstArg.value}'`,
|
98
99
|
fix: (fixer) =>
|
99
100
|
fixer.replaceText(
|
100
101
|
firstArg,
|
package/test/plugin.test.js
CHANGED
@@ -28,13 +28,13 @@ describe("plugin", () => {
|
|
28
28
|
eslint = initESLint("eslintrc.json");
|
29
29
|
});
|
30
30
|
|
31
|
-
test("no illegal
|
31
|
+
test("no illegal paths for monorepos (projects that are not at root)", async () => {
|
32
32
|
const code = `import { s, c } from "../val.config";
|
33
33
|
|
34
34
|
export const schema = s.string();
|
35
35
|
|
36
36
|
export default c.define(
|
37
|
-
"/something",
|
37
|
+
"/something.val.ts",
|
38
38
|
schema,
|
39
39
|
"React Server components also works"
|
40
40
|
);`;
|
@@ -44,10 +44,10 @@ export default c.define(
|
|
44
44
|
|
45
45
|
expect(results).toHaveLength(1);
|
46
46
|
expect(results[0].messages).toHaveLength(1);
|
47
|
-
expect(results[0].messages[0].fix?.text).toEqual('"/app/test"');
|
47
|
+
expect(results[0].messages[0].fix?.text).toEqual('"/app/test.val.ts"');
|
48
48
|
});
|
49
49
|
|
50
|
-
test("no illegal
|
50
|
+
test("no illegal paths for monorepos (projects that are not at root) - nested", async () => {
|
51
51
|
const code = `import { s, c } from "../../../../val.config";
|
52
52
|
|
53
53
|
export const schema = s.string();
|
@@ -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"'
|
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
|
@@ -2,7 +2,7 @@ import { RuleTester } from "eslint";
|
|
2
2
|
import { rules as valRules } from "@valbuild/eslint-plugin";
|
3
3
|
import path from "path";
|
4
4
|
|
5
|
-
const rule = valRules["no-illegal-module-
|
5
|
+
const rule = valRules["no-illegal-module-paths"];
|
6
6
|
|
7
7
|
RuleTester.setDefaultConfig({
|
8
8
|
parserOptions: {
|
@@ -16,13 +16,13 @@ RuleTester.setDefaultConfig({
|
|
16
16
|
|
17
17
|
const ruleTester = new RuleTester();
|
18
18
|
|
19
|
-
ruleTester.run("no-illegal-module-
|
19
|
+
ruleTester.run("no-illegal-module-paths", rule, {
|
20
20
|
valid: [
|
21
21
|
{
|
22
22
|
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
23
23
|
code: `import { c, s } from '../val.config.ts';
|
24
24
|
export const schema = s.string();
|
25
|
-
export default c.define('/foo/test', schema, 'String')`,
|
25
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
26
26
|
},
|
27
27
|
],
|
28
28
|
invalid: [
|
@@ -30,45 +30,45 @@ ruleTester.run("no-illegal-module-ids", rule, {
|
|
30
30
|
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
31
31
|
code: `import { c, s } from '../val.config.ts';
|
32
32
|
export const schema = s.string();
|
33
|
-
export default c.define('foo', schema, 'String')`,
|
33
|
+
export default c.define('foo.val.ts', schema, 'String')`,
|
34
34
|
errors: [
|
35
35
|
{
|
36
36
|
message:
|
37
|
-
"Val: c.define
|
37
|
+
"Val: c.define path must match the filename. Expected: '/foo/test.val.ts'. Found: 'foo.val.ts'",
|
38
38
|
},
|
39
39
|
],
|
40
40
|
output: `import { c, s } from '../val.config.ts';
|
41
41
|
export const schema = s.string();
|
42
|
-
export default c.define('/foo/test', schema, 'String')`,
|
42
|
+
export default c.define('/foo/test.val.ts', schema, 'String')`,
|
43
43
|
},
|
44
44
|
{
|
45
45
|
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
46
46
|
code: `import { c, s } from "../val.config.ts";
|
47
47
|
export const schema = s.string();
|
48
|
-
export default c.define("foo", schema, 'String')`,
|
48
|
+
export default c.define("foo.val.ts", schema, 'String')`,
|
49
49
|
errors: [
|
50
50
|
{
|
51
51
|
message:
|
52
|
-
"Val: c.define
|
52
|
+
"Val: c.define path must match the filename. Expected: '/foo/test.val.ts'. Found: 'foo.val.ts'",
|
53
53
|
},
|
54
54
|
],
|
55
55
|
output: `import { c, s } from "../val.config.ts";
|
56
56
|
export const schema = s.string();
|
57
|
-
export default c.define("/foo/test", schema, 'String')`,
|
57
|
+
export default c.define("/foo/test.val.ts", schema, 'String')`,
|
58
58
|
},
|
59
59
|
{
|
60
60
|
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
61
61
|
code: `import { c, s } from "../val.config.ts";
|
62
62
|
export const schema = s.string();
|
63
|
-
export default c.define(\`foo\`, schema, 'String')`,
|
63
|
+
export default c.define(\`foo.val.ts\`, schema, 'String')`,
|
64
64
|
errors: [
|
65
65
|
{
|
66
|
-
message: "Val: c.define
|
66
|
+
message: "Val: c.define path should not be a template literal",
|
67
67
|
},
|
68
68
|
],
|
69
69
|
output: `import { c, s } from "../val.config.ts";
|
70
70
|
export const schema = s.string();
|
71
|
-
export default c.define("/foo/test", schema, 'String')`,
|
71
|
+
export default c.define("/foo/test.val.ts", schema, 'String')`,
|
72
72
|
},
|
73
73
|
],
|
74
74
|
});
|