@yasainet/eslint 0.0.15 → 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/README.md +10 -10
- package/package.json +1 -1
- package/src/common/imports.mjs +26 -1
- package/src/common/index.mjs +5 -2
- package/src/common/layers.mjs +21 -0
- package/src/common/local-plugins/import-path-style.mjs +99 -0
- package/src/common/local-plugins/index.mjs +10 -0
- package/src/common/naming.mjs +2 -6
- package/src/deno/index.mjs +3 -1
- package/src/next/imports.mjs +16 -0
- package/src/next/index.mjs +2 -0
- package/src/node/index.mjs +3 -1
package/README.md
CHANGED
|
@@ -100,22 +100,22 @@ export default [...eslintConfig];
|
|
|
100
100
|
|
|
101
101
|
## Release
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
Version is derived from the Git tag. CI automatically sets `package.json` version before publishing.
|
|
104
|
+
|
|
105
|
+
1. Commit and push to `main`
|
|
106
|
+
2. Create and push a tag:
|
|
106
107
|
|
|
107
108
|
```sh
|
|
108
109
|
git tag v1.0.0
|
|
109
110
|
git push --tags
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
3. GitHub Actions will automatically publish to npm
|
|
113
114
|
|
|
114
115
|
### With lazygit
|
|
115
116
|
|
|
116
|
-
1.
|
|
117
|
-
2.
|
|
118
|
-
3.
|
|
119
|
-
4.
|
|
120
|
-
5.
|
|
121
|
-
6. GitHub Actions will automatically publish to npm
|
|
117
|
+
1. Stage and commit in lazygit
|
|
118
|
+
2. Select the commit, press `T` to create a tag (e.g. `v1.0.0`)
|
|
119
|
+
3. Press `P` to push the commit
|
|
120
|
+
4. Switch to the Tags panel (`]`), select the tag, and press `P` to push it
|
|
121
|
+
5. GitHub Actions will automatically publish to npm
|
package/package.json
CHANGED
package/src/common/imports.mjs
CHANGED
|
@@ -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(
|
|
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",
|
package/src/common/index.mjs
CHANGED
|
@@ -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(
|
|
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
|
}
|
package/src/common/layers.mjs
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
/** @description Scope layer rules to the given feature root */
|
|
2
2
|
export function createLayersConfigs(featureRoot) {
|
|
3
|
+
const loggerSelector = "CallExpression[callee.object.name='logger']";
|
|
4
|
+
const loggerMessage =
|
|
5
|
+
"logger is not allowed outside actions. Logging belongs in actions.";
|
|
6
|
+
|
|
3
7
|
return [
|
|
8
|
+
// Logger/console: all features except actions
|
|
9
|
+
{
|
|
10
|
+
name: "layers/logger",
|
|
11
|
+
files: [`${featureRoot}/**/*.ts`],
|
|
12
|
+
ignores: [`${featureRoot}/**/actions/*.ts`],
|
|
13
|
+
rules: {
|
|
14
|
+
"no-console": "error",
|
|
15
|
+
"no-restricted-syntax": [
|
|
16
|
+
"error",
|
|
17
|
+
{ selector: loggerSelector, message: loggerMessage },
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
// Repositories: try-catch + if + logger
|
|
4
22
|
{
|
|
5
23
|
name: "layers/repositories",
|
|
6
24
|
files: [`${featureRoot}/**/repositories/*.ts`],
|
|
@@ -17,9 +35,11 @@ export function createLayersConfigs(featureRoot) {
|
|
|
17
35
|
message:
|
|
18
36
|
"if statements are not allowed in repositories. Conditional logic belongs in services.",
|
|
19
37
|
},
|
|
38
|
+
{ selector: loggerSelector, message: loggerMessage },
|
|
20
39
|
],
|
|
21
40
|
},
|
|
22
41
|
},
|
|
42
|
+
// Services: try-catch + logger
|
|
23
43
|
{
|
|
24
44
|
name: "layers/services",
|
|
25
45
|
files: [`${featureRoot}/**/services/*.ts`],
|
|
@@ -31,6 +51,7 @@ export function createLayersConfigs(featureRoot) {
|
|
|
31
51
|
message:
|
|
32
52
|
"try-catch is not allowed in services. Error handling belongs in actions.",
|
|
33
53
|
},
|
|
54
|
+
{ selector: loggerSelector, message: loggerMessage },
|
|
34
55
|
],
|
|
35
56
|
},
|
|
36
57
|
},
|
|
@@ -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
|
+
};
|
package/src/common/naming.mjs
CHANGED
|
@@ -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
|
},
|
package/src/deno/index.mjs
CHANGED
|
@@ -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
|
+
];
|
package/src/next/index.mjs
CHANGED
|
@@ -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
|
];
|
package/src/node/index.mjs
CHANGED