@yasainet/eslint 0.0.7 → 0.0.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasainet/eslint",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "ESLint",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,8 +22,10 @@ const PROJECT_ROOT = findProjectRoot();
22
22
 
23
23
  const EXCLUDE_LIST = ["proxy.ts", "types"];
24
24
 
25
- function generatePrefixLibMapping() {
26
- const libDir = path.join(PROJECT_ROOT, "src/lib");
25
+ /** @description Scan lib directory derived from featureRoot and build prefix-to-lib-relative-path mapping */
26
+ export function generatePrefixLibMapping(featureRoot) {
27
+ const libRoot = featureRoot.replace(/features$/, "lib");
28
+ const libDir = path.join(PROJECT_ROOT, libRoot);
27
29
  const mapping = {};
28
30
 
29
31
  if (!fs.existsSync(libDir)) {
@@ -48,20 +50,18 @@ function generatePrefixLibMapping() {
48
50
  !EXCLUDE_LIST.includes(subEntry.name)
49
51
  ) {
50
52
  const prefix = subEntry.name.replace(".ts", "");
51
- mapping[prefix] = `@/lib/${entry.name}/${prefix}`;
53
+ mapping[prefix] = `${entry.name}/${prefix}`;
52
54
  }
53
55
  }
54
56
  } else if (entry.isFile() && entry.name.endsWith(".ts")) {
55
57
  const prefix = entry.name.replace(".ts", "");
56
- mapping[prefix] = `@/lib/${prefix}`;
58
+ mapping[prefix] = prefix;
57
59
  }
58
60
  }
59
61
 
60
62
  return mapping;
61
63
  }
62
64
 
63
- export const PREFIX_LIB_MAPPING = generatePrefixLibMapping();
64
-
65
65
  export const featuresGlob = (featureRoot, subpath) => [
66
66
  `${featureRoot}/${subpath}`,
67
67
  ];
@@ -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(PREFIX_LIB_MAPPING);
86
- const allowedLib = PREFIX_LIB_MAPPING[prefix];
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: [PREFIX_LIB_MAPPING[p], `${PREFIX_LIB_MAPPING[p]}/*`],
91
- message: `${prefix}.repo.ts can only import from ${allowedLib}. Use the correct repository file for this lib.`,
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: ["@/lib/*", "@/lib/**"],
95
+ group: ["**/lib/*", "**/lib/**"],
98
96
  message:
99
- "@/lib/* can only be imported from repositories (lib-boundary violation)",
97
+ "lib/* can only be imported from repositories (lib-boundary violation)",
100
98
  },
101
99
  ];
102
100
 
@@ -122,6 +120,7 @@ export const libBoundaryConfigs = [
122
120
  "src/proxy.ts",
123
121
  "src/app/sitemap.ts",
124
122
  "src/features/**/repositories/**",
123
+ "src/features/**/types/**",
125
124
  ],
126
125
  rules: {
127
126
  "no-restricted-imports": ["error", { patterns: LIB_BOUNDARY_PATTERNS }],
@@ -130,7 +129,7 @@ export const libBoundaryConfigs = [
130
129
  ];
131
130
 
132
131
  /** @description Scope import restriction rules to the given feature root */
133
- export function createImportsConfigs(featureRoot) {
132
+ export function createImportsConfigs(featureRoot, prefixLibMapping) {
134
133
  const configs = [];
135
134
 
136
135
  configs.push(
@@ -142,8 +141,8 @@ export function createImportsConfigs(featureRoot) {
142
141
  ),
143
142
  );
144
143
 
145
- for (const prefix of Object.keys(PREFIX_LIB_MAPPING)) {
146
- const patterns = prefixLibPatterns(prefix);
144
+ for (const prefix of Object.keys(prefixLibMapping)) {
145
+ const patterns = prefixLibPatterns(prefix, prefixLibMapping);
147
146
  if (patterns.length === 0) continue;
148
147
  configs.push(
149
148
  makeConfig(
@@ -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
  }
@@ -1,11 +1,10 @@
1
- import { featuresGlob, PREFIX_LIB_MAPPING } from "./constants.mjs";
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) {
6
+ export function createNamingConfigs(featureRoot, prefixLibMapping) {
7
+ const prefixPattern = `@(${Object.keys(prefixLibMapping).join("|")})`;
9
8
  return [
10
9
  {
11
10
  name: "naming/services",