@no-k/hermes 0.2.0 → 0.3.2

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.
@@ -0,0 +1,22 @@
1
+ import type { Rule } from "eslint";
2
+ import { createImportListener } from "../import-listener";
3
+ import { optionSchema } from "../options";
4
+
5
+ const rule: Rule.RuleModule = {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Enforce FSD layer direction and slice isolation",
10
+ url: "https://github.com/no-k/hermes/tree/main/packages/lib/lint/fsd#fsd-layer-imports",
11
+ },
12
+ schema: [optionSchema],
13
+ messages: {
14
+ invalidDirection: "FSD layer '{{fromLayer}}' cannot import upper layer '{{toLayer}}'.",
15
+ crossSliceSameLayer:
16
+ "FSD same-layer imports must stay inside the same slice. '{{fromLayer}}/{{fromSlice}}' cannot import '{{toLayer}}/{{toSlice}}'.",
17
+ },
18
+ },
19
+ create: (context) => createImportListener(context, "checkLayers"),
20
+ };
21
+
22
+ export default rule;
@@ -0,0 +1,20 @@
1
+ import type { Rule } from "eslint";
2
+ import { createImportListener } from "../import-listener";
3
+ import { optionSchema } from "../options";
4
+
5
+ const rule: Rule.RuleModule = {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Enforce public API imports across FSD scopes",
10
+ url: "https://github.com/no-k/hermes/tree/main/packages/lib/lint/fsd#fsd-public-api",
11
+ },
12
+ schema: [optionSchema],
13
+ messages: {
14
+ usePublicApi: "FSD cross-scope import must use the public API of '{{layer}}/{{publicName}}'.",
15
+ },
16
+ },
17
+ create: (context) => createImportListener(context, "checkPublicApi"),
18
+ };
19
+
20
+ export default rule;
@@ -0,0 +1,33 @@
1
+ import type { Rule } from "eslint";
2
+ import { createFsdPolicy } from "../fsd";
3
+ import { type FsdOptions, optionSchema } from "../options";
4
+
5
+ const rule: Rule.RuleModule = {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Enforce FSD slice/segment structure, including segment-only App and Shared",
10
+ url: "https://github.com/no-k/hermes/tree/main/packages/lib/lint/fsd#fsd-slice-segments",
11
+ },
12
+ schema: [optionSchema],
13
+ messages: {
14
+ missingSlice: "FSD layer '{{layer}}' must contain slice directories before implementation files.",
15
+ missingSegment:
16
+ "FSD implementation in '{{layer}}/{{slice}}' must live in a segment or be an allowed public API entrypoint.",
17
+ },
18
+ },
19
+ create(context) {
20
+ if (!context.filename || context.filename.startsWith("<")) return {};
21
+ const policy = createFsdPolicy(context.cwd, context.options[0] as FsdOptions | undefined);
22
+ const location = policy.locate(context.filename);
23
+ if (!location) return {};
24
+ return {
25
+ Program(node) {
26
+ const violation = policy.checkStructure(location);
27
+ if (violation) context.report({ node, ...violation });
28
+ },
29
+ };
30
+ },
31
+ };
32
+
33
+ export default rule;