@yasainet/eslint 0.0.46 → 0.0.48
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/imports.mjs +51 -0
- package/src/common/layers.mjs +5 -0
- package/src/common/rules.mjs +22 -1
- package/src/next/index.mjs +8 -1
package/package.json
CHANGED
package/src/common/imports.mjs
CHANGED
|
@@ -124,6 +124,32 @@ const PAGE_BOUNDARY_PATTERNS = [
|
|
|
124
124
|
},
|
|
125
125
|
];
|
|
126
126
|
|
|
127
|
+
const HOOKS_BOUNDARY_PATTERNS = [
|
|
128
|
+
{
|
|
129
|
+
group: ["*/repositories/*", "*/repositories"],
|
|
130
|
+
message:
|
|
131
|
+
"hooks can only import actions, not repositories (hooks-boundary violation)",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
group: ["*/services/*", "*/services"],
|
|
135
|
+
message:
|
|
136
|
+
"hooks can only import actions, not services (hooks-boundary violation)",
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const COMPONENTS_BOUNDARY_PATTERNS = [
|
|
141
|
+
{
|
|
142
|
+
group: ["*/repositories/*", "*/repositories"],
|
|
143
|
+
message:
|
|
144
|
+
"components can only import actions or hooks, not repositories (components-boundary violation)",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
group: ["*/services/*", "*/services"],
|
|
148
|
+
message:
|
|
149
|
+
"components can only import actions or hooks, not services (components-boundary violation)",
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
|
|
127
153
|
function makeConfig(name, files, ...patternArrays) {
|
|
128
154
|
const patterns = patternArrays.flat();
|
|
129
155
|
if (patterns.length === 0) return null;
|
|
@@ -147,6 +173,31 @@ export const pageBoundaryConfigs = [
|
|
|
147
173
|
},
|
|
148
174
|
];
|
|
149
175
|
|
|
176
|
+
/** Next.js-only: restrict hooks to only import actions (not repositories or services). */
|
|
177
|
+
export const hooksBoundaryConfigs = [
|
|
178
|
+
{
|
|
179
|
+
name: "imports/hooks-boundary",
|
|
180
|
+
files: ["src/features/**/hooks/*.ts"],
|
|
181
|
+
rules: {
|
|
182
|
+
"no-restricted-imports": ["error", { patterns: HOOKS_BOUNDARY_PATTERNS }],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
/** Next.js-only: restrict components to only import actions or hooks (not repositories or services). */
|
|
188
|
+
export const componentsBoundaryConfigs = [
|
|
189
|
+
{
|
|
190
|
+
name: "imports/components-boundary",
|
|
191
|
+
files: ["src/components/**/*.{ts,tsx}"],
|
|
192
|
+
rules: {
|
|
193
|
+
"no-restricted-imports": [
|
|
194
|
+
"error",
|
|
195
|
+
{ patterns: COMPONENTS_BOUNDARY_PATTERNS },
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
|
|
150
201
|
/**
|
|
151
202
|
* Next.js-only: restrict @/lib imports and mapping imports outside features.
|
|
152
203
|
* Per-feature subdir rules live in createImportsConfigs to avoid clobbering each other.
|
package/src/common/layers.mjs
CHANGED
|
@@ -60,6 +60,11 @@ export function createLayersConfigs(featureRoot) {
|
|
|
60
60
|
message:
|
|
61
61
|
"Loops are not allowed in repositories. Repositories should be thin CRUD wrappers — iteration belongs in services.",
|
|
62
62
|
},
|
|
63
|
+
{
|
|
64
|
+
selector: "ThrowStatement",
|
|
65
|
+
message:
|
|
66
|
+
"throw is not allowed in repositories. Repositories must return Supabase's { data, error } shape as-is. Error handling belongs in actions.",
|
|
67
|
+
},
|
|
63
68
|
{ selector: loggerSelector, message: loggerMessage },
|
|
64
69
|
],
|
|
65
70
|
},
|
package/src/common/rules.mjs
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join, sep } from "node:path";
|
|
3
|
+
|
|
1
4
|
import tseslint from "typescript-eslint";
|
|
2
5
|
|
|
3
6
|
import { simpleImportSortPlugin, stylistic } from "./plugins.mjs";
|
|
4
7
|
|
|
8
|
+
// When evaluated under LSP servers like vscode-eslint, `process.cwd()` returns
|
|
9
|
+
// the linted file's directory rather than the consumer's project root, so it
|
|
10
|
+
// cannot be used to derive `tsconfigRootDir`. Walk up from this module until a
|
|
11
|
+
// `tsconfig.json` outside of `node_modules` is found. Falls back to
|
|
12
|
+
// `process.cwd()` for CLI parity if no such directory is reachable.
|
|
13
|
+
const findProjectRoot = (start) => {
|
|
14
|
+
let dir = start;
|
|
15
|
+
while (dir !== dirname(dir)) {
|
|
16
|
+
if (!dir.split(sep).includes("node_modules") && existsSync(join(dir, "tsconfig.json"))) {
|
|
17
|
+
return dir;
|
|
18
|
+
}
|
|
19
|
+
dir = dirname(dir);
|
|
20
|
+
}
|
|
21
|
+
return process.cwd();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const projectRoot = findProjectRoot(import.meta.dirname);
|
|
25
|
+
|
|
5
26
|
/** Base rule configs for code style and TypeScript checks. */
|
|
6
27
|
export const rulesConfigs = [
|
|
7
28
|
{
|
|
@@ -46,7 +67,7 @@ export const rulesConfigs = [
|
|
|
46
67
|
// can consult the TypeScript type checker.
|
|
47
68
|
parserOptions: {
|
|
48
69
|
projectService: true,
|
|
49
|
-
tsconfigRootDir:
|
|
70
|
+
tsconfigRootDir: projectRoot,
|
|
50
71
|
},
|
|
51
72
|
},
|
|
52
73
|
plugins: {
|
package/src/next/index.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { createEntryPointConfigs } from "../common/entry-points.mjs";
|
|
2
2
|
import { createCommonConfigs } from "../common/index.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
componentsBoundaryConfigs,
|
|
5
|
+
hooksBoundaryConfigs,
|
|
6
|
+
libBoundaryConfigs,
|
|
7
|
+
pageBoundaryConfigs,
|
|
8
|
+
} from "../common/imports.mjs";
|
|
4
9
|
|
|
5
10
|
import { directivesConfigs } from "./directives.mjs";
|
|
6
11
|
import { importPathStyleConfigs } from "./imports.mjs";
|
|
@@ -21,6 +26,8 @@ export const eslintConfig = [
|
|
|
21
26
|
...createCommonConfigs("src/features"),
|
|
22
27
|
...libBoundaryConfigs,
|
|
23
28
|
...pageBoundaryConfigs,
|
|
29
|
+
...hooksBoundaryConfigs,
|
|
30
|
+
...componentsBoundaryConfigs,
|
|
24
31
|
...namingConfigs,
|
|
25
32
|
...directivesConfigs,
|
|
26
33
|
...importPathStyleConfigs,
|