@yasainet/eslint 0.0.16 → 0.0.17

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.16",
3
+ "version": "0.0.17",
4
4
  "description": "ESLint",
5
5
  "type": "module",
6
6
  "exports": {
@@ -129,9 +129,34 @@ export const libBoundaryConfigs = [
129
129
  ];
130
130
 
131
131
  /** @description Scope import restriction rules to the given feature root */
132
- export function createImportsConfigs(featureRoot, prefixLibMapping) {
132
+ export function createImportsConfigs(
133
+ featureRoot,
134
+ prefixLibMapping,
135
+ { banAliasImports = false } = {},
136
+ ) {
133
137
  const configs = [];
134
138
 
139
+ if (banAliasImports) {
140
+ configs.push({
141
+ name: "imports/ban-alias",
142
+ files: [`${featureRoot}/**/*.ts`],
143
+ rules: {
144
+ "no-restricted-imports": [
145
+ "error",
146
+ {
147
+ patterns: [
148
+ {
149
+ group: ["@/*", "@/**"],
150
+ message:
151
+ "Alias imports (@/) are not available in this environment. Use relative paths.",
152
+ },
153
+ ],
154
+ },
155
+ ],
156
+ },
157
+ });
158
+ }
159
+
135
160
  configs.push(
136
161
  makeConfig(
137
162
  "repositories",
@@ -6,13 +6,16 @@ import { createNamingConfigs } from "./naming.mjs";
6
6
  import { rulesConfigs } from "./rules.mjs";
7
7
 
8
8
  /** @description Build common configs scoped to the given feature root */
9
- export function createCommonConfigs(featureRoot) {
9
+ export function createCommonConfigs(
10
+ featureRoot,
11
+ { banAliasImports = false } = {},
12
+ ) {
10
13
  const prefixLibMapping = generatePrefixLibMapping(featureRoot);
11
14
  return [
12
15
  ...rulesConfigs,
13
16
  ...createNamingConfigs(featureRoot, prefixLibMapping),
14
17
  ...createLayersConfigs(featureRoot),
15
- ...createImportsConfigs(featureRoot, prefixLibMapping),
18
+ ...createImportsConfigs(featureRoot, prefixLibMapping, { banAliasImports }),
16
19
  ...createJsdocConfigs(featureRoot),
17
20
  ];
18
21
  }
@@ -0,0 +1,99 @@
1
+ import path from "path";
2
+
3
+ /**
4
+ * @description Enforce import path style within features:
5
+ * - Same-feature imports must use relative paths
6
+ * - Cross-feature imports must use @/ alias
7
+ */
8
+ export const importPathStyleRule = {
9
+ meta: {
10
+ type: "problem",
11
+ messages: {
12
+ useRelative:
13
+ "Same-feature import must use a relative path instead of '{{ importPath }}'.",
14
+ useAlias:
15
+ "Cross-feature import must use '@/' instead of relative path '{{ importPath }}'.",
16
+ },
17
+ schema: [
18
+ {
19
+ type: "object",
20
+ properties: {
21
+ featureRoot: { type: "string" },
22
+ },
23
+ required: ["featureRoot"],
24
+ additionalProperties: false,
25
+ },
26
+ ],
27
+ },
28
+ create(context) {
29
+ const { featureRoot } = context.options[0];
30
+ const filename = context.filename;
31
+
32
+ const rootSep = featureRoot + "/";
33
+ const rootIdx = filename.indexOf(rootSep);
34
+ if (rootIdx === -1) return {};
35
+
36
+ const afterRoot = filename.slice(rootIdx + rootSep.length);
37
+ const featureName = afterRoot.split("/")[0];
38
+ if (!featureName) return {};
39
+
40
+ // Absolute path of the current feature directory
41
+ const featureDir =
42
+ filename.slice(0, rootIdx + rootSep.length) + featureName;
43
+
44
+ // Alias prefix for same-feature: @/features/{featureName}
45
+ const aliasBase = featureRoot.replace(/^src\//, "");
46
+ const sameFeaturePrefix = `@/${aliasBase}/${featureName}/`;
47
+ const sameFeatureExact = `@/${aliasBase}/${featureName}`;
48
+
49
+ function check(source) {
50
+ if (!source || typeof source.value !== "string") return;
51
+ const importPath = source.value;
52
+
53
+ // Case 1: @/features/{same-feature}/... → use relative path
54
+ if (
55
+ importPath.startsWith(sameFeaturePrefix) ||
56
+ importPath === sameFeatureExact
57
+ ) {
58
+ context.report({
59
+ node: source,
60
+ messageId: "useRelative",
61
+ data: { importPath },
62
+ });
63
+ return;
64
+ }
65
+
66
+ // Case 2: relative path that exits current feature → use @/
67
+ if (importPath.startsWith(".")) {
68
+ const resolved = path.resolve(path.dirname(filename), importPath);
69
+ if (
70
+ !resolved.startsWith(featureDir + "/") &&
71
+ resolved !== featureDir
72
+ ) {
73
+ context.report({
74
+ node: source,
75
+ messageId: "useAlias",
76
+ data: { importPath },
77
+ });
78
+ }
79
+ }
80
+ }
81
+
82
+ return {
83
+ ImportDeclaration(node) {
84
+ check(node.source);
85
+ },
86
+ ExportNamedDeclaration(node) {
87
+ if (node.source) check(node.source);
88
+ },
89
+ ExportAllDeclaration(node) {
90
+ check(node.source);
91
+ },
92
+ ImportExpression(node) {
93
+ if (node.source && node.source.type === "Literal") {
94
+ check(node.source);
95
+ }
96
+ },
97
+ };
98
+ },
99
+ };
@@ -0,0 +1,10 @@
1
+ import { actionHandleServiceRule } from "./action-handle-service.mjs";
2
+ import { importPathStyleRule } from "./import-path-style.mjs";
3
+
4
+ /** @description Shared local plugin object to avoid ESLint "Cannot redefine plugin" errors */
5
+ export const localPlugin = {
6
+ rules: {
7
+ "action-handle-service": actionHandleServiceRule,
8
+ "import-path-style": importPathStyleRule,
9
+ },
10
+ };
@@ -1,6 +1,6 @@
1
1
  import { featuresGlob } from "./constants.mjs";
2
+ import { localPlugin } from "./local-plugins/index.mjs";
2
3
  import { checkFile } from "./plugins.mjs";
3
- import { actionHandleServiceRule } from "./local-plugins/action-handle-service.mjs";
4
4
 
5
5
  /** @description Scope naming rules to the given feature root */
6
6
  export function createNamingConfigs(featureRoot, prefixLibMapping) {
@@ -181,11 +181,7 @@ export function createNamingConfigs(featureRoot, prefixLibMapping) {
181
181
  {
182
182
  name: "naming/actions-handle-service",
183
183
  files: featuresGlob(featureRoot, "**/actions/*.ts"),
184
- plugins: {
185
- local: {
186
- rules: { "action-handle-service": actionHandleServiceRule },
187
- },
188
- },
184
+ plugins: { local: localPlugin },
189
185
  rules: {
190
186
  "local/action-handle-service": "error",
191
187
  },
@@ -1,5 +1,7 @@
1
1
  import { createCommonConfigs } from "../common/index.mjs";
2
2
 
3
3
  export const eslintConfig = [
4
- ...createCommonConfigs("supabase/functions/features"),
4
+ ...createCommonConfigs("supabase/functions/features", {
5
+ banAliasImports: true,
6
+ }),
5
7
  ];
@@ -0,0 +1,16 @@
1
+ import { localPlugin } from "../common/local-plugins/index.mjs";
2
+
3
+ /** @description Next.js: enforce relative paths within same feature, @/ for cross-feature */
4
+ export const importPathStyleConfigs = [
5
+ {
6
+ name: "imports/path-style",
7
+ files: ["src/features/**/*.ts"],
8
+ plugins: { local: localPlugin },
9
+ rules: {
10
+ "local/import-path-style": [
11
+ "error",
12
+ { featureRoot: "src/features" },
13
+ ],
14
+ },
15
+ },
16
+ ];
@@ -2,6 +2,7 @@ import { createCommonConfigs } from "../common/index.mjs";
2
2
  import { libBoundaryConfigs } from "../common/imports.mjs";
3
3
 
4
4
  import { directivesConfigs } from "./directives.mjs";
5
+ import { importPathStyleConfigs } from "./imports.mjs";
5
6
  import { namingConfigs } from "./naming.mjs";
6
7
 
7
8
  export const eslintConfig = [
@@ -9,4 +10,5 @@ export const eslintConfig = [
9
10
  ...libBoundaryConfigs,
10
11
  ...namingConfigs,
11
12
  ...directivesConfigs,
13
+ ...importPathStyleConfigs,
12
14
  ];
@@ -1,3 +1,5 @@
1
1
  import { createCommonConfigs } from "../common/index.mjs";
2
2
 
3
- export const eslintConfig = [...createCommonConfigs("scripts/features")];
3
+ export const eslintConfig = [
4
+ ...createCommonConfigs("scripts/features", { banAliasImports: true }),
5
+ ];