@yasainet/eslint 0.0.9 → 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 +10 -5
- package/src/common/imports.mjs +8 -0
- package/src/common/naming.mjs +37 -6
package/package.json
CHANGED
package/src/common/constants.mjs
CHANGED
|
@@ -20,7 +20,12 @@ 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
|
+
|
|
25
|
+
/** @description Extract the base name from a .ts filename by stripping all extensions. */
|
|
26
|
+
function baseName(filename) {
|
|
27
|
+
return filename.replace(/\..*$/, "");
|
|
28
|
+
}
|
|
24
29
|
|
|
25
30
|
/** @description Scan lib directory derived from featureRoot and build prefix-to-lib-relative-path mapping */
|
|
26
31
|
export function generatePrefixLibMapping(featureRoot) {
|
|
@@ -49,13 +54,13 @@ export function generatePrefixLibMapping(featureRoot) {
|
|
|
49
54
|
subEntry.name.endsWith(".ts") &&
|
|
50
55
|
!EXCLUDE_LIST.includes(subEntry.name)
|
|
51
56
|
) {
|
|
52
|
-
const prefix = subEntry.name
|
|
53
|
-
mapping[prefix] = `${entry.name}/${
|
|
57
|
+
const prefix = baseName(subEntry.name);
|
|
58
|
+
mapping[prefix] = `${entry.name}/${subEntry.name.replace(".ts", "")}`;
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
} else if (entry.isFile() && entry.name.endsWith(".ts")) {
|
|
57
|
-
const prefix = entry.name
|
|
58
|
-
mapping[prefix] =
|
|
62
|
+
const prefix = baseName(entry.name);
|
|
63
|
+
mapping[prefix] = entry.name.replace(".ts", "");
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
package/src/common/imports.mjs
CHANGED
|
@@ -175,6 +175,14 @@ export function createImportsConfigs(featureRoot, prefixLibMapping) {
|
|
|
175
175
|
),
|
|
176
176
|
);
|
|
177
177
|
|
|
178
|
+
configs.push(
|
|
179
|
+
makeConfig(
|
|
180
|
+
"utils",
|
|
181
|
+
[`${featureRoot}/**/utils/*.ts`],
|
|
182
|
+
LIB_BOUNDARY_PATTERNS,
|
|
183
|
+
),
|
|
184
|
+
);
|
|
185
|
+
|
|
178
186
|
for (const prefix of ["server", "client", "admin"]) {
|
|
179
187
|
configs.push(
|
|
180
188
|
makeConfig(
|
package/src/common/naming.mjs
CHANGED
|
@@ -5,7 +5,14 @@ import { actionHandleServiceRule } from "./local-plugins/action-handle-service.m
|
|
|
5
5
|
/** @description Scope naming rules to the given feature root */
|
|
6
6
|
export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
7
7
|
const prefixPattern = `@(${Object.keys(prefixLibMapping).join("|")})`;
|
|
8
|
-
|
|
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 = [
|
|
9
16
|
{
|
|
10
17
|
name: "naming/services",
|
|
11
18
|
files: featuresGlob(featureRoot, "**/services/*.ts"),
|
|
@@ -17,17 +24,39 @@ export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
|
17
24
|
],
|
|
18
25
|
},
|
|
19
26
|
},
|
|
20
|
-
|
|
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({
|
|
21
33
|
name: "naming/repositories",
|
|
22
34
|
files: featuresGlob(featureRoot, "**/repositories/*.ts"),
|
|
35
|
+
ignores: featuresGlob(featureRoot, "shared/repositories/*.ts"),
|
|
23
36
|
plugins: { "check-file": checkFile },
|
|
24
37
|
rules: {
|
|
25
38
|
"check-file/filename-naming-convention": [
|
|
26
39
|
"error",
|
|
27
|
-
{ "**/*.ts": `${
|
|
40
|
+
{ "**/*.ts": `${dbPrefixPattern}.repo` },
|
|
28
41
|
],
|
|
29
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
|
+
],
|
|
30
56
|
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
configs.push(
|
|
31
60
|
{
|
|
32
61
|
name: "naming/types",
|
|
33
62
|
files: featuresGlob(featureRoot, "*/types/*.type.ts"),
|
|
@@ -48,7 +77,7 @@ export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
|
48
77
|
rules: {
|
|
49
78
|
"check-file/filename-naming-convention": [
|
|
50
79
|
"error",
|
|
51
|
-
{ "**/*.ts":
|
|
80
|
+
{ "**/*.ts": `${sharedPrefixPattern}.type` },
|
|
52
81
|
],
|
|
53
82
|
},
|
|
54
83
|
},
|
|
@@ -83,7 +112,7 @@ export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
|
83
112
|
rules: {
|
|
84
113
|
"check-file/filename-naming-convention": [
|
|
85
114
|
"error",
|
|
86
|
-
{ "**/*.ts":
|
|
115
|
+
{ "**/*.ts": `${sharedPrefixPattern}.util` },
|
|
87
116
|
],
|
|
88
117
|
},
|
|
89
118
|
},
|
|
@@ -150,5 +179,7 @@ export function createNamingConfigs(featureRoot, prefixLibMapping) {
|
|
|
150
179
|
],
|
|
151
180
|
},
|
|
152
181
|
},
|
|
153
|
-
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
return configs;
|
|
154
185
|
}
|