@noctcore/eslint-plugin-architecture 0.2.0 → 0.3.0

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 CHANGED
@@ -55,3 +55,4 @@ ESLint against real file paths, not virtual sources.
55
55
  | [`index-must-reexport-default`](./docs/rules/index-must-reexport-default.md) | A component folder's `index.ts` must re-export the sibling default named after the folder. | |
56
56
  | [`max-import-depth`](./docs/rules/max-import-depth.md) | A relative import may not climb more than `max` parent levels (default 3); autofixed to a path alias when one is configured. | 🔧 |
57
57
  | [`no-cross-feature-imports`](./docs/rules/no-cross-feature-imports.md) | A file in one feature may not import runtime code from another feature. | |
58
+ | [`single-semantic-module`](./docs/rules/single-semantic-module.md) | A module exports one semantic concern (types, constants, functions, classes, components, hooks, schemas or enums); private helpers do not count. Off until configured. | |
package/dist/index.cjs CHANGED
@@ -48,7 +48,12 @@ var recommended = {
48
48
  "noctcore-architecture/filename-matches-export": "error",
49
49
  "noctcore-architecture/index-must-reexport-default": "error",
50
50
  "noctcore-architecture/max-import-depth": "error",
51
- "noctcore-architecture/no-cross-feature-imports": "error"
51
+ "noctcore-architecture/no-cross-feature-imports": "error",
52
+ // Ships OFF: which files it governs and which category mixes they may keep
53
+ // (a NestJS `.constants.ts` legitimately holds constants, types and enums) is
54
+ // a per-codebase decision best made from measured counts. Enable it with
55
+ // 'noctcore-architecture/single-semantic-module': ['error', { allow: [['constant', 'type', 'enum']] }]
56
+ "noctcore-architecture/single-semantic-module": "off"
52
57
  };
53
58
 
54
59
  // src/rules/barrel-purity.ts
@@ -794,6 +799,578 @@ var noCrossFeatureImportsRule = createRule({
794
799
  }
795
800
  });
796
801
 
802
+ // src/semantic-module/classify.ts
803
+ var import_utils15 = require("@typescript-eslint/utils");
804
+
805
+ // src/semantic-module/ast.ts
806
+ var import_utils13 = require("@typescript-eslint/utils");
807
+ function getDeclarationName(node) {
808
+ if ("id" in node) {
809
+ const id = node.id;
810
+ if (isIdentifier(id)) {
811
+ return id.name;
812
+ }
813
+ }
814
+ return void 0;
815
+ }
816
+ function getVariableDeclaratorName(declarator) {
817
+ return declarator.id.type === import_utils13.AST_NODE_TYPES.Identifier ? declarator.id.name : void 0;
818
+ }
819
+ function isWrapperExpression(expression) {
820
+ return expression.type === import_utils13.AST_NODE_TYPES.TSAsExpression || expression.type === import_utils13.AST_NODE_TYPES.TSTypeAssertion || expression.type === import_utils13.AST_NODE_TYPES.TSNonNullExpression || expression.type === import_utils13.AST_NODE_TYPES.TSSatisfiesExpression || expression.type === import_utils13.AST_NODE_TYPES.TSInstantiationExpression;
821
+ }
822
+ function unwrapExpression(expression) {
823
+ let current = expression;
824
+ while (isWrapperExpression(current)) {
825
+ current = current.expression;
826
+ }
827
+ return current;
828
+ }
829
+ function isAmbientDeclaration(node) {
830
+ if ("declare" in node && node.declare === true) {
831
+ return true;
832
+ }
833
+ return node.type === import_utils13.AST_NODE_TYPES.TSModuleDeclaration && node.kind === "global";
834
+ }
835
+ function functionReturnsJsx(node) {
836
+ if (node.type === import_utils13.AST_NODE_TYPES.ArrowFunctionExpression) {
837
+ if (!node.expression && node.body.type === import_utils13.AST_NODE_TYPES.BlockStatement) {
838
+ return blockReturnsJsx(node.body);
839
+ }
840
+ return containsJsx(node.body);
841
+ }
842
+ return blockReturnsJsx(node.body);
843
+ }
844
+ function blockReturnsJsx(block) {
845
+ return containsNode(block, (node) => {
846
+ if (node.type !== import_utils13.AST_NODE_TYPES.ReturnStatement || !node.argument) {
847
+ return false;
848
+ }
849
+ return containsJsx(node.argument);
850
+ });
851
+ }
852
+ function containsJsx(node) {
853
+ return containsNode(
854
+ node,
855
+ (candidate) => candidate.type === import_utils13.AST_NODE_TYPES.JSXElement || candidate.type === import_utils13.AST_NODE_TYPES.JSXFragment
856
+ );
857
+ }
858
+ var SKIPPED_KEYS = /* @__PURE__ */ new Set(["parent", "loc", "range", "tokens", "comments"]);
859
+ function containsNode(root, predicate) {
860
+ const stack = [root];
861
+ while (stack.length > 0) {
862
+ const current = stack.pop();
863
+ if (!current) {
864
+ continue;
865
+ }
866
+ if (predicate(current)) {
867
+ return true;
868
+ }
869
+ for (const [key, value] of Object.entries(current)) {
870
+ if (SKIPPED_KEYS.has(key)) {
871
+ continue;
872
+ }
873
+ if (Array.isArray(value)) {
874
+ for (const item of value) {
875
+ if (isNodeLike(item)) {
876
+ stack.push(item);
877
+ }
878
+ }
879
+ continue;
880
+ }
881
+ if (isNodeLike(value)) {
882
+ stack.push(value);
883
+ }
884
+ }
885
+ }
886
+ return false;
887
+ }
888
+ function isNodeLike(value) {
889
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
890
+ }
891
+ function isIdentifier(value) {
892
+ return isNodeLike(value) && value.type === import_utils13.AST_NODE_TYPES.Identifier;
893
+ }
894
+
895
+ // src/semantic-module/classifiers.ts
896
+ var import_utils14 = require("@typescript-eslint/utils");
897
+ function isHookName(name, options) {
898
+ if (!options.hookDetection.enabled || !name) {
899
+ return false;
900
+ }
901
+ return options.hookDetection.namePattern.test(name);
902
+ }
903
+ function isReactComponentName(name) {
904
+ return Boolean(name && /^[A-Z][A-Za-z0-9]*$/u.test(name));
905
+ }
906
+ function isReactComponentFunction(node, name, options, isDefaultExport = false) {
907
+ if (!options.reactComponentDetection.enabled) {
908
+ return false;
909
+ }
910
+ if (!isReactComponentName(name) && !isDefaultExport) {
911
+ return false;
912
+ }
913
+ if (node.returnType && typeReferencesJsxValue(node.returnType.typeAnnotation)) {
914
+ return true;
915
+ }
916
+ return functionReturnsJsx(node);
917
+ }
918
+ function isReactComponentVariable(declarator, options) {
919
+ if (!options.reactComponentDetection.enabled) {
920
+ return false;
921
+ }
922
+ const name = getVariableDeclaratorName(declarator);
923
+ if (!isReactComponentName(name)) {
924
+ return false;
925
+ }
926
+ if (declarator.id.type === import_utils14.AST_NODE_TYPES.Identifier && declarator.id.typeAnnotation && typeReferencesReactComponent(declarator.id.typeAnnotation.typeAnnotation)) {
927
+ return true;
928
+ }
929
+ if (!declarator.init) {
930
+ return false;
931
+ }
932
+ if (declarator.init.type === import_utils14.AST_NODE_TYPES.ArrowFunctionExpression || declarator.init.type === import_utils14.AST_NODE_TYPES.FunctionExpression) {
933
+ return isReactComponentFunction(declarator.init, name, options);
934
+ }
935
+ return containsJsx(declarator.init);
936
+ }
937
+ var REACT_COMPONENT_TYPES = /* @__PURE__ */ new Set([
938
+ "FC",
939
+ "FunctionComponent",
940
+ "React.FC",
941
+ "React.FunctionComponent"
942
+ ]);
943
+ var JSX_VALUE_TYPES = /* @__PURE__ */ new Set([
944
+ "JSX.Element",
945
+ "React.ReactElement",
946
+ "React.ReactNode"
947
+ ]);
948
+ function typeReferencesReactComponent(node) {
949
+ return containsNode(
950
+ node,
951
+ (candidate) => candidate.type === import_utils14.AST_NODE_TYPES.TSTypeReference && REACT_COMPONENT_TYPES.has(entityNameToString(candidate.typeName))
952
+ );
953
+ }
954
+ function typeReferencesJsxValue(node) {
955
+ return containsNode(
956
+ node,
957
+ (candidate) => candidate.type === import_utils14.AST_NODE_TYPES.TSTypeReference && JSX_VALUE_TYPES.has(entityNameToString(candidate.typeName))
958
+ );
959
+ }
960
+ function entityNameToString(entityName) {
961
+ if (entityName.type === import_utils14.AST_NODE_TYPES.Identifier) {
962
+ return entityName.name;
963
+ }
964
+ if (entityName.type === import_utils14.AST_NODE_TYPES.TSQualifiedName) {
965
+ return `${entityNameToString(entityName.left)}.${entityName.right.name}`;
966
+ }
967
+ return "this";
968
+ }
969
+ var SCHEMA_LIBRARY_MODULES = {
970
+ zod: ["zod"],
971
+ yup: ["yup"],
972
+ valibot: ["valibot"]
973
+ };
974
+ var SCHEMA_BUILDER_NAMES = /* @__PURE__ */ new Set([
975
+ "array",
976
+ "boolean",
977
+ "date",
978
+ "enum",
979
+ "literal",
980
+ "number",
981
+ "object",
982
+ "record",
983
+ "string",
984
+ "tuple",
985
+ "union"
986
+ ]);
987
+ function collectSchemaImportContext(program, options) {
988
+ const namespaceIdentifiers = /* @__PURE__ */ new Set();
989
+ const builderIdentifiers = /* @__PURE__ */ new Set();
990
+ const enabledModules = new Set(
991
+ options.schemaLibraries.flatMap((library) => SCHEMA_LIBRARY_MODULES[library])
992
+ );
993
+ for (const statement of program.body) {
994
+ if (statement.type !== import_utils14.AST_NODE_TYPES.ImportDeclaration || statement.importKind === "type" || !enabledModules.has(String(statement.source.value))) {
995
+ continue;
996
+ }
997
+ for (const specifier of statement.specifiers) {
998
+ if (specifier.type === import_utils14.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils14.AST_NODE_TYPES.ImportDefaultSpecifier) {
999
+ namespaceIdentifiers.add(specifier.local.name);
1000
+ continue;
1001
+ }
1002
+ if (specifier.importKind === "type") {
1003
+ continue;
1004
+ }
1005
+ const importedName = specifier.imported.type === import_utils14.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
1006
+ if (importedName === "z") {
1007
+ namespaceIdentifiers.add(specifier.local.name);
1008
+ }
1009
+ if (SCHEMA_BUILDER_NAMES.has(importedName)) {
1010
+ builderIdentifiers.add(specifier.local.name);
1011
+ }
1012
+ }
1013
+ }
1014
+ return { namespaceIdentifiers, builderIdentifiers };
1015
+ }
1016
+ function isSchemaExpression(expression, context) {
1017
+ const unwrapped = unwrapExpression(expression);
1018
+ if (unwrapped.type !== import_utils14.AST_NODE_TYPES.CallExpression) {
1019
+ return false;
1020
+ }
1021
+ const rootName = expressionRootIdentifier(unwrapped.callee);
1022
+ if (!rootName) {
1023
+ return false;
1024
+ }
1025
+ return context.namespaceIdentifiers.has(rootName) || context.builderIdentifiers.has(rootName);
1026
+ }
1027
+ function expressionRootIdentifier(node) {
1028
+ switch (node.type) {
1029
+ case import_utils14.AST_NODE_TYPES.Identifier:
1030
+ return node.name;
1031
+ case import_utils14.AST_NODE_TYPES.MemberExpression:
1032
+ return expressionRootIdentifier(node.object);
1033
+ case import_utils14.AST_NODE_TYPES.CallExpression:
1034
+ return expressionRootIdentifier(node.callee);
1035
+ case import_utils14.AST_NODE_TYPES.ChainExpression:
1036
+ return expressionRootIdentifier(node.expression);
1037
+ default:
1038
+ return null;
1039
+ }
1040
+ }
1041
+ function getConstantReason(expression) {
1042
+ if (!expression) {
1043
+ return "top-level variable declaration without initializer";
1044
+ }
1045
+ switch (unwrapExpression(expression).type) {
1046
+ case import_utils14.AST_NODE_TYPES.Literal:
1047
+ return "literal runtime value";
1048
+ case import_utils14.AST_NODE_TYPES.ObjectExpression:
1049
+ return "object literal runtime value";
1050
+ case import_utils14.AST_NODE_TYPES.ArrayExpression:
1051
+ return "array literal runtime value";
1052
+ case import_utils14.AST_NODE_TYPES.TemplateLiteral:
1053
+ return "template literal runtime value";
1054
+ case import_utils14.AST_NODE_TYPES.CallExpression:
1055
+ return "computed top-level runtime value";
1056
+ default:
1057
+ return "top-level runtime value";
1058
+ }
1059
+ }
1060
+
1061
+ // src/semantic-module/options.ts
1062
+ var SEMANTIC_CATEGORIES = [
1063
+ "type",
1064
+ "constant",
1065
+ "function",
1066
+ "class",
1067
+ "react-component",
1068
+ "hook",
1069
+ "schema",
1070
+ "enum"
1071
+ ];
1072
+ var SCHEMA_LIBRARIES = ["zod", "yup", "valibot"];
1073
+ function sortCategories(categories) {
1074
+ const categorySet = new Set(categories);
1075
+ return SEMANTIC_CATEGORIES.filter((category) => categorySet.has(category));
1076
+ }
1077
+ var DEFAULT_HOOK_NAME_PATTERN = "^use[A-Z0-9].*";
1078
+ var DEFAULT_OPTIONS = {
1079
+ allow: [],
1080
+ enumCategory: "enum",
1081
+ debug: false,
1082
+ ignoreAmbientDeclarations: false,
1083
+ ignorePrivateDeclarations: true,
1084
+ schemaLibraries: SCHEMA_LIBRARIES,
1085
+ reactComponentDetection: { enabled: true },
1086
+ hookDetection: { enabled: true, namePattern: DEFAULT_HOOK_NAME_PATTERN }
1087
+ };
1088
+ function normalizeOptions(options) {
1089
+ return {
1090
+ allow: options.allow ?? DEFAULT_OPTIONS.allow,
1091
+ enumCategory: options.enumCategory ?? DEFAULT_OPTIONS.enumCategory,
1092
+ debug: options.debug ?? DEFAULT_OPTIONS.debug,
1093
+ ignoreAmbientDeclarations: options.ignoreAmbientDeclarations ?? DEFAULT_OPTIONS.ignoreAmbientDeclarations,
1094
+ ignorePrivateDeclarations: options.ignorePrivateDeclarations ?? DEFAULT_OPTIONS.ignorePrivateDeclarations,
1095
+ schemaLibraries: options.schemaLibraries ?? DEFAULT_OPTIONS.schemaLibraries,
1096
+ reactComponentDetection: { enabled: options.reactComponentDetection?.enabled ?? true },
1097
+ hookDetection: {
1098
+ enabled: options.hookDetection?.enabled ?? true,
1099
+ namePattern: compilePattern(options.hookDetection?.namePattern ?? DEFAULT_HOOK_NAME_PATTERN)
1100
+ }
1101
+ };
1102
+ }
1103
+ function compilePattern(pattern) {
1104
+ try {
1105
+ return new RegExp(pattern);
1106
+ } catch (error) {
1107
+ throw new Error(
1108
+ `single-semantic-module: hookDetection.namePattern ${JSON.stringify(pattern)} is not a valid regular expression (${String(error)}).`
1109
+ );
1110
+ }
1111
+ }
1112
+ function isCategorySetAllowed(categories, allow) {
1113
+ if (categories.size <= 1) {
1114
+ return true;
1115
+ }
1116
+ const detected = [...categories];
1117
+ return allow.some((group) => {
1118
+ const allowed = new Set(group);
1119
+ return detected.every((category) => allowed.has(category));
1120
+ });
1121
+ }
1122
+
1123
+ // src/semantic-module/classify.ts
1124
+ function analyzeSemanticModule(program, rawOptions) {
1125
+ const options = normalizeOptions(rawOptions);
1126
+ const context = {
1127
+ options,
1128
+ schemaImports: collectSchemaImportContext(program, options),
1129
+ exportedNames: collectLocallyExportedNames(program)
1130
+ };
1131
+ const classifications = program.body.flatMap(
1132
+ (statement) => classifyTopLevelStatement(statement, context)
1133
+ );
1134
+ return {
1135
+ categories: new Set(classifications.map((classification2) => classification2.category)),
1136
+ classifications,
1137
+ options
1138
+ };
1139
+ }
1140
+ function collectLocallyExportedNames(program) {
1141
+ const names = /* @__PURE__ */ new Set();
1142
+ for (const statement of program.body) {
1143
+ if (statement.type === import_utils15.AST_NODE_TYPES.ExportNamedDeclaration && statement.source === null && statement.declaration === null) {
1144
+ for (const specifier of statement.specifiers) {
1145
+ if (specifier.local.type === import_utils15.AST_NODE_TYPES.Identifier) {
1146
+ names.add(specifier.local.name);
1147
+ }
1148
+ }
1149
+ } else if (statement.type === import_utils15.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils15.AST_NODE_TYPES.Identifier) {
1150
+ names.add(statement.declaration.name);
1151
+ }
1152
+ }
1153
+ return names;
1154
+ }
1155
+ function classifyTopLevelStatement(statement, context) {
1156
+ switch (statement.type) {
1157
+ case import_utils15.AST_NODE_TYPES.ImportDeclaration:
1158
+ case import_utils15.AST_NODE_TYPES.EmptyStatement:
1159
+ case import_utils15.AST_NODE_TYPES.ExportAllDeclaration:
1160
+ return [];
1161
+ case import_utils15.AST_NODE_TYPES.ExportNamedDeclaration:
1162
+ return statement.declaration ? classifyDeclarationLike(statement.declaration, context) : [];
1163
+ case import_utils15.AST_NODE_TYPES.ExportDefaultDeclaration:
1164
+ return classifyDeclarationLike(statement.declaration, { ...context, isDefaultExport: true });
1165
+ default:
1166
+ if (!context.options.ignorePrivateDeclarations) {
1167
+ return classifyDeclarationLike(statement, context);
1168
+ }
1169
+ return classifyExportedByName(statement, context);
1170
+ }
1171
+ }
1172
+ function classifyExportedByName(statement, context) {
1173
+ if (context.exportedNames.size === 0) {
1174
+ return [];
1175
+ }
1176
+ if (statement.type === import_utils15.AST_NODE_TYPES.VariableDeclaration) {
1177
+ const exported = statement.declarations.filter((declarator) => {
1178
+ const name2 = getVariableDeclaratorName(declarator);
1179
+ return name2 !== void 0 && context.exportedNames.has(name2);
1180
+ });
1181
+ return exported.map((declarator) => classifyVariableDeclarator(declarator, context));
1182
+ }
1183
+ const name = getDeclarationName(statement);
1184
+ return name !== void 0 && context.exportedNames.has(name) ? classifyDeclarationLike(statement, context) : [];
1185
+ }
1186
+ function classifyDeclarationLike(node, context) {
1187
+ if (isAmbientDeclaration(node)) {
1188
+ return context.options.ignoreAmbientDeclarations ? [] : [classification("type", node, getDeclarationName(node), "ambient declaration")];
1189
+ }
1190
+ switch (node.type) {
1191
+ case import_utils15.AST_NODE_TYPES.TSInterfaceDeclaration:
1192
+ case import_utils15.AST_NODE_TYPES.TSTypeAliasDeclaration:
1193
+ case import_utils15.AST_NODE_TYPES.TSModuleDeclaration:
1194
+ return [
1195
+ classification("type", node, getDeclarationName(node), "TypeScript type-space declaration")
1196
+ ];
1197
+ case import_utils15.AST_NODE_TYPES.TSEnumDeclaration:
1198
+ return [
1199
+ classification(
1200
+ context.options.enumCategory,
1201
+ node,
1202
+ getDeclarationName(node),
1203
+ context.options.enumCategory === "type" ? "enum configured as type" : "enum declaration"
1204
+ )
1205
+ ];
1206
+ case import_utils15.AST_NODE_TYPES.ClassDeclaration:
1207
+ return [classification("class", node, getDeclarationName(node), "class declaration")];
1208
+ case import_utils15.AST_NODE_TYPES.FunctionDeclaration:
1209
+ return [classifyFunction(node, getDeclarationName(node), context, "function declaration")];
1210
+ case import_utils15.AST_NODE_TYPES.VariableDeclaration:
1211
+ return node.declarations.map((declarator) => classifyVariableDeclarator(declarator, context));
1212
+ case import_utils15.AST_NODE_TYPES.ArrowFunctionExpression:
1213
+ case import_utils15.AST_NODE_TYPES.FunctionExpression:
1214
+ return [classifyFunction(node, void 0, context, "function expression")];
1215
+ case import_utils15.AST_NODE_TYPES.ClassExpression:
1216
+ return [classification("class", node, getDeclarationName(node), "class expression")];
1217
+ case import_utils15.AST_NODE_TYPES.CallExpression:
1218
+ case import_utils15.AST_NODE_TYPES.ArrayExpression:
1219
+ case import_utils15.AST_NODE_TYPES.ObjectExpression:
1220
+ case import_utils15.AST_NODE_TYPES.Literal:
1221
+ case import_utils15.AST_NODE_TYPES.TemplateLiteral:
1222
+ return [classifyDefaultExpression(node, context)];
1223
+ case import_utils15.AST_NODE_TYPES.TSDeclareFunction:
1224
+ return [
1225
+ classification("function", node, getDeclarationName(node), "function overload signature")
1226
+ ];
1227
+ default:
1228
+ return [];
1229
+ }
1230
+ }
1231
+ function classifyFunction(node, name, context, reason) {
1232
+ if (isHookName(name, context.options)) {
1233
+ return classification("hook", node, name, "function name matches hook pattern");
1234
+ }
1235
+ if (isReactComponentFunction(node, name, context.options, context.isDefaultExport === true)) {
1236
+ return classification(
1237
+ "react-component",
1238
+ node,
1239
+ name,
1240
+ `${reason === "function declaration" ? "function component" : "function expression"} returns JSX or React element`
1241
+ );
1242
+ }
1243
+ return classification("function", node, name, reason);
1244
+ }
1245
+ function classifyVariableDeclarator(declarator, context) {
1246
+ const name = getVariableDeclaratorName(declarator);
1247
+ const init = declarator.init ? unwrapExpression(declarator.init) : null;
1248
+ if (init && isSchemaExpression(init, context.schemaImports)) {
1249
+ return classification("schema", declarator, name, "schema builder expression");
1250
+ }
1251
+ if (isReactComponentVariable(declarator, context.options)) {
1252
+ return classification("react-component", declarator, name, "React component variable");
1253
+ }
1254
+ if (isHookName(name, context.options)) {
1255
+ return classification("hook", declarator, name, "variable name matches hook pattern");
1256
+ }
1257
+ if (init?.type === import_utils15.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils15.AST_NODE_TYPES.FunctionExpression) {
1258
+ return classifyFunction(init, name, context, "function expression");
1259
+ }
1260
+ if (init?.type === import_utils15.AST_NODE_TYPES.ClassExpression) {
1261
+ return classification("class", declarator, name, "class expression");
1262
+ }
1263
+ return classification("constant", declarator, name, getConstantReason(init));
1264
+ }
1265
+ function classifyDefaultExpression(expression, context) {
1266
+ const unwrapped = unwrapExpression(expression);
1267
+ if (isSchemaExpression(unwrapped, context.schemaImports)) {
1268
+ return classification("schema", expression, void 0, "default schema expression");
1269
+ }
1270
+ if (unwrapped.type === import_utils15.AST_NODE_TYPES.ArrowFunctionExpression || unwrapped.type === import_utils15.AST_NODE_TYPES.FunctionExpression) {
1271
+ return classifyFunction(unwrapped, void 0, context, "function expression");
1272
+ }
1273
+ if (unwrapped.type === import_utils15.AST_NODE_TYPES.ClassExpression) {
1274
+ return classification("class", expression, void 0, "default class expression");
1275
+ }
1276
+ return classification("constant", expression, void 0, getConstantReason(unwrapped));
1277
+ }
1278
+ function classification(category, node, declarationName, reason) {
1279
+ return declarationName ? { category, node, reason, declarationName } : { category, node, reason };
1280
+ }
1281
+ function buildMixedCategoriesMessage(classifications, debug) {
1282
+ const categories = sortCategories(classifications.map((entry) => entry.category));
1283
+ const lines = [
1284
+ "Mixed semantic categories detected in module:",
1285
+ ...categories.map((category) => `- ${category}`)
1286
+ ];
1287
+ if (debug) {
1288
+ lines.push("", "Detected declarations:");
1289
+ for (const entry of classifications) {
1290
+ lines.push(`- ${entry.category}: ${entry.declarationName ?? "<anonymous>"} (${entry.reason})`);
1291
+ }
1292
+ }
1293
+ lines.push(
1294
+ "",
1295
+ "A module must contain only one semantic concern.",
1296
+ "Move declarations into separate files/modules."
1297
+ );
1298
+ return lines.join("\n");
1299
+ }
1300
+
1301
+ // src/rules/single-semantic-module.ts
1302
+ var RULE_NAME8 = "single-semantic-module";
1303
+ var optionSchema8 = {
1304
+ type: "object",
1305
+ additionalProperties: false,
1306
+ properties: {
1307
+ allow: {
1308
+ type: "array",
1309
+ items: {
1310
+ type: "array",
1311
+ minItems: 2,
1312
+ uniqueItems: true,
1313
+ items: { type: "string", enum: [...SEMANTIC_CATEGORIES] }
1314
+ }
1315
+ },
1316
+ enumCategory: { type: "string", enum: ["enum", "type"] },
1317
+ debug: { type: "boolean" },
1318
+ ignoreAmbientDeclarations: { type: "boolean" },
1319
+ ignorePrivateDeclarations: { type: "boolean" },
1320
+ schemaLibraries: {
1321
+ type: "array",
1322
+ uniqueItems: true,
1323
+ items: { type: "string", enum: [...SCHEMA_LIBRARIES] }
1324
+ },
1325
+ reactComponentDetection: {
1326
+ type: "object",
1327
+ additionalProperties: false,
1328
+ properties: { enabled: { type: "boolean" } }
1329
+ },
1330
+ hookDetection: {
1331
+ type: "object",
1332
+ additionalProperties: false,
1333
+ properties: {
1334
+ enabled: { type: "boolean" },
1335
+ namePattern: { type: "string" }
1336
+ }
1337
+ }
1338
+ }
1339
+ };
1340
+ var singleSemanticModuleRule = createRule({
1341
+ name: RULE_NAME8,
1342
+ meta: {
1343
+ type: "suggestion",
1344
+ docs: {
1345
+ description: "Require each module to export only one semantic concern (types, constants, functions, classes, components, hooks, schemas or enums)."
1346
+ },
1347
+ schema: [optionSchema8],
1348
+ messages: {
1349
+ mixedSemanticCategories: "{{message}}"
1350
+ }
1351
+ },
1352
+ defaultOptions: [DEFAULT_OPTIONS],
1353
+ create(context, [options]) {
1354
+ return {
1355
+ Program(program) {
1356
+ const analysis = analyzeSemanticModule(program, options);
1357
+ if (isCategorySetAllowed(analysis.categories, analysis.options.allow)) {
1358
+ return;
1359
+ }
1360
+ const [first] = analysis.classifications;
1361
+ const reportNode = analysis.classifications.find((entry) => entry.category !== first?.category)?.node ?? program;
1362
+ context.report({
1363
+ node: reportNode,
1364
+ messageId: "mixedSemanticCategories",
1365
+ data: {
1366
+ message: buildMixedCategoriesMessage(analysis.classifications, analysis.options.debug)
1367
+ }
1368
+ });
1369
+ }
1370
+ };
1371
+ }
1372
+ });
1373
+
797
1374
  // src/rules/index.ts
798
1375
  var rules = {
799
1376
  "barrel-purity": barrelPurityRule,
@@ -802,12 +1379,13 @@ var rules = {
802
1379
  "filename-matches-export": filenameMatchesExportRule,
803
1380
  "index-must-reexport-default": indexMustReexportDefaultRule,
804
1381
  "max-import-depth": maxImportDepthRule,
805
- "no-cross-feature-imports": noCrossFeatureImportsRule
1382
+ "no-cross-feature-imports": noCrossFeatureImportsRule,
1383
+ "single-semantic-module": singleSemanticModuleRule
806
1384
  };
807
1385
 
808
1386
  // src/index.ts
809
1387
  var NAMESPACE = "noctcore-architecture";
810
- var VERSION = "0.2.0";
1388
+ var VERSION = "0.3.0";
811
1389
  var plugin = {
812
1390
  meta: { name: "@noctcore/eslint-plugin-architecture", version: VERSION },
813
1391
  rules,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,34 @@
1
1
  import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
2
 
3
+ declare const SEMANTIC_CATEGORIES: readonly ["type", "constant", "function", "class", "react-component", "hook", "schema", "enum"];
4
+ type SemanticCategory = (typeof SEMANTIC_CATEGORIES)[number];
5
+ type EnumCategory = Extract<SemanticCategory, 'enum' | 'type'>;
6
+ type SchemaLibrary = 'zod' | 'yup' | 'valibot';
7
+ interface SingleSemanticModuleOptions {
8
+ /** Category sets a module may mix, e.g. `[['constant', 'type', 'enum']]`. */
9
+ readonly allow?: readonly (readonly SemanticCategory[])[];
10
+ /** Whether a TS `enum` is its own category or counts as `type`. */
11
+ readonly enumCategory?: EnumCategory;
12
+ /** List every classified declaration and why in the report. */
13
+ readonly debug?: boolean;
14
+ /** Skip `declare ...` and `declare global` blocks entirely. */
15
+ readonly ignoreAmbientDeclarations?: boolean;
16
+ /**
17
+ * Only the exported surface defines a module's semantics: a non-exported
18
+ * render helper, config object or class serves that surface and is not
19
+ * classified. Default true.
20
+ */
21
+ readonly ignorePrivateDeclarations?: boolean;
22
+ readonly schemaLibraries?: readonly SchemaLibrary[];
23
+ readonly reactComponentDetection?: {
24
+ readonly enabled?: boolean;
25
+ };
26
+ readonly hookDetection?: {
27
+ readonly enabled?: boolean;
28
+ readonly namePattern?: string;
29
+ };
30
+ }
31
+
3
32
  interface NoCrossFeatureImportsOptions {
4
33
  readonly featureRoot?: string;
5
34
  readonly alias?: string;
@@ -58,6 +87,9 @@ declare const rules: {
58
87
  'no-cross-feature-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"crossFeatureImport", [NoCrossFeatureImportsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
59
88
  name: string;
60
89
  };
90
+ 'single-semantic-module': _typescript_eslint_utils_ts_eslint.RuleModule<"mixedSemanticCategories", [SingleSemanticModuleOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
91
+ name: string;
92
+ };
61
93
  };
62
94
 
63
95
  declare const plugin: {
@@ -87,6 +119,9 @@ declare const plugin: {
87
119
  'no-cross-feature-imports': _typescript_eslint_utils_ts_eslint.RuleModule<"crossFeatureImport", [NoCrossFeatureImportsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
88
120
  name: string;
89
121
  };
122
+ 'single-semantic-module': _typescript_eslint_utils_ts_eslint.RuleModule<"mixedSemanticCategories", [SingleSemanticModuleOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
123
+ name: string;
124
+ };
90
125
  };
91
126
  configs: Record<string, unknown>;
92
127
  };