@yasainet/eslint 0.0.8 → 0.0.12
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/package.json +1 -1
- package/src/common/constants.mjs +14 -9
- package/src/common/imports.mjs +18 -12
- package/src/common/index.mjs +4 -2
- package/src/common/naming.mjs +40 -10
package/package.json
CHANGED
package/src/common/constants.mjs
CHANGED
|
@@ -20,10 +20,17 @@ function findProjectRoot() {
|
|
|
20
20
|
|
|
21
21
|
const PROJECT_ROOT = findProjectRoot();
|
|
22
22
|
|
|
23
|
-
const EXCLUDE_LIST = ["proxy.ts", "types"];
|
|
23
|
+
const EXCLUDE_LIST = ["proxy.lib.ts", "types"];
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/** @description Extract the base name from a .ts filename by stripping all extensions. */
|
|
26
|
+
function baseName(filename) {
|
|
27
|
+
return filename.replace(/\..*$/, "");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @description Scan lib directory derived from featureRoot and build prefix-to-lib-relative-path mapping */
|
|
31
|
+
export function generatePrefixLibMapping(featureRoot) {
|
|
32
|
+
const libRoot = featureRoot.replace(/features$/, "lib");
|
|
33
|
+
const libDir = path.join(PROJECT_ROOT, libRoot);
|
|
27
34
|
const mapping = {};
|
|
28
35
|
|
|
29
36
|
if (!fs.existsSync(libDir)) {
|
|
@@ -47,21 +54,19 @@ function generatePrefixLibMapping() {
|
|
|
47
54
|
subEntry.name.endsWith(".ts") &&
|
|
48
55
|
!EXCLUDE_LIST.includes(subEntry.name)
|
|
49
56
|
) {
|
|
50
|
-
const prefix = subEntry.name
|
|
51
|
-
mapping[prefix] =
|
|
57
|
+
const prefix = baseName(subEntry.name);
|
|
58
|
+
mapping[prefix] = `${entry.name}/${subEntry.name.replace(".ts", "")}`;
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
55
|
-
const prefix = entry.name
|
|
56
|
-
mapping[prefix] =
|
|
62
|
+
const prefix = baseName(entry.name);
|
|
63
|
+
mapping[prefix] = entry.name.replace(".ts", "");
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
return mapping;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
export const PREFIX_LIB_MAPPING = generatePrefixLibMapping();
|
|
64
|
-
|
|
65
70
|
export const featuresGlob = (featureRoot, subpath) => [
|
|
66
71
|
`${featureRoot}/${subpath}`,
|
|
67
72
|
];
|
package/src/common/imports.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { PREFIX_LIB_MAPPING } from "./constants.mjs";
|
|
2
|
-
|
|
3
1
|
const LAYER_PATTERNS = {
|
|
4
2
|
repositories: [
|
|
5
3
|
{
|
|
@@ -81,22 +79,22 @@ const CARDINALITY_PATTERNS = {
|
|
|
81
79
|
],
|
|
82
80
|
};
|
|
83
81
|
|
|
84
|
-
function prefixLibPatterns(prefix) {
|
|
85
|
-
const prefixes = Object.keys(
|
|
86
|
-
const allowedLib =
|
|
82
|
+
function prefixLibPatterns(prefix, mapping) {
|
|
83
|
+
const prefixes = Object.keys(mapping);
|
|
84
|
+
const allowedLib = mapping[prefix];
|
|
87
85
|
return prefixes
|
|
88
86
|
.filter((p) => p !== prefix)
|
|
89
87
|
.map((p) => ({
|
|
90
|
-
group: [
|
|
91
|
-
message: `${prefix}.repo.ts can only import from
|
|
88
|
+
group: [`**/lib/${mapping[p]}`, `**/lib/${mapping[p]}/*`],
|
|
89
|
+
message: `${prefix}.repo.ts can only import from lib/${allowedLib}. Use the correct repository file for this lib.`,
|
|
92
90
|
}));
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
const LIB_BOUNDARY_PATTERNS = [
|
|
96
94
|
{
|
|
97
|
-
group: ["
|
|
95
|
+
group: ["**/lib/*", "**/lib/**"],
|
|
98
96
|
message:
|
|
99
|
-
"
|
|
97
|
+
"lib/* can only be imported from repositories (lib-boundary violation)",
|
|
100
98
|
},
|
|
101
99
|
];
|
|
102
100
|
|
|
@@ -131,7 +129,7 @@ export const libBoundaryConfigs = [
|
|
|
131
129
|
];
|
|
132
130
|
|
|
133
131
|
/** @description Scope import restriction rules to the given feature root */
|
|
134
|
-
export function createImportsConfigs(featureRoot) {
|
|
132
|
+
export function createImportsConfigs(featureRoot, prefixLibMapping) {
|
|
135
133
|
const configs = [];
|
|
136
134
|
|
|
137
135
|
configs.push(
|
|
@@ -143,8 +141,8 @@ export function createImportsConfigs(featureRoot) {
|
|
|
143
141
|
),
|
|
144
142
|
);
|
|
145
143
|
|
|
146
|
-
for (const prefix of Object.keys(
|
|
147
|
-
const patterns = prefixLibPatterns(prefix);
|
|
144
|
+
for (const prefix of Object.keys(prefixLibMapping)) {
|
|
145
|
+
const patterns = prefixLibPatterns(prefix, prefixLibMapping);
|
|
148
146
|
if (patterns.length === 0) continue;
|
|
149
147
|
configs.push(
|
|
150
148
|
makeConfig(
|
|
@@ -177,6 +175,14 @@ export function createImportsConfigs(featureRoot) {
|
|
|
177
175
|
),
|
|
178
176
|
);
|
|
179
177
|
|
|
178
|
+
configs.push(
|
|
179
|
+
makeConfig(
|
|
180
|
+
"utils",
|
|
181
|
+
[`${featureRoot}/**/utils/*.ts`],
|
|
182
|
+
LIB_BOUNDARY_PATTERNS,
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
|
|
180
186
|
for (const prefix of ["server", "client", "admin"]) {
|
|
181
187
|
configs.push(
|
|
182
188
|
makeConfig(
|
package/src/common/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { generatePrefixLibMapping } from "./constants.mjs";
|
|
1
2
|
import { createImportsConfigs } from "./imports.mjs";
|
|
2
3
|
import { createJsdocConfigs } from "./jsdoc.mjs";
|
|
3
4
|
import { createLayersConfigs } from "./layers.mjs";
|
|
@@ -6,11 +7,12 @@ import { rulesConfigs } from "./rules.mjs";
|
|
|
6
7
|
|
|
7
8
|
/** @description Build common configs scoped to the given feature root */
|
|
8
9
|
export function createCommonConfigs(featureRoot) {
|
|
10
|
+
const prefixLibMapping = generatePrefixLibMapping(featureRoot);
|
|
9
11
|
return [
|
|
10
12
|
...rulesConfigs,
|
|
11
|
-
...createNamingConfigs(featureRoot),
|
|
13
|
+
...createNamingConfigs(featureRoot, prefixLibMapping),
|
|
12
14
|
...createLayersConfigs(featureRoot),
|
|
13
|
-
...createImportsConfigs(featureRoot),
|
|
15
|
+
...createImportsConfigs(featureRoot, prefixLibMapping),
|
|
14
16
|
...createJsdocConfigs(featureRoot),
|
|
15
17
|
];
|
|
16
18
|
}
|
package/src/common/naming.mjs
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { featuresGlob
|
|
1
|
+
import { featuresGlob } from "./constants.mjs";
|
|
2
2
|
import { checkFile } from "./plugins.mjs";
|
|
3
3
|
import { actionHandleServiceRule } from "./local-plugins/action-handle-service.mjs";
|
|
4
4
|
|
|
5
|
-
const prefixPattern = `@(${Object.keys(PREFIX_LIB_MAPPING).join("|")})`;
|
|
6
|
-
|
|
7
5
|
/** @description Scope naming rules to the given feature root */
|
|
8
|
-
export function createNamingConfigs(featureRoot) {
|
|
9
|
-
|
|
6
|
+
export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
7
|
+
const prefixPattern = `@(${Object.keys(prefixLibMapping).join("|")})`;
|
|
8
|
+
const sharedPrefixPattern = `@(shared|${Object.keys(prefixLibMapping).join("|")})`;
|
|
9
|
+
|
|
10
|
+
// DB prefix: value contains "/" = sub-directory origin = DB client
|
|
11
|
+
const dbPrefixKeys = Object.entries(prefixLibMapping)
|
|
12
|
+
.filter(([, value]) => value.includes("/"))
|
|
13
|
+
.map(([key]) => key);
|
|
14
|
+
|
|
15
|
+
const configs = [
|
|
10
16
|
{
|
|
11
17
|
name: "naming/services",
|
|
12
18
|
files: featuresGlob(featureRoot, "**/services/*.ts"),
|
|
@@ -18,17 +24,39 @@ export function createNamingConfigs(featureRoot) {
|
|
|
18
24
|
],
|
|
19
25
|
},
|
|
20
26
|
},
|
|
21
|
-
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// Non-shared features: only DB prefixes allowed for repositories
|
|
30
|
+
if (dbPrefixKeys.length > 0) {
|
|
31
|
+
const dbPrefixPattern = `@(${dbPrefixKeys.join("|")})`;
|
|
32
|
+
configs.push({
|
|
22
33
|
name: "naming/repositories",
|
|
23
34
|
files: featuresGlob(featureRoot, "**/repositories/*.ts"),
|
|
35
|
+
ignores: featuresGlob(featureRoot, "shared/repositories/*.ts"),
|
|
24
36
|
plugins: { "check-file": checkFile },
|
|
25
37
|
rules: {
|
|
26
38
|
"check-file/filename-naming-convention": [
|
|
27
39
|
"error",
|
|
28
|
-
{ "**/*.ts": `${
|
|
40
|
+
{ "**/*.ts": `${dbPrefixPattern}.repo` },
|
|
29
41
|
],
|
|
30
42
|
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Shared feature: any name allowed for repositories
|
|
47
|
+
configs.push({
|
|
48
|
+
name: "naming/repositories-shared",
|
|
49
|
+
files: featuresGlob(featureRoot, "shared/repositories/*.ts"),
|
|
50
|
+
plugins: { "check-file": checkFile },
|
|
51
|
+
rules: {
|
|
52
|
+
"check-file/filename-naming-convention": [
|
|
53
|
+
"error",
|
|
54
|
+
{ "**/*.ts": "+([a-z0-9_-]).repo" },
|
|
55
|
+
],
|
|
31
56
|
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
configs.push(
|
|
32
60
|
{
|
|
33
61
|
name: "naming/types",
|
|
34
62
|
files: featuresGlob(featureRoot, "*/types/*.type.ts"),
|
|
@@ -49,7 +77,7 @@ export function createNamingConfigs(featureRoot) {
|
|
|
49
77
|
rules: {
|
|
50
78
|
"check-file/filename-naming-convention": [
|
|
51
79
|
"error",
|
|
52
|
-
{ "**/*.ts":
|
|
80
|
+
{ "**/*.ts": `${sharedPrefixPattern}.type` },
|
|
53
81
|
],
|
|
54
82
|
},
|
|
55
83
|
},
|
|
@@ -84,7 +112,7 @@ export function createNamingConfigs(featureRoot) {
|
|
|
84
112
|
rules: {
|
|
85
113
|
"check-file/filename-naming-convention": [
|
|
86
114
|
"error",
|
|
87
|
-
{ "**/*.ts":
|
|
115
|
+
{ "**/*.ts": `${sharedPrefixPattern}.util` },
|
|
88
116
|
],
|
|
89
117
|
},
|
|
90
118
|
},
|
|
@@ -151,5 +179,7 @@ export function createNamingConfigs(featureRoot) {
|
|
|
151
179
|
],
|
|
152
180
|
},
|
|
153
181
|
},
|
|
154
|
-
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
return configs;
|
|
155
185
|
}
|