@cerios/sparta-lint-rules 0.0.2 → 0.0.3
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 +41 -10
- package/dist/conventions-DK3A7JWL.d.cts +97 -0
- package/dist/conventions-DK3A7JWL.d.mts +97 -0
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.mts +16 -2
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/oxlint.cjs +2 -1
- package/dist/oxlint.cjs.map +1 -1
- package/dist/oxlint.d.cts +18 -1
- package/dist/oxlint.d.mts +19 -2
- package/dist/oxlint.mjs +2 -1
- package/dist/oxlint.mjs.map +1 -1
- package/dist/{plugin-types-CXFDQLJF.d.cts → plugin-types-7QJakt0Z.d.cts} +8 -3
- package/dist/{plugin-types-CXFDQLJF.d.mts → plugin-types-7QJakt0Z.d.mts} +8 -3
- package/dist/{rules-T_C5segG.cjs → rules-5VZcw4ds.cjs} +43 -29
- package/dist/rules-5VZcw4ds.cjs.map +1 -0
- package/dist/{rules-D94N3gGx.mjs → rules-Ay2ZlXtg.mjs} +43 -29
- package/dist/rules-Ay2ZlXtg.mjs.map +1 -0
- package/dist/settings.cjs +1 -0
- package/dist/settings.d.cts +5 -96
- package/dist/settings.d.mts +5 -96
- package/dist/settings.mjs +1 -0
- package/oxlintrc.schema.json +718 -0
- package/package.json +10 -3
- package/dist/rules-D94N3gGx.mjs.map +0 -1
- package/dist/rules-T_C5segG.cjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
// \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -131,7 +132,11 @@ const LAYER_FOLDERS = {
|
|
|
131
132
|
suffix: "window"
|
|
132
133
|
}
|
|
133
134
|
};
|
|
134
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Layer folders that may also live outside a group: directly in an area (`sparta/<area>/builders/`), shared by its
|
|
137
|
+
* groups, and in `sparta/common/`, shared by everything. In a group or an area's `common/` they are ordinary layer
|
|
138
|
+
* folders.
|
|
139
|
+
*/
|
|
135
140
|
const AREA_LAYER_FOLDERS = /* @__PURE__ */ new Set(["builders", "directors"]);
|
|
136
141
|
const AREAS = [
|
|
137
142
|
"api",
|
|
@@ -274,6 +279,7 @@ function buildPatterns(spartaFolder, testsFolder, areas) {
|
|
|
274
279
|
area: new RegExp(`/${sparta}/(${areaNames})${end}(?:/([^/]+))?(?:/([^/]+))?`),
|
|
275
280
|
layer: new RegExp(`/${sparta}/(?:${areaNames})/[^/]+/([^/]+)/`),
|
|
276
281
|
top: new RegExp(`/${sparta}/(${TOP_LEVEL_FOLDERS.join("|")})${end}`),
|
|
282
|
+
common: new RegExp(`/${sparta}/common/([^/]+)${end}`),
|
|
277
283
|
checked: new RegExp(`/(?:${sparta}|${tests})/`),
|
|
278
284
|
sparta: new RegExp(`/${sparta}/`),
|
|
279
285
|
tests: new RegExp(`/${tests}${end}`),
|
|
@@ -508,15 +514,18 @@ const TOP_LEVEL_KINDS = {
|
|
|
508
514
|
const standardFolder = (conventions, folder) => folder === void 0 ? void 0 : conventions.layerFolders.get(folder);
|
|
509
515
|
/** The layer of a standard layer folder (`stepper` for `steppers`), if it has one. */
|
|
510
516
|
const layerOf = (standard) => standard === void 0 ? void 0 : LAYER_FOLDERS[standard].layer;
|
|
511
|
-
/**
|
|
512
|
-
const
|
|
513
|
-
const name = file.match(conventions.patterns.area)?.[2];
|
|
517
|
+
/** `name` as a builders or directors folder (`AREA_LAYER_FOLDERS`), if it is one. */
|
|
518
|
+
const builderFolder = (conventions, name) => {
|
|
514
519
|
const standard = standardFolder(conventions, name);
|
|
515
520
|
return name !== void 0 && standard !== void 0 && AREA_LAYER_FOLDERS.has(standard) ? {
|
|
516
521
|
name,
|
|
517
522
|
standard
|
|
518
523
|
} : void 0;
|
|
519
524
|
};
|
|
525
|
+
/** The area-level layer folder (`builders/`, `directors/` directly below an area) a project path is in, if any. */
|
|
526
|
+
const areaLayerFolder = (file, conventions) => builderFolder(conventions, file.match(conventions.patterns.area)?.[2]);
|
|
527
|
+
/** The `builders/` or `directors/` folder directly below `sparta/common/` a project path is in, if any. */
|
|
528
|
+
const commonLayerFolder = (file, conventions) => builderFolder(conventions, file.match(conventions.patterns.common)?.[1]);
|
|
520
529
|
const caseInsensitivePaths = process.platform === "win32";
|
|
521
530
|
/**
|
|
522
531
|
* The part of `filename` below the project `root`, with a leading `/` (`/sparta/ui/...`), or `undefined` for files
|
|
@@ -556,7 +565,12 @@ function classify(filename, conventions, root) {
|
|
|
556
565
|
};
|
|
557
566
|
}
|
|
558
567
|
const top = file.match(patterns.top)?.[1];
|
|
559
|
-
|
|
568
|
+
if (top === void 0) return void 0;
|
|
569
|
+
const commonLayer = top === "common" ? commonLayerFolder(file, conventions) : void 0;
|
|
570
|
+
return commonLayer ? {
|
|
571
|
+
kind: "shared",
|
|
572
|
+
layer: layerOf(commonLayer.standard)
|
|
573
|
+
} : { kind: TOP_LEVEL_KINDS[top] ?? "shared" };
|
|
560
574
|
}
|
|
561
575
|
/** Project root per directory, kept for the lifetime of the linter process. */
|
|
562
576
|
const rootCache = /* @__PURE__ */ new Map();
|
|
@@ -631,10 +645,12 @@ function resolveImport(filename, request, root, conventions) {
|
|
|
631
645
|
const layerFolder = (filename, conventions, root) => {
|
|
632
646
|
const file = projectPath(filename, root);
|
|
633
647
|
if (file === void 0) return void 0;
|
|
634
|
-
|
|
648
|
+
const top = file.match(conventions.patterns.top)?.[1];
|
|
649
|
+
if (top === "scenarios") return {
|
|
635
650
|
name: "scenarios",
|
|
636
651
|
standard: "scenarios"
|
|
637
652
|
};
|
|
653
|
+
if (top === "common") return commonLayerFolder(file, conventions);
|
|
638
654
|
const areaLayer = areaLayerFolder(file, conventions);
|
|
639
655
|
if (areaLayer) return areaLayer;
|
|
640
656
|
const folder = file.match(conventions.patterns.layer)?.[1];
|
|
@@ -810,15 +826,17 @@ const FORBIDDEN_LAYERS = {
|
|
|
810
826
|
mobile: uiLayers("screen"),
|
|
811
827
|
ui: uiLayers("page")
|
|
812
828
|
};
|
|
813
|
-
/** The layers of `
|
|
829
|
+
/** The layers of the `builders/` and `directors/` folders, wherever they live. */
|
|
814
830
|
const BUILDER_LAYERS = /* @__PURE__ */ new Set(["builder", "director"]);
|
|
815
|
-
/** The only
|
|
831
|
+
/** The only layers, besides directors, that may use builders and directors. */
|
|
816
832
|
const BUILDER_USERS = /* @__PURE__ */ new Set([
|
|
817
833
|
"scenario",
|
|
818
834
|
"stepper",
|
|
819
835
|
"asserter",
|
|
820
836
|
"service"
|
|
821
837
|
]);
|
|
838
|
+
/** Whether a file is a builder or director: in a group, an area's `common/`, an area, or `sparta/common/`. */
|
|
839
|
+
const isBuilderLayer = (info) => info.layer !== void 0 && BUILDER_LAYERS.has(info.layer);
|
|
822
840
|
const DATABASE_ACCESS = [
|
|
823
841
|
"repository",
|
|
824
842
|
"base-repository",
|
|
@@ -898,7 +916,7 @@ const describe = (info, { spartaFolder, testsFolder }) => ({
|
|
|
898
916
|
"area-layer": `${info.areaFolder} ${info.layer}`,
|
|
899
917
|
"top-scenario": `${spartaFolder}/scenarios`,
|
|
900
918
|
fixture: `${spartaFolder}/fixtures`,
|
|
901
|
-
shared: `${spartaFolder}/common|support`,
|
|
919
|
+
shared: info.layer ? `${spartaFolder}/common ${info.layer}` : `${spartaFolder}/common|support`,
|
|
902
920
|
test: testsFolder
|
|
903
921
|
})[info.kind];
|
|
904
922
|
/** Whether code in an area folder (a group, or the area's builders and directors) may not depend on `target`. */
|
|
@@ -932,16 +950,23 @@ function isolationViolation(source, target) {
|
|
|
932
950
|
}
|
|
933
951
|
/**
|
|
934
952
|
* Whether `source` may not use the builder or director `target`: builders use no builders or directors, directors
|
|
935
|
-
* only use builders, and
|
|
953
|
+
* only use builders, and otherwise only scenarios, steppers, asserters and services may use them. Fixtures,
|
|
954
|
+
* top-level scenarios and tests are left to the other checks. Which builders a file can see is up to isolation.
|
|
936
955
|
*/
|
|
937
956
|
function builderViolation(source, target) {
|
|
938
|
-
if (source
|
|
939
|
-
if (
|
|
957
|
+
if (isBuilderLayer(source)) return source.layer === "builder" || target.layer === "director";
|
|
958
|
+
if ([
|
|
959
|
+
"group",
|
|
960
|
+
"area-common",
|
|
961
|
+
"shared"
|
|
962
|
+
].includes(source.kind)) return source.layer === void 0 || !BUILDER_USERS.has(source.layer);
|
|
940
963
|
}
|
|
941
964
|
function layerViolation(source, target) {
|
|
942
|
-
if (!target.layer
|
|
965
|
+
if (!target.layer) return false;
|
|
943
966
|
const builder = BUILDER_LAYERS.has(target.layer) ? builderViolation(source, target) : void 0;
|
|
944
967
|
if (builder !== void 0) return builder;
|
|
968
|
+
if (isBuilderLayer(source)) return target.layer !== "service";
|
|
969
|
+
if (!target.area) return false;
|
|
945
970
|
if (source.kind === "group" || source.kind === "area-common") {
|
|
946
971
|
if (!source.area || !source.layer) return false;
|
|
947
972
|
return source.areaFolder === target.areaFolder && Boolean(FORBIDDEN_LAYERS[source.area][source.layer]?.has(target.layer));
|
|
@@ -962,8 +987,7 @@ const rule$13 = {
|
|
|
962
987
|
isolation: "{{source}} must not depend on {{target}} ({{request}}). Move shared code to the area's common/ folder or the top-level common/ folder.",
|
|
963
988
|
layer: "{{source}} must not depend on {{target}} ({{request}}).",
|
|
964
989
|
reexport: "Do not re-export {{target}} outside its layer; this bypasses the architecture boundaries.",
|
|
965
|
-
staticService: "{{source}} is a static abstract class and must not depend on {{target}} ({{request}}); only a normal class may use services."
|
|
966
|
-
placement: "Builders and directors belong in '{{expected}}/', shared by the area's groups, not in a group folder."
|
|
990
|
+
staticService: "{{source}} is a static abstract class and must not depend on {{target}} ({{request}}); only a normal class may use services."
|
|
967
991
|
}
|
|
968
992
|
},
|
|
969
993
|
create(context) {
|
|
@@ -975,7 +999,7 @@ const rule$13 = {
|
|
|
975
999
|
/** Whether the file declares a normal (instantiable) class. Set on `Program`, before any import is visited. */
|
|
976
1000
|
let isNormalClass = false;
|
|
977
1001
|
/** An `index.ts` barrel in `builders/` or `directors/` may import and re-export its own layer. */
|
|
978
|
-
const isOwnBarrel = (target) => source
|
|
1002
|
+
const isOwnBarrel = (target) => isBuilderLayer(source) && moduleName(filename) === "index" && target.kind === source.kind && target.areaFolder === source.areaFolder && target.group === source.group && target.layer === source.layer;
|
|
979
1003
|
const check = (node, request, reexport = false) => {
|
|
980
1004
|
if (request === void 0) return;
|
|
981
1005
|
const resolved = resolveImport(filename, request, root, conventions);
|
|
@@ -996,7 +1020,7 @@ const rule$13 = {
|
|
|
996
1020
|
messageId: "layer",
|
|
997
1021
|
data
|
|
998
1022
|
});
|
|
999
|
-
else if (source
|
|
1023
|
+
else if (isBuilderLayer(source) && target.layer === "service" && !isNormalClass) context.report({
|
|
1000
1024
|
node,
|
|
1001
1025
|
messageId: "staticService",
|
|
1002
1026
|
data
|
|
@@ -1010,15 +1034,6 @@ const rule$13 = {
|
|
|
1010
1034
|
return {
|
|
1011
1035
|
Program(node) {
|
|
1012
1036
|
isNormalClass = topLevelClasses(node).some((declaration) => !isStaticClass(declaration));
|
|
1013
|
-
if (source.kind === "group" && source.layer !== void 0 && BUILDER_LAYERS.has(source.layer)) {
|
|
1014
|
-
const folder = layerFolder(filename, conventions, root)?.name ?? `${source.layer}s`;
|
|
1015
|
-
const expected = `${conventions.spartaFolder}/${source.areaFolder}/${folder}`;
|
|
1016
|
-
context.report({
|
|
1017
|
-
node,
|
|
1018
|
-
messageId: "placement",
|
|
1019
|
-
data: { expected }
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
1037
|
},
|
|
1023
1038
|
ImportDeclaration: (node) => check(node, stringValue(node.source)),
|
|
1024
1039
|
ExportNamedDeclaration: (node) => check(node, stringValue(node.source), true),
|
|
@@ -1106,8 +1121,7 @@ const rule$11 = {
|
|
|
1106
1121
|
const filename = context.filename;
|
|
1107
1122
|
const conventions = conventionsFor(context);
|
|
1108
1123
|
const root = rootFor(context, conventions);
|
|
1109
|
-
|
|
1110
|
-
if (source?.kind !== "area-layer" || source.layer !== "director" || moduleName(filename) === "index") return {};
|
|
1124
|
+
if (classify(filename, conventions, root)?.layer !== "director" || moduleName(filename) === "index") return {};
|
|
1111
1125
|
const isBuilder = (request) => {
|
|
1112
1126
|
if (request === void 0) return false;
|
|
1113
1127
|
const resolved = resolveImport(filename, request, root, conventions);
|
|
@@ -2485,4 +2499,4 @@ Object.defineProperty(exports, "rules", {
|
|
|
2485
2499
|
}
|
|
2486
2500
|
});
|
|
2487
2501
|
|
|
2488
|
-
//# sourceMappingURL=rules-
|
|
2502
|
+
//# sourceMappingURL=rules-5VZcw4ds.cjs.map
|