@valbuild/eslint-plugin 0.45.0 → 0.47.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 +39 -35
- package/dist/valbuild-eslint-plugin.cjs.prod.js +39 -35
- package/dist/valbuild-eslint-plugin.esm.js +39 -35
- package/package.json +1 -1
- package/src/index.js +3 -24
- package/src/rules/noIllegalImports.js +42 -0
- package/src/rules/noIllegalModuleIds.js +1 -1
- package/test/rules/noIllegalImports.test.js +65 -0
- package/test/rules/noIllegalModuleIds.test.js +2 -2
@@ -106,7 +106,7 @@ var noIllegalModuleIds = {
|
|
106
106
|
if (rawArg) {
|
107
107
|
context.report({
|
108
108
|
node: firstArg,
|
109
|
-
message: "Val: val.content
|
109
|
+
message: "Val: val.content id should match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
110
110
|
fix: function fix(fixer) {
|
111
111
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
112
112
|
}
|
@@ -122,49 +122,53 @@ var noIllegalModuleIds = {
|
|
122
122
|
|
123
123
|
// @ts-check
|
124
124
|
|
125
|
+
/**
|
126
|
+
* @type {import('eslint').Rule.RuleModule}
|
127
|
+
*/
|
128
|
+
var noIllegalImports = {
|
129
|
+
meta: {
|
130
|
+
type: "problem",
|
131
|
+
docs: {
|
132
|
+
description: "Check that val files only has valid imports.",
|
133
|
+
category: "Best Practices",
|
134
|
+
recommended: true
|
135
|
+
},
|
136
|
+
fixable: "code",
|
137
|
+
schema: []
|
138
|
+
},
|
139
|
+
create: function create(context) {
|
140
|
+
return {
|
141
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
142
|
+
var importSource = node.source.value;
|
143
|
+
var filename = context.filename || context.getFilename();
|
144
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
145
|
+
// only allow: .val files, @valbuild packages, and val config
|
146
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
147
|
+
var message = "Val: import source should be a .val.ts file, a @valbuild package, or val.config.ts. Found: '".concat(importSource, "'");
|
148
|
+
context.report({
|
149
|
+
node: node.source,
|
150
|
+
message: message
|
151
|
+
});
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
155
|
+
}
|
156
|
+
};
|
157
|
+
|
158
|
+
// @ts-check
|
159
|
+
|
125
160
|
/**
|
126
161
|
* @type {Plugin["rules"]}
|
127
162
|
*/
|
128
163
|
var rules = {
|
129
|
-
"no-illegal-module-ids": noIllegalModuleIds
|
164
|
+
"no-illegal-module-ids": noIllegalModuleIds,
|
165
|
+
"no-illegal-imports": noIllegalImports
|
130
166
|
};
|
131
167
|
|
132
168
|
/**
|
133
169
|
* @type {Plugin["processors"]}
|
134
170
|
*/
|
135
|
-
var processors = {
|
136
|
-
val: {
|
137
|
-
/**
|
138
|
-
* @param {string} text
|
139
|
-
* @param {string} filename
|
140
|
-
* @returns {{ filename: string, text: string }[]}
|
141
|
-
*/
|
142
|
-
preprocess: function preprocess(text, filename) {
|
143
|
-
console.log("preprocess", {
|
144
|
-
text: text,
|
145
|
-
filename: filename
|
146
|
-
});
|
147
|
-
return [{
|
148
|
-
text: text,
|
149
|
-
filename: filename
|
150
|
-
}];
|
151
|
-
},
|
152
|
-
/**
|
153
|
-
* Transforms generated messages for output.
|
154
|
-
* @param {LintMessage[][]} messages An array containing one array of messages
|
155
|
-
* for each code block returned from `preprocess`.
|
156
|
-
* @param {string} filename The filename of the file
|
157
|
-
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
|
158
|
-
*/
|
159
|
-
postprocess: function postprocess(messages, filename) {
|
160
|
-
console.log({
|
161
|
-
messages: messages,
|
162
|
-
filename: filename
|
163
|
-
});
|
164
|
-
return messages.flat();
|
165
|
-
}
|
166
|
-
}
|
167
|
-
};
|
171
|
+
var processors = {};
|
168
172
|
|
169
173
|
/**
|
170
174
|
* @type {Plugin}
|
@@ -106,7 +106,7 @@ var noIllegalModuleIds = {
|
|
106
106
|
if (rawArg) {
|
107
107
|
context.report({
|
108
108
|
node: firstArg,
|
109
|
-
message: "Val: val.content
|
109
|
+
message: "Val: val.content id should match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
110
110
|
fix: function fix(fixer) {
|
111
111
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
112
112
|
}
|
@@ -122,49 +122,53 @@ var noIllegalModuleIds = {
|
|
122
122
|
|
123
123
|
// @ts-check
|
124
124
|
|
125
|
+
/**
|
126
|
+
* @type {import('eslint').Rule.RuleModule}
|
127
|
+
*/
|
128
|
+
var noIllegalImports = {
|
129
|
+
meta: {
|
130
|
+
type: "problem",
|
131
|
+
docs: {
|
132
|
+
description: "Check that val files only has valid imports.",
|
133
|
+
category: "Best Practices",
|
134
|
+
recommended: true
|
135
|
+
},
|
136
|
+
fixable: "code",
|
137
|
+
schema: []
|
138
|
+
},
|
139
|
+
create: function create(context) {
|
140
|
+
return {
|
141
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
142
|
+
var importSource = node.source.value;
|
143
|
+
var filename = context.filename || context.getFilename();
|
144
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
145
|
+
// only allow: .val files, @valbuild packages, and val config
|
146
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
147
|
+
var message = "Val: import source should be a .val.ts file, a @valbuild package, or val.config.ts. Found: '".concat(importSource, "'");
|
148
|
+
context.report({
|
149
|
+
node: node.source,
|
150
|
+
message: message
|
151
|
+
});
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
155
|
+
}
|
156
|
+
};
|
157
|
+
|
158
|
+
// @ts-check
|
159
|
+
|
125
160
|
/**
|
126
161
|
* @type {Plugin["rules"]}
|
127
162
|
*/
|
128
163
|
var rules = {
|
129
|
-
"no-illegal-module-ids": noIllegalModuleIds
|
164
|
+
"no-illegal-module-ids": noIllegalModuleIds,
|
165
|
+
"no-illegal-imports": noIllegalImports
|
130
166
|
};
|
131
167
|
|
132
168
|
/**
|
133
169
|
* @type {Plugin["processors"]}
|
134
170
|
*/
|
135
|
-
var processors = {
|
136
|
-
val: {
|
137
|
-
/**
|
138
|
-
* @param {string} text
|
139
|
-
* @param {string} filename
|
140
|
-
* @returns {{ filename: string, text: string }[]}
|
141
|
-
*/
|
142
|
-
preprocess: function preprocess(text, filename) {
|
143
|
-
console.log("preprocess", {
|
144
|
-
text: text,
|
145
|
-
filename: filename
|
146
|
-
});
|
147
|
-
return [{
|
148
|
-
text: text,
|
149
|
-
filename: filename
|
150
|
-
}];
|
151
|
-
},
|
152
|
-
/**
|
153
|
-
* Transforms generated messages for output.
|
154
|
-
* @param {LintMessage[][]} messages An array containing one array of messages
|
155
|
-
* for each code block returned from `preprocess`.
|
156
|
-
* @param {string} filename The filename of the file
|
157
|
-
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
|
158
|
-
*/
|
159
|
-
postprocess: function postprocess(messages, filename) {
|
160
|
-
console.log({
|
161
|
-
messages: messages,
|
162
|
-
filename: filename
|
163
|
-
});
|
164
|
-
return messages.flat();
|
165
|
-
}
|
166
|
-
}
|
167
|
-
};
|
171
|
+
var processors = {};
|
168
172
|
|
169
173
|
/**
|
170
174
|
* @type {Plugin}
|
@@ -98,7 +98,7 @@ var noIllegalModuleIds = {
|
|
98
98
|
if (rawArg) {
|
99
99
|
context.report({
|
100
100
|
node: firstArg,
|
101
|
-
message: "Val: val.content
|
101
|
+
message: "Val: val.content id should match the filename. Expected: '".concat(expectedValue, "'. Found: '").concat(firstArg.value, "'"),
|
102
102
|
fix: function fix(fixer) {
|
103
103
|
return fixer.replaceText(firstArg, "".concat(rawArg).concat(expectedValue).concat(rawArg));
|
104
104
|
}
|
@@ -114,49 +114,53 @@ var noIllegalModuleIds = {
|
|
114
114
|
|
115
115
|
// @ts-check
|
116
116
|
|
117
|
+
/**
|
118
|
+
* @type {import('eslint').Rule.RuleModule}
|
119
|
+
*/
|
120
|
+
var noIllegalImports = {
|
121
|
+
meta: {
|
122
|
+
type: "problem",
|
123
|
+
docs: {
|
124
|
+
description: "Check that val files only has valid imports.",
|
125
|
+
category: "Best Practices",
|
126
|
+
recommended: true
|
127
|
+
},
|
128
|
+
fixable: "code",
|
129
|
+
schema: []
|
130
|
+
},
|
131
|
+
create: function create(context) {
|
132
|
+
return {
|
133
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
134
|
+
var importSource = node.source.value;
|
135
|
+
var filename = context.filename || context.getFilename();
|
136
|
+
var isValFile = filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
137
|
+
// only allow: .val files, @valbuild packages, and val config
|
138
|
+
if (isValFile && typeof importSource === "string" && !importSource.match(/\.val(\.ts|\.js|)$/) && !importSource.match(/^@valbuild/) && !importSource.match(/val\.config(\.ts|\.js|)$/)) {
|
139
|
+
var message = "Val: import source should be a .val.ts file, a @valbuild package, or val.config.ts. Found: '".concat(importSource, "'");
|
140
|
+
context.report({
|
141
|
+
node: node.source,
|
142
|
+
message: message
|
143
|
+
});
|
144
|
+
}
|
145
|
+
}
|
146
|
+
};
|
147
|
+
}
|
148
|
+
};
|
149
|
+
|
150
|
+
// @ts-check
|
151
|
+
|
117
152
|
/**
|
118
153
|
* @type {Plugin["rules"]}
|
119
154
|
*/
|
120
155
|
var rules = {
|
121
|
-
"no-illegal-module-ids": noIllegalModuleIds
|
156
|
+
"no-illegal-module-ids": noIllegalModuleIds,
|
157
|
+
"no-illegal-imports": noIllegalImports
|
122
158
|
};
|
123
159
|
|
124
160
|
/**
|
125
161
|
* @type {Plugin["processors"]}
|
126
162
|
*/
|
127
|
-
var processors = {
|
128
|
-
val: {
|
129
|
-
/**
|
130
|
-
* @param {string} text
|
131
|
-
* @param {string} filename
|
132
|
-
* @returns {{ filename: string, text: string }[]}
|
133
|
-
*/
|
134
|
-
preprocess: function preprocess(text, filename) {
|
135
|
-
console.log("preprocess", {
|
136
|
-
text: text,
|
137
|
-
filename: filename
|
138
|
-
});
|
139
|
-
return [{
|
140
|
-
text: text,
|
141
|
-
filename: filename
|
142
|
-
}];
|
143
|
-
},
|
144
|
-
/**
|
145
|
-
* Transforms generated messages for output.
|
146
|
-
* @param {LintMessage[][]} messages An array containing one array of messages
|
147
|
-
* for each code block returned from `preprocess`.
|
148
|
-
* @param {string} filename The filename of the file
|
149
|
-
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
|
150
|
-
*/
|
151
|
-
postprocess: function postprocess(messages, filename) {
|
152
|
-
console.log({
|
153
|
-
messages: messages,
|
154
|
-
filename: filename
|
155
|
-
});
|
156
|
-
return messages.flat();
|
157
|
-
}
|
158
|
-
}
|
159
|
-
};
|
163
|
+
var processors = {};
|
160
164
|
|
161
165
|
/**
|
162
166
|
* @type {Plugin}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -7,41 +7,20 @@
|
|
7
7
|
*/
|
8
8
|
|
9
9
|
import noIllegalModuleIds from "./rules/noIllegalModuleIds";
|
10
|
+
import noIllegalImports from "./rules/noIllegalImports";
|
10
11
|
|
11
12
|
/**
|
12
13
|
* @type {Plugin["rules"]}
|
13
14
|
*/
|
14
15
|
export let rules = {
|
15
16
|
"no-illegal-module-ids": noIllegalModuleIds,
|
17
|
+
"no-illegal-imports": noIllegalImports,
|
16
18
|
};
|
17
19
|
|
18
20
|
/**
|
19
21
|
* @type {Plugin["processors"]}
|
20
22
|
*/
|
21
|
-
export const processors = {
|
22
|
-
val: {
|
23
|
-
/**
|
24
|
-
* @param {string} text
|
25
|
-
* @param {string} filename
|
26
|
-
* @returns {{ filename: string, text: string }[]}
|
27
|
-
*/
|
28
|
-
preprocess: (text, filename) => {
|
29
|
-
console.log("preprocess", { text, filename });
|
30
|
-
return [{ text, filename }];
|
31
|
-
},
|
32
|
-
/**
|
33
|
-
* Transforms generated messages for output.
|
34
|
-
* @param {LintMessage[][]} messages An array containing one array of messages
|
35
|
-
* for each code block returned from `preprocess`.
|
36
|
-
* @param {string} filename The filename of the file
|
37
|
-
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
|
38
|
-
*/
|
39
|
-
postprocess: (messages, filename) => {
|
40
|
-
console.log({ messages, filename });
|
41
|
-
return messages.flat();
|
42
|
-
},
|
43
|
-
},
|
44
|
-
};
|
23
|
+
export const processors = {};
|
45
24
|
|
46
25
|
/**
|
47
26
|
* @type {Plugin}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @type {import('eslint').Rule.RuleModule}
|
5
|
+
*/
|
6
|
+
export default {
|
7
|
+
meta: {
|
8
|
+
type: "problem",
|
9
|
+
docs: {
|
10
|
+
description: "Check that val files only has valid imports.",
|
11
|
+
category: "Best Practices",
|
12
|
+
recommended: true,
|
13
|
+
},
|
14
|
+
fixable: "code",
|
15
|
+
schema: [],
|
16
|
+
},
|
17
|
+
create: function (context) {
|
18
|
+
return {
|
19
|
+
ImportDeclaration(node) {
|
20
|
+
const importSource = node.source.value;
|
21
|
+
const filename = context.filename || context.getFilename();
|
22
|
+
|
23
|
+
const isValFile =
|
24
|
+
filename.endsWith(".val.ts") || filename.endsWith(".val.js");
|
25
|
+
// only allow: .val files, @valbuild packages, and val config
|
26
|
+
if (
|
27
|
+
isValFile &&
|
28
|
+
typeof importSource === "string" &&
|
29
|
+
!importSource.match(/\.val(\.ts|\.js|)$/) &&
|
30
|
+
!importSource.match(/^@valbuild/) &&
|
31
|
+
!importSource.match(/val\.config(\.ts|\.js|)$/)
|
32
|
+
) {
|
33
|
+
const message = `Val: import source should be a .val.ts file, a @valbuild package, or val.config.ts. Found: '${importSource}'`;
|
34
|
+
context.report({
|
35
|
+
node: node.source,
|
36
|
+
message,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
},
|
40
|
+
};
|
41
|
+
},
|
42
|
+
};
|
@@ -92,7 +92,7 @@ export default {
|
|
92
92
|
if (rawArg) {
|
93
93
|
context.report({
|
94
94
|
node: firstArg,
|
95
|
-
message: `Val: val.content
|
95
|
+
message: `Val: val.content id should match the filename. Expected: '${expectedValue}'. Found: '${firstArg.value}'`,
|
96
96
|
fix: (fixer) =>
|
97
97
|
fixer.replaceText(
|
98
98
|
firstArg,
|
@@ -0,0 +1,65 @@
|
|
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-illegal-imports"];
|
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-illegal-imports", rule, {
|
20
|
+
valid: [
|
21
|
+
{
|
22
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
23
|
+
code: `
|
24
|
+
import { val, s } from '../val.config';
|
25
|
+
import { eventSchema } from './event.val';
|
26
|
+
|
27
|
+
export const schema = s.array(eventSchema);
|
28
|
+
export default val.content('/foo/test', schema, [])`,
|
29
|
+
},
|
30
|
+
{
|
31
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
32
|
+
code: `
|
33
|
+
import { val, s } from '../val.config.ts';
|
34
|
+
import { eventSchema } from './event.val.ts';
|
35
|
+
|
36
|
+
export const schema = s.array(eventSchema);
|
37
|
+
export default val.content('/foo/test', schema, [])`,
|
38
|
+
},
|
39
|
+
{
|
40
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
41
|
+
code: `
|
42
|
+
import { val, s } from '../val.config.ts';
|
43
|
+
|
44
|
+
export const schema = s.string();
|
45
|
+
export default val.content('/foo/test', schema, 'String')`,
|
46
|
+
},
|
47
|
+
],
|
48
|
+
invalid: [
|
49
|
+
{
|
50
|
+
filename: path.join(process.cwd(), "./foo/test.val.ts"),
|
51
|
+
code: `
|
52
|
+
import { val, s } from '../val.config';
|
53
|
+
import { eventSchema } from './event';
|
54
|
+
|
55
|
+
export const schema = s.array(eventSchema);
|
56
|
+
export default val.content('/foo/test', schema, [])`,
|
57
|
+
errors: [
|
58
|
+
{
|
59
|
+
message:
|
60
|
+
"Val: import source should be a .val.ts file, a @valbuild package, or val.config.ts. Found: './event'",
|
61
|
+
},
|
62
|
+
],
|
63
|
+
},
|
64
|
+
],
|
65
|
+
});
|
@@ -34,7 +34,7 @@ ruleTester.run("no-illegal-module-ids", rule, {
|
|
34
34
|
errors: [
|
35
35
|
{
|
36
36
|
message:
|
37
|
-
"Val: val.content
|
37
|
+
"Val: val.content id should match the filename. Expected: '/foo/test'. Found: 'foo'",
|
38
38
|
},
|
39
39
|
],
|
40
40
|
output: `import { val, s } from '../val.config.ts';
|
@@ -49,7 +49,7 @@ ruleTester.run("no-illegal-module-ids", rule, {
|
|
49
49
|
errors: [
|
50
50
|
{
|
51
51
|
message:
|
52
|
-
"Val: val.content
|
52
|
+
"Val: val.content id should match the filename. Expected: '/foo/test'. Found: 'foo'",
|
53
53
|
},
|
54
54
|
],
|
55
55
|
output: `import { val, s } from "../val.config.ts";
|