@cerios/sparta-lint-rules 0.0.1 → 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.
@@ -1,3 +1,4 @@
1
+
1
2
  // \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -22,17 +23,57 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
23
  let node_path = require("node:path");
23
24
  node_path = __toESM(node_path);
24
25
  let node_fs = require("node:fs");
26
+ let node_module = require("node:module");
25
27
  let oxc_parser = require("oxc-parser");
26
28
  // src/utils/ast.ts
27
29
  const isIdentifier = (node, name) => node?.type === "Identifier" && node.name === name;
28
30
  /** The value of a string literal node, or `undefined` for any other node. */
29
31
  const stringValue = (node) => node?.type === "Literal" && typeof node.value === "string" ? node.value : void 0;
32
+ /** The value of a string literal or a template literal without expressions (`\`./x\``), or `undefined`. */
33
+ const staticString = (node) => node?.type === "TemplateLiteral" && node.expressions.length === 0 ? node.quasis[0]?.value.cooked ?? void 0 : stringValue(node);
30
34
  /** True for `@step` and `@step("...")` decorators, or any of the given decorator `names`. */
31
35
  const isStepDecorator = (decorator, names) => {
32
36
  const { expression } = decorator;
33
37
  const callee = expression.type === "CallExpression" ? expression.callee : expression;
34
38
  return callee.type === "Identifier" && names.has(callee.name);
35
39
  };
40
+ // src/utils/class-members.ts
41
+ const isMethod = (member) => member.type === "MethodDefinition" || member.type === "TSAbstractMethodDefinition";
42
+ const FUNCTION_VALUES$1 = /* @__PURE__ */ new Set([
43
+ "ArrowFunctionExpression",
44
+ "FunctionExpression",
45
+ "ClassExpression"
46
+ ]);
47
+ /**
48
+ * A plain property declaration (`static readonly PATTERN = /.../;`, `private readonly date: Date;`, …).
49
+ * A property holding a function or class is not plain: it is treated like a method.
50
+ */
51
+ const isPlainProperty = (member) => {
52
+ if (member.type === "TSIndexSignature") return true;
53
+ if (member.type !== "PropertyDefinition" && member.type !== "TSAbstractPropertyDefinition" && member.type !== "AccessorProperty") return false;
54
+ return member.value === null || !FUNCTION_VALUES$1.has(member.value.type);
55
+ };
56
+ /** `private` or an ECMAScript `#private` name. */
57
+ const isPrivate = (member) => "accessibility" in member && member.accessibility === "private" || "key" in member && member.key.type === "PrivateIdentifier";
58
+ const memberName$1 = (member) => {
59
+ const key = "key" in member ? member.key : void 0;
60
+ if (key && "name" in key && typeof key.name === "string") return key.name;
61
+ if (key && "value" in key && typeof key.value === "string") return key.value;
62
+ return "<computed>";
63
+ };
64
+ /** A member that belongs to the class itself: `static` members, static blocks and a `private constructor`. */
65
+ const isStaticMember = (member) => member.type === "StaticBlock" || "static" in member && member.static || member.type === "MethodDefinition" && member.kind === "constructor" && member.accessibility === "private";
66
+ /** A static abstract class: `abstract`, with only static members, so it is used without ever being instantiated. */
67
+ const isStaticClass = (node) => node.abstract === true && node.body.body.every(isStaticMember);
68
+ /** The classes declared at the top level of a program, including exported ones. */
69
+ function topLevelClasses(program) {
70
+ const classes = [];
71
+ for (const statement of program.body) {
72
+ const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" ? statement.declaration : statement;
73
+ if (declaration?.type === "ClassDeclaration") classes.push(declaration);
74
+ }
75
+ return classes;
76
+ }
36
77
  // src/utils/docs.ts
37
78
  const REPOSITORY = "https://github.com/CeriosTesting/sparta-lint-rules";
38
79
  const docsUrl = (ruleName) => `${REPOSITORY}/blob/main/docs/rules/${ruleName}.md`;
@@ -85,11 +126,22 @@ const LAYER_FOLDERS = {
85
126
  steppers: {
86
127
  layer: "stepper",
87
128
  suffix: "stepper"
129
+ },
130
+ windows: {
131
+ layer: "window",
132
+ suffix: "window"
88
133
  }
89
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
+ */
140
+ const AREA_LAYER_FOLDERS = /* @__PURE__ */ new Set(["builders", "directors"]);
90
141
  const AREAS = [
91
142
  "api",
92
143
  "database",
144
+ "desktop",
93
145
  "mobile",
94
146
  "ui"
95
147
  ];
@@ -131,9 +183,9 @@ const suggest = (value, candidates) => {
131
183
  })).toSorted((a, b) => a.score - b.score);
132
184
  return best && best.score <= Math.max(2, Math.floor(best.candidate.length / 3)) ? `; did you mean ${JSON.stringify(best.candidate)}?` : "";
133
185
  };
134
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
186
+ const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
135
187
  function record(value, where) {
136
- if (!isRecord(value)) throw new SettingsError(where, `must be an object, got ${JSON.stringify(value)}.`);
188
+ if (!isRecord$1(value)) throw new SettingsError(where, `must be an object, got ${JSON.stringify(value)}.`);
137
189
  return value;
138
190
  }
139
191
  function checkKeys(value, allowed, where) {
@@ -222,14 +274,16 @@ function buildPatterns(spartaFolder, testsFolder, areas) {
222
274
  const sparta = escape(spartaFolder);
223
275
  const tests = escape(testsFolder);
224
276
  const areaNames = [...areas.keys()].map(escape).join("|");
277
+ const end = "(?=/|$)";
225
278
  return {
226
- area: new RegExp(`/${sparta}/(${areaNames})/([^/]+)(?:/([^/]+))?`),
279
+ area: new RegExp(`/${sparta}/(${areaNames})${end}(?:/([^/]+))?(?:/([^/]+))?`),
227
280
  layer: new RegExp(`/${sparta}/(?:${areaNames})/[^/]+/([^/]+)/`),
228
- top: new RegExp(`/${sparta}/(${TOP_LEVEL_FOLDERS.join("|")})/`),
281
+ top: new RegExp(`/${sparta}/(${TOP_LEVEL_FOLDERS.join("|")})${end}`),
282
+ common: new RegExp(`/${sparta}/common/([^/]+)${end}`),
229
283
  checked: new RegExp(`/(?:${sparta}|${tests})/`),
230
284
  sparta: new RegExp(`/${sparta}/`),
231
- tests: new RegExp(`/${tests}/`),
232
- framework: new RegExp(`/${tests}/framework/`)
285
+ tests: new RegExp(`/${tests}${end}`),
286
+ framework: new RegExp(`/${tests}/framework${end}`)
233
287
  };
234
288
  }
235
289
  const STANDARD_LAYER_FOLDERS = Object.keys(LAYER_FOLDERS);
@@ -260,6 +314,196 @@ function parseSettings(raw, cwd) {
260
314
  };
261
315
  }
262
316
  parseSettings(void 0, process.cwd());
317
+ // src/utils/tsconfig.ts
318
+ const normalize$1 = (value) => value.split("\\").join("/");
319
+ const CONFIG_DIR = "${configDir}";
320
+ /** Where the string or comment that starts at `index` ends (exclusive), or `undefined` when none starts there. */
321
+ function skippedEnd(text, index) {
322
+ const start = text.slice(index, index + 2);
323
+ if (text[index] === "\"") {
324
+ let end = index + 1;
325
+ while (end < text.length && text[end] !== "\"") end += text[end] === "\\" ? 2 : 1;
326
+ return end + 1;
327
+ }
328
+ if (start === "//") {
329
+ const end = text.indexOf("\n", index);
330
+ return end === -1 ? text.length : end;
331
+ }
332
+ if (start === "/*") {
333
+ const end = text.indexOf("*/", index + 2);
334
+ return end === -1 ? text.length : end + 2;
335
+ }
336
+ }
337
+ /**
338
+ * Parses JSON with comments and trailing commas, as `tsconfig.json` allows. Comments are only recognised outside
339
+ * strings, so `"https://..."` stays intact.
340
+ */
341
+ function parseJsonc(text) {
342
+ let out = "";
343
+ /** Position in `out` of a comma that may still turn out to be a trailing one. */
344
+ let pendingComma = -1;
345
+ let index = text.charCodeAt(0) === 65279 ? 1 : 0;
346
+ while (index < text.length) {
347
+ const char = text[index];
348
+ const end = skippedEnd(text, index);
349
+ if (end !== void 0) {
350
+ if (char === "\"") {
351
+ out += text.slice(index, end);
352
+ pendingComma = -1;
353
+ }
354
+ index = end;
355
+ continue;
356
+ }
357
+ if (char === ",") pendingComma = out.length;
358
+ else if ((char === "}" || char === "]") && pendingComma !== -1) {
359
+ out = `${out.slice(0, pendingComma)} ${out.slice(pendingComma + 1)}`;
360
+ pendingComma = -1;
361
+ } else if (!/\s/.test(char)) pendingComma = -1;
362
+ out += char;
363
+ index++;
364
+ }
365
+ return JSON.parse(out);
366
+ }
367
+ const isFile$1 = (file) => (0, node_fs.statSync)(file, { throwIfNoEntry: false })?.isFile() ?? false;
368
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
369
+ var TsconfigError = class extends Error {
370
+ constructor(file, message) {
371
+ super(`sparta-lint-rules: cannot read ${normalize$1(file)}: ${message}`);
372
+ this.name = "TsconfigError";
373
+ }
374
+ };
375
+ function readConfig(file) {
376
+ let config;
377
+ try {
378
+ config = parseJsonc((0, node_fs.readFileSync)(file, "utf8"));
379
+ } catch (error) {
380
+ throw new TsconfigError(file, error instanceof Error ? error.message : String(error));
381
+ }
382
+ if (!isRecord(config)) throw new TsconfigError(file, "the config must be a JSON object.");
383
+ return config;
384
+ }
385
+ /** The file an `extends` entry points to: a path relative to the config, or a package such as `@tsconfig/node22`. */
386
+ function resolveExtends(specifier, from) {
387
+ if (specifier.startsWith(".") || node_path.default.isAbsolute(specifier)) {
388
+ const file = node_path.default.resolve(node_path.default.dirname(from), specifier);
389
+ if (isFile$1(file)) return file;
390
+ if (!file.endsWith(".json") && isFile$1(`${file}.json`)) return `${file}.json`;
391
+ } else {
392
+ const require$1 = (0, node_module.createRequire)(from);
393
+ const candidates = specifier.endsWith(".json") ? [specifier] : [`${specifier}/tsconfig.json`, specifier];
394
+ for (const candidate of candidates) try {
395
+ return require$1.resolve(candidate);
396
+ } catch {}
397
+ }
398
+ throw new TsconfigError(from, `extends ${JSON.stringify(specifier)}, which cannot be found.`);
399
+ }
400
+ const substitute = (value, configDir) => value.split(CONFIG_DIR).join(configDir);
401
+ function loadOptions(file, configDir, chain, read) {
402
+ if (chain.includes(file)) throw new TsconfigError(chain[0], `circular extends: ${[...chain, file].map(normalize$1).join(" -> ")}.`);
403
+ const config = readConfig(file);
404
+ const dir = node_path.default.dirname(file);
405
+ const parents = typeof config.extends === "string" ? [config.extends] : config.extends;
406
+ let options = {};
407
+ read.push(file);
408
+ if (Array.isArray(parents)) for (const parent of parents) {
409
+ if (typeof parent !== "string") continue;
410
+ const inherited = loadOptions(resolveExtends(parent, file), configDir, [...chain, file], read);
411
+ options = {
412
+ ...options,
413
+ ...inherited
414
+ };
415
+ }
416
+ const compilerOptions = isRecord(config.compilerOptions) ? config.compilerOptions : {};
417
+ if (typeof compilerOptions.baseUrl === "string") options.baseUrl = node_path.default.resolve(dir, substitute(compilerOptions.baseUrl, configDir));
418
+ if (isRecord(compilerOptions.paths)) options.paths = {
419
+ mapping: compilerOptions.paths,
420
+ base: dir
421
+ };
422
+ return options;
423
+ }
424
+ function toMappings(options, configDir) {
425
+ if (!options.paths) return [];
426
+ const base = options.baseUrl ?? options.paths.base;
427
+ return Object.entries(options.paths.mapping).flatMap(([pattern, value]) => {
428
+ const targets = Array.isArray(value) ? value.filter((target) => typeof target === "string") : [];
429
+ const star = pattern.indexOf("*");
430
+ if (targets.length === 0) return [];
431
+ return [{
432
+ pattern,
433
+ prefix: star === -1 ? pattern : pattern.slice(0, star),
434
+ suffix: star === -1 ? "" : pattern.slice(star + 1),
435
+ wildcard: star !== -1,
436
+ targets: targets.map((target) => normalize$1(node_path.default.resolve(base, substitute(target, configDir))))
437
+ }];
438
+ });
439
+ }
440
+ /** Parsed configs per file, kept for the lifetime of the linter process and refreshed when any file in the chain changes. */
441
+ const configCache = /* @__PURE__ */ new Map();
442
+ const mtime = (file) => (0, node_fs.statSync)(file, { throwIfNoEntry: false })?.mtimeMs;
443
+ /** The `paths` and `baseUrl` of a config file, including what it extends. Throws for unreadable or invalid configs. */
444
+ function loadTsconfig(file) {
445
+ const cached = configCache.get(file);
446
+ if (cached?.read.every((entry) => mtime(entry.file) === entry.mtimeMs)) return cached.value;
447
+ const configDir = node_path.default.dirname(file);
448
+ const read = [];
449
+ const options = loadOptions(file, configDir, [], read);
450
+ const value = {
451
+ file: normalize$1(file),
452
+ baseUrl: options.baseUrl === void 0 ? void 0 : normalize$1(options.baseUrl),
453
+ paths: toMappings(options, configDir)
454
+ };
455
+ configCache.set(file, {
456
+ read: read.map((entry) => ({
457
+ file: entry,
458
+ mtimeMs: mtime(entry) ?? -1
459
+ })),
460
+ value
461
+ });
462
+ return value;
463
+ }
464
+ /** Nearest `tsconfig.json` per directory (`null` for none), kept for the lifetime of the linter process. */
465
+ const lookupCache = /* @__PURE__ */ new Map();
466
+ /** The nearest `tsconfig.json`, from the file's folder upwards, or `undefined` when there is none. */
467
+ function findTsconfig(filename) {
468
+ const visited = [];
469
+ let found;
470
+ for (let dir = node_path.default.dirname(node_path.default.resolve(filename));;) {
471
+ found = lookupCache.get(dir);
472
+ if (found !== void 0) break;
473
+ visited.push(dir);
474
+ const candidate = node_path.default.join(dir, "tsconfig.json");
475
+ if (isFile$1(candidate)) {
476
+ found = candidate;
477
+ break;
478
+ }
479
+ const parent = node_path.default.dirname(dir);
480
+ if (parent === dir) {
481
+ found = null;
482
+ break;
483
+ }
484
+ dir = parent;
485
+ }
486
+ for (const dir of visited) lookupCache.set(dir, found);
487
+ return found ?? void 0;
488
+ }
489
+ /** The `paths` and `baseUrl` that apply to a file, from its nearest `tsconfig.json`. */
490
+ function tsconfigFor(filename) {
491
+ const file = findTsconfig(filename);
492
+ return file === void 0 ? void 0 : loadTsconfig(file);
493
+ }
494
+ /**
495
+ * The candidate paths a `paths` entry maps a request to, as TypeScript picks them: an exact pattern first,
496
+ * otherwise the wildcard pattern with the longest prefix. `undefined` when no pattern matches.
497
+ */
498
+ function matchPaths(request, mappings) {
499
+ const exact = mappings.find((mapping) => !mapping.wildcard && mapping.pattern === request);
500
+ if (exact) return exact.targets;
501
+ let best;
502
+ for (const mapping of mappings) if (mapping.wildcard && request.length >= mapping.prefix.length + mapping.suffix.length && request.startsWith(mapping.prefix) && request.endsWith(mapping.suffix) && (best === void 0 || mapping.prefix.length > best.prefix.length)) best = mapping;
503
+ if (best === void 0) return void 0;
504
+ const matched = request.slice(best.prefix.length, request.length - best.suffix.length);
505
+ return best.targets.map((target) => target.replace("*", matched));
506
+ }
263
507
  // src/utils/sparta-paths.ts
264
508
  const normalize = (value) => value.split("\\").join("/");
265
509
  const TOP_LEVEL_KINDS = {
@@ -268,6 +512,20 @@ const TOP_LEVEL_KINDS = {
268
512
  };
269
513
  /** The standard layer folder that a project's folder name follows, if any. */
270
514
  const standardFolder = (conventions, folder) => folder === void 0 ? void 0 : conventions.layerFolders.get(folder);
515
+ /** The layer of a standard layer folder (`stepper` for `steppers`), if it has one. */
516
+ const layerOf = (standard) => standard === void 0 ? void 0 : LAYER_FOLDERS[standard].layer;
517
+ /** `name` as a builders or directors folder (`AREA_LAYER_FOLDERS`), if it is one. */
518
+ const builderFolder = (conventions, name) => {
519
+ const standard = standardFolder(conventions, name);
520
+ return name !== void 0 && standard !== void 0 && AREA_LAYER_FOLDERS.has(standard) ? {
521
+ name,
522
+ standard
523
+ } : void 0;
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]);
271
529
  const caseInsensitivePaths = process.platform === "win32";
272
530
  /**
273
531
  * The part of `filename` below the project `root`, with a leading `/` (`/sparta/ui/...`), or `undefined` for files
@@ -289,9 +547,15 @@ function classify(filename, conventions, root) {
289
547
  const area = file.match(patterns.area);
290
548
  if (area) {
291
549
  const [, areaName, group, folder] = area;
550
+ const areaLayer = areaLayerFolder(file, conventions);
551
+ if (areaLayer) return {
552
+ kind: "area-layer",
553
+ area: conventions.areas.get(areaName),
554
+ areaFolder: areaName,
555
+ layer: layerOf(areaLayer.standard)
556
+ };
292
557
  const base = file.match(/-base-(client|repository|service)(?:\.[cm]?[jt]s)?$/)?.[1];
293
- const standard = standardFolder(conventions, folder);
294
- const layer = base ? `base-${base}` : standard === void 0 ? void 0 : LAYER_FOLDERS[standard].layer;
558
+ const layer = base ? `base-${base}` : layerOf(standardFolder(conventions, folder));
295
559
  return {
296
560
  kind: group === "common" ? "area-common" : "group",
297
561
  area: conventions.areas.get(areaName),
@@ -301,7 +565,12 @@ function classify(filename, conventions, root) {
301
565
  };
302
566
  }
303
567
  const top = file.match(patterns.top)?.[1];
304
- return top ? { kind: TOP_LEVEL_KINDS[top] ?? "shared" } : void 0;
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" };
305
574
  }
306
575
  /** Project root per directory, kept for the lifetime of the linter process. */
307
576
  const rootCache = /* @__PURE__ */ new Map();
@@ -330,22 +599,60 @@ function projectRoot(filename) {
330
599
  for (const dir of visited) rootCache.set(dir, root);
331
600
  return root;
332
601
  }
602
+ /** The extensions tried, in order, to find the file behind an extension-less import. */
603
+ const MODULE_EXTENSIONS = [
604
+ "",
605
+ ".ts",
606
+ ".tsx",
607
+ ".mts",
608
+ ".cts",
609
+ "/index.ts"
610
+ ];
611
+ const isFile = (file) => (0, node_fs.statSync)(file, { throwIfNoEntry: false })?.isFile() ?? false;
612
+ /** The TypeScript file an import path points to (`./x` -> `./x.ts`, `./x.js` -> `./x.ts`), if it exists. */
613
+ function moduleFile(base) {
614
+ const stripped = base.replace(/\.(?:m|c)?js$/, "");
615
+ for (const candidate of [base, ...MODULE_EXTENSIONS.map((extension) => `${stripped}${extension}`)]) if (isFile(candidate)) return normalize(candidate);
616
+ }
617
+ /** True when an import path points to an existing file or folder. */
618
+ const moduleExists = (base) => ((0, node_fs.statSync)(base, { throwIfNoEntry: false })?.isDirectory() ?? false) || moduleFile(base) !== void 0;
333
619
  /**
334
- * Resolves a relative or aliased import (`@sparta/*`, `@tests/*` and `settings.sparta.aliases`) to an absolute,
335
- * normalized path. Other imports are ignored. Aliases resolve against `root`.
620
+ * Resolves an import to an absolute, normalized path, the way TypeScript would:
621
+ *
622
+ * 1. relative imports, against the importing file;
623
+ * 2. `compilerOptions.paths` of the nearest `tsconfig.json`, taking the first target that exists;
624
+ * 3. the `@sparta/*` and `@tests/*` aliases and `settings.sparta.aliases`, against `root`;
625
+ * 4. the first `paths` target when none exists (yet);
626
+ * 5. `compilerOptions.baseUrl`, only when the file exists, so package imports are not mistaken for project files.
627
+ *
628
+ * Other imports (packages) resolve to `undefined`.
336
629
  */
337
630
  function resolveImport(filename, request, root, conventions) {
338
- for (const [prefix, target] of conventions.aliases) if (request.startsWith(prefix)) return `${root}/${target === "sparta" ? conventions.spartaFolder : conventions.testsFolder}/${request.slice(prefix.length)}`;
339
631
  if (request.startsWith(".")) return normalize(node_path.default.resolve(node_path.default.dirname(filename), request));
632
+ const tsconfig = tsconfigFor(filename);
633
+ const mapped = tsconfig === void 0 ? void 0 : matchPaths(request, tsconfig.paths);
634
+ const existing = mapped?.find(moduleExists);
635
+ if (existing !== void 0) return existing;
636
+ for (const [prefix, target] of conventions.aliases) if (request.startsWith(prefix)) return `${root}/${target === "sparta" ? conventions.spartaFolder : conventions.testsFolder}/${request.slice(prefix.length)}`;
637
+ if (mapped !== void 0 && mapped.length > 0) return mapped[0];
638
+ const fromBaseUrl = tsconfig?.baseUrl === void 0 ? void 0 : `${tsconfig.baseUrl}/${request}`;
639
+ return fromBaseUrl !== void 0 && moduleExists(fromBaseUrl) ? fromBaseUrl : void 0;
340
640
  }
341
- /** The layer folder a file lives in (`steppers`, `pages`, ...), with `sparta/scenarios/` counting as `scenarios`. */
641
+ /**
642
+ * The layer folder a file lives in (`steppers`, `pages`, ...), with `sparta/scenarios/` counting as `scenarios`
643
+ * and `sparta/<area>/builders/` and `directors/` as themselves.
644
+ */
342
645
  const layerFolder = (filename, conventions, root) => {
343
646
  const file = projectPath(filename, root);
344
647
  if (file === void 0) return void 0;
345
- if (file.match(conventions.patterns.top)?.[1] === "scenarios") return {
648
+ const top = file.match(conventions.patterns.top)?.[1];
649
+ if (top === "scenarios") return {
346
650
  name: "scenarios",
347
651
  standard: "scenarios"
348
652
  };
653
+ if (top === "common") return commonLayerFolder(file, conventions);
654
+ const areaLayer = areaLayerFolder(file, conventions);
655
+ if (areaLayer) return areaLayer;
349
656
  const folder = file.match(conventions.patterns.layer)?.[1];
350
657
  return folder === void 0 ? void 0 : {
351
658
  name: folder,
@@ -354,6 +661,10 @@ const layerFolder = (filename, conventions, root) => {
354
661
  };
355
662
  /** The file name suffix the files in a layer folder must use (`stepper` for `steppers/`), if it has one. */
356
663
  const layerSuffix = (folder) => folder?.standard === void 0 ? void 0 : LAYER_FOLDERS[folder.standard].suffix;
664
+ /** The file name without its TypeScript extension: `orders-stepper` for `orders-stepper.ts` or `.mts`. */
665
+ const moduleName = (filename) => node_path.default.basename(filename).replace(/\.[cm]?tsx?$/, "");
666
+ /** `.d.ts`, `.d.mts` and `.d.cts` files, which only declare types. */
667
+ const isDeclarationFile = (filename) => /\.d\.[cm]?ts$/.test(filename);
357
668
  /** True for files that follow the layer naming convention (layer folders and fixtures). */
358
669
  const isLayerFile = (filename, conventions, root) => layerSuffix(layerFolder(filename, conventions, root)) !== void 0 || projectPath(filename, root)?.match(conventions.patterns.top)?.[1] === "fixtures";
359
670
  // src/utils/settings.ts
@@ -387,22 +698,18 @@ const DATABASE_LAYERS = [
387
698
  "service",
388
699
  "stepper"
389
700
  ];
390
- /** The UI layers; `view` is the area's name for a page (`page` for web, `screen` for mobile). */
701
+ /** The UI layers; `view` is the area's name for a page (`page` for web, `screen` for mobile, `window` for desktop). */
391
702
  const uiLayers = (view) => ({
392
703
  component: /* @__PURE__ */ new Set([
393
704
  view,
394
705
  "stepper",
395
706
  "asserter",
396
- "scenario",
397
- "builder",
398
- "director"
707
+ "scenario"
399
708
  ]),
400
709
  [view]: /* @__PURE__ */ new Set([
401
710
  "stepper",
402
711
  "asserter",
403
- "scenario",
404
- "builder",
405
- "director"
712
+ "scenario"
406
713
  ]),
407
714
  stepper: /* @__PURE__ */ new Set(["asserter", "scenario"]),
408
715
  asserter: /* @__PURE__ */ new Set([
@@ -410,23 +717,9 @@ const uiLayers = (view) => ({
410
717
  "asserter",
411
718
  "scenario"
412
719
  ]),
413
- builder: /* @__PURE__ */ new Set([
414
- view,
415
- "component",
416
- "stepper",
417
- "asserter",
418
- "scenario"
419
- ]),
420
- director: /* @__PURE__ */ new Set([
421
- view,
422
- "component",
423
- "stepper",
424
- "asserter",
425
- "scenario"
426
- ]),
427
720
  scenario: /* @__PURE__ */ new Set([view, "component"])
428
721
  });
429
- /** Forbidden target layers inside the same area (API -> API, UI -> UI, database -> database, mobile -> mobile). */
722
+ /** Forbidden target layers inside the same area (API -> API, UI -> UI, database -> database, and so on). */
430
723
  const FORBIDDEN_LAYERS = {
431
724
  api: {
432
725
  client: /* @__PURE__ */ new Set([
@@ -529,9 +822,21 @@ const FORBIDDEN_LAYERS = {
529
822
  "base-repository"
530
823
  ])
531
824
  },
825
+ desktop: uiLayers("window"),
532
826
  mobile: uiLayers("screen"),
533
827
  ui: uiLayers("page")
534
828
  };
829
+ /** The layers of the `builders/` and `directors/` folders, wherever they live. */
830
+ const BUILDER_LAYERS = /* @__PURE__ */ new Set(["builder", "director"]);
831
+ /** The only layers, besides directors, that may use builders and directors. */
832
+ const BUILDER_USERS = /* @__PURE__ */ new Set([
833
+ "scenario",
834
+ "stepper",
835
+ "asserter",
836
+ "service"
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);
535
840
  const DATABASE_ACCESS = [
536
841
  "repository",
537
842
  "base-repository",
@@ -550,6 +855,7 @@ const FORBIDDEN_FOR_ORCHESTRATION = {
550
855
  "base-service"
551
856
  ]),
552
857
  database: new Set(DATABASE_ACCESS),
858
+ desktop: /* @__PURE__ */ new Set(["window", "component"]),
553
859
  mobile: /* @__PURE__ */ new Set(["screen", "component"]),
554
860
  ui: /* @__PURE__ */ new Set(["page", "component"])
555
861
  },
@@ -567,6 +873,12 @@ const FORBIDDEN_FOR_ORCHESTRATION = {
567
873
  "stepper",
568
874
  "asserter"
569
875
  ]),
876
+ desktop: /* @__PURE__ */ new Set([
877
+ "window",
878
+ "component",
879
+ "stepper",
880
+ "asserter"
881
+ ]),
570
882
  mobile: /* @__PURE__ */ new Set([
571
883
  "screen",
572
884
  "component",
@@ -583,32 +895,45 @@ const FORBIDDEN_FOR_ORCHESTRATION = {
583
895
  };
584
896
  const REEXPORT_LAYERS = /* @__PURE__ */ new Set([
585
897
  "asserter",
898
+ "builder",
586
899
  "client",
587
900
  "base-client",
588
901
  "base-repository",
589
902
  "component",
903
+ "director",
590
904
  "page",
591
905
  "repository",
592
906
  "scenario",
593
907
  "screen",
594
908
  "service",
595
909
  "base-service",
596
- "stepper"
910
+ "stepper",
911
+ "window"
597
912
  ]);
598
913
  const describe = (info, { spartaFolder, testsFolder }) => ({
599
- group: `${info.areaFolder}/${info.group}${info.layer ? ` ${info.layer}` : ""}`,
914
+ group: `${info.areaFolder}${info.group === void 0 ? "" : `/${info.group}`}${info.layer ? ` ${info.layer}` : ""}`,
600
915
  "area-common": `${info.areaFolder}/common`,
916
+ "area-layer": `${info.areaFolder} ${info.layer}`,
601
917
  "top-scenario": `${spartaFolder}/scenarios`,
602
918
  fixture: `${spartaFolder}/fixtures`,
603
- shared: `${spartaFolder}/common|support`,
919
+ shared: info.layer ? `${spartaFolder}/common ${info.layer}` : `${spartaFolder}/common|support`,
604
920
  test: testsFolder
605
921
  })[info.kind];
922
+ /** Whether code in an area folder (a group, or the area's builders and directors) may not depend on `target`. */
923
+ function areaIsolationViolation(source, target) {
924
+ if (["fixture", "top-scenario"].includes(target.kind)) return true;
925
+ if (target.areaFolder === void 0) return false;
926
+ if (target.areaFolder !== source.areaFolder) return true;
927
+ if (target.kind !== "group") return false;
928
+ return source.kind === "area-layer" ? target.layer !== "service" : target.group !== source.group;
929
+ }
606
930
  /** Isolation compares area folders, not area types: `web/` and `ui/` are separate areas even when both follow `ui`. */
607
931
  function isolationViolation(source, target) {
608
932
  if (target.kind === "test") return source.kind !== "test";
609
933
  if (source.kind === "shared") return [
610
934
  "group",
611
935
  "area-common",
936
+ "area-layer",
612
937
  "fixture",
613
938
  "top-scenario"
614
939
  ].includes(target.kind);
@@ -616,20 +941,32 @@ function isolationViolation(source, target) {
616
941
  if ([
617
942
  "fixture",
618
943
  "top-scenario",
619
- "group"
944
+ "group",
945
+ "area-layer"
620
946
  ].includes(target.kind)) return true;
621
947
  return target.kind === "area-common" && target.areaFolder !== source.areaFolder;
622
948
  }
623
- if (source.kind === "group") {
624
- if (["fixture", "top-scenario"].includes(target.kind)) return true;
625
- if (target.areaFolder === void 0) return false;
626
- if (target.areaFolder !== source.areaFolder) return true;
627
- return target.kind === "group" && target.group !== source.group;
628
- }
629
- return false;
949
+ return source.kind === "group" || source.kind === "area-layer" ? areaIsolationViolation(source, target) : false;
950
+ }
951
+ /**
952
+ * Whether `source` may not use the builder or director `target`: builders use no builders or directors, directors
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.
955
+ */
956
+ function builderViolation(source, target) {
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);
630
963
  }
631
964
  function layerViolation(source, target) {
632
- if (!target.layer || !target.area) return false;
965
+ if (!target.layer) return false;
966
+ const builder = BUILDER_LAYERS.has(target.layer) ? builderViolation(source, target) : void 0;
967
+ if (builder !== void 0) return builder;
968
+ if (isBuilderLayer(source)) return target.layer !== "service";
969
+ if (!target.area) return false;
633
970
  if (source.kind === "group" || source.kind === "area-common") {
634
971
  if (!source.area || !source.layer) return false;
635
972
  return source.areaFolder === target.areaFolder && Boolean(FORBIDDEN_LAYERS[source.area][source.layer]?.has(target.layer));
@@ -638,7 +975,7 @@ function layerViolation(source, target) {
638
975
  return false;
639
976
  }
640
977
  const isForbiddenReexport = (source, target) => target.layer !== void 0 && REEXPORT_LAYERS.has(target.layer) && target.layer !== source.layer && !["fixture", "test"].includes(source.kind);
641
- const rule$12 = {
978
+ const rule$13 = {
642
979
  meta: {
643
980
  type: "problem",
644
981
  docs: {
@@ -649,7 +986,8 @@ const rule$12 = {
649
986
  messages: {
650
987
  isolation: "{{source}} must not depend on {{target}} ({{request}}). Move shared code to the area's common/ folder or the top-level common/ folder.",
651
988
  layer: "{{source}} must not depend on {{target}} ({{request}}).",
652
- reexport: "Do not re-export {{target}} outside its layer; this bypasses the architecture boundaries."
989
+ reexport: "Do not re-export {{target}} outside its layer; this bypasses the architecture boundaries.",
990
+ staticService: "{{source}} is a static abstract class and must not depend on {{target}} ({{request}}); only a normal class may use services."
653
991
  }
654
992
  },
655
993
  create(context) {
@@ -658,11 +996,15 @@ const rule$12 = {
658
996
  const root = rootFor(context, conventions);
659
997
  const source = classify(filename, conventions, root);
660
998
  if (!source) return {};
999
+ /** Whether the file declares a normal (instantiable) class. Set on `Program`, before any import is visited. */
1000
+ let isNormalClass = false;
1001
+ /** An `index.ts` barrel in `builders/` or `directors/` may import and re-export its own layer. */
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;
661
1003
  const check = (node, request, reexport = false) => {
662
1004
  if (request === void 0) return;
663
1005
  const resolved = resolveImport(filename, request, root, conventions);
664
1006
  const target = resolved ? classify(resolved, conventions, root) : void 0;
665
- if (!target) return;
1007
+ if (!target || isOwnBarrel(target)) return;
666
1008
  const data = {
667
1009
  source: describe(source, conventions),
668
1010
  target: describe(target, conventions),
@@ -678,6 +1020,11 @@ const rule$12 = {
678
1020
  messageId: "layer",
679
1021
  data
680
1022
  });
1023
+ else if (isBuilderLayer(source) && target.layer === "service" && !isNormalClass) context.report({
1024
+ node,
1025
+ messageId: "staticService",
1026
+ data
1027
+ });
681
1028
  else if (reexport && isForbiddenReexport(source, target)) context.report({
682
1029
  node,
683
1030
  messageId: "reexport",
@@ -685,15 +1032,19 @@ const rule$12 = {
685
1032
  });
686
1033
  };
687
1034
  return {
1035
+ Program(node) {
1036
+ isNormalClass = topLevelClasses(node).some((declaration) => !isStaticClass(declaration));
1037
+ },
688
1038
  ImportDeclaration: (node) => check(node, stringValue(node.source)),
689
1039
  ExportNamedDeclaration: (node) => check(node, stringValue(node.source), true),
690
1040
  ExportAllDeclaration: (node) => check(node, stringValue(node.source), true),
691
- ImportExpression: (node) => check(node, stringValue(node.source)),
1041
+ ImportExpression: (node) => check(node, staticString(node.source)),
1042
+ TSImportType: (node) => check(node, stringValue(node.source)),
692
1043
  TSImportEqualsDeclaration(node) {
693
1044
  if (node.moduleReference.type === "TSExternalModuleReference") check(node, stringValue(node.moduleReference.expression));
694
1045
  },
695
1046
  CallExpression(node) {
696
- if (node.callee.type === "Identifier" && node.callee.name === "require") check(node, stringValue(node.arguments[0]));
1047
+ if (node.callee.type === "Identifier" && node.callee.name === "require") check(node, staticString(node.arguments[0]));
697
1048
  }
698
1049
  };
699
1050
  }
@@ -704,7 +1055,7 @@ const classOf = (statement) => {
704
1055
  const node = (statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration") && statement.declaration ? statement.declaration : statement;
705
1056
  return node.type === "ClassDeclaration" ? node : void 0;
706
1057
  };
707
- const rule$11 = {
1058
+ const rule$12 = {
708
1059
  meta: {
709
1060
  type: "suggestion",
710
1061
  docs: {
@@ -714,15 +1065,29 @@ const rule$11 = {
714
1065
  schema: [],
715
1066
  messages: {
716
1067
  name: "Class '{{found}}' must be named '{{expected}}' to match the file name.",
717
- single: "A layer file contains exactly one class; move '{{found}}' to its own file."
1068
+ single: "A layer file contains exactly one class; move '{{found}}' to its own file.",
1069
+ missing: "A layer file contains exactly one class; expected a class named '{{expected}}'."
718
1070
  }
719
1071
  },
720
1072
  create(context) {
721
1073
  const conventions = conventionsFor(context);
722
- if (!isLayerFile(context.filename, conventions, rootFor(context, conventions))) return {};
723
- const expected = toPascalCase(node_path.default.basename(context.filename).replace(/\.ts$/, ""));
1074
+ const root = rootFor(context, conventions);
1075
+ const { filename } = context;
1076
+ if (isDeclarationFile(filename) || !isLayerFile(filename, conventions, root)) return {};
1077
+ const module = moduleName(filename);
1078
+ const expected = toPascalCase(module);
1079
+ const requiresClass = module !== "index" && layerSuffix(layerFolder(filename, conventions, root)) !== void 0;
724
1080
  return { Program(program) {
725
- program.body.map(classOf).filter((node) => node !== void 0).forEach((node, index) => {
1081
+ const classes = program.body.map(classOf).filter((node) => node !== void 0);
1082
+ if (classes.length === 0 && requiresClass) {
1083
+ context.report({
1084
+ node: program,
1085
+ messageId: "missing",
1086
+ data: { expected }
1087
+ });
1088
+ return;
1089
+ }
1090
+ classes.forEach((node, index) => {
726
1091
  const found = node.id?.name ?? "(anonymous)";
727
1092
  if (index > 0) context.report({
728
1093
  node: node.id ?? node,
@@ -741,6 +1106,67 @@ const rule$11 = {
741
1106
  } };
742
1107
  }
743
1108
  };
1109
+ // src/rules/director-composes-builders.ts
1110
+ const rule$11 = {
1111
+ meta: {
1112
+ type: "suggestion",
1113
+ docs: {
1114
+ description: "Require a director to compose several builders; a director using a single builder belongs on that builder.",
1115
+ url: docsUrl("director-composes-builders")
1116
+ },
1117
+ schema: [],
1118
+ messages: { singleBuilder: "This director only uses '{{builder}}'; make it a custom method on '{{builder}}'. A director composes several builders." }
1119
+ },
1120
+ create(context) {
1121
+ const filename = context.filename;
1122
+ const conventions = conventionsFor(context);
1123
+ const root = rootFor(context, conventions);
1124
+ if (classify(filename, conventions, root)?.layer !== "director" || moduleName(filename) === "index") return {};
1125
+ const isBuilder = (request) => {
1126
+ if (request === void 0) return false;
1127
+ const resolved = resolveImport(filename, request, root, conventions);
1128
+ return resolved !== void 0 && classify(resolved, conventions, root)?.layer === "builder";
1129
+ };
1130
+ /** The builders the director uses, by imported name, with the import to report. */
1131
+ const builders = /* @__PURE__ */ new Map();
1132
+ /** Set when a builder is imported in a way that does not tell how many builders are used. */
1133
+ let unknown = false;
1134
+ return {
1135
+ ImportDeclaration(node) {
1136
+ if (node.importKind === "type" || typeof node.source.value !== "string" || !isBuilder(node.source.value)) return;
1137
+ for (const specifier of node.specifiers) if (specifier.type === "ImportNamespaceSpecifier") unknown = true;
1138
+ else if (specifier.type === "ImportDefaultSpecifier") builders.set(specifier.local.name, {
1139
+ local: specifier.local.name,
1140
+ node
1141
+ });
1142
+ else if (specifier.importKind !== "type") {
1143
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : String(specifier.imported.value);
1144
+ builders.set(imported, {
1145
+ local: specifier.local.name,
1146
+ node
1147
+ });
1148
+ }
1149
+ },
1150
+ ImportExpression(node) {
1151
+ if (isBuilder(staticString(node.source))) unknown = true;
1152
+ },
1153
+ CallExpression(node) {
1154
+ if (node.callee.type === "Identifier" && node.callee.name === "require") {
1155
+ if (isBuilder(staticString(node.arguments[0]))) unknown = true;
1156
+ }
1157
+ },
1158
+ "Program:exit"() {
1159
+ const [only] = builders.values();
1160
+ if (unknown || builders.size !== 1 || only === void 0) return;
1161
+ context.report({
1162
+ node: only.node,
1163
+ messageId: "singleBuilder",
1164
+ data: { builder: only.local }
1165
+ });
1166
+ }
1167
+ };
1168
+ }
1169
+ };
744
1170
  // src/rules/expect-from-support.ts
745
1171
  /** Files inside the sparta folder, except its support folder (where `expect` itself is defined). */
746
1172
  const appliesTo = (filename, { patterns }, root) => {
@@ -761,10 +1187,21 @@ const rule$10 = {
761
1187
  create(context) {
762
1188
  const conventions = conventionsFor(context);
763
1189
  const { supportModule } = conventions;
764
- if (!appliesTo(context.filename, conventions, rootFor(context, conventions))) return {};
1190
+ const root = rootFor(context, conventions);
1191
+ if (!appliesTo(context.filename, conventions, root)) return {};
1192
+ /**
1193
+ * The support module, a subpath of it, or a relative import into the support folder. Other aliases for that
1194
+ * folder are reported, so the configured module name stays the one that is used.
1195
+ */
1196
+ const isSupport = (source) => {
1197
+ if (source === supportModule || source.startsWith(`${supportModule}/`)) return true;
1198
+ if (!source.startsWith(".")) return false;
1199
+ const resolved = resolveImport(context.filename, source, root, conventions);
1200
+ return (resolved === void 0 ? void 0 : projectPath(resolved, root))?.match(conventions.patterns.top)?.[1] === "support";
1201
+ };
765
1202
  return { ImportDeclaration(node) {
766
1203
  const source = node.source.value;
767
- if (source === supportModule) return;
1204
+ if (isSupport(String(source))) return;
768
1205
  const specifier = node.specifiers.find((item) => item.type === "ImportSpecifier" && item.imported.type === "Identifier" && item.imported.name === "expect");
769
1206
  if (specifier === void 0) return;
770
1207
  const data = {
@@ -789,24 +1226,35 @@ const rule$10 = {
789
1226
  }
790
1227
  };
791
1228
  // src/rules/file-naming.ts
1229
+ /** Lowercase words of letters and digits, joined by single hyphens: `orders-v2-stepper`. */
1230
+ const KEBAB_CASE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
1231
+ /** `myOrders`, `My_APIOrders` and `checkout--flow` become `my-orders`, `my-api-orders` and `checkout-flow`. */
1232
+ const toKebabCase = (name) => name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "").toLowerCase();
792
1233
  const rule$9 = {
793
1234
  meta: {
794
1235
  type: "suggestion",
795
1236
  docs: {
796
- description: "Require files in a layer folder to end with the layer suffix (e.g. `*-stepper.ts`).",
1237
+ description: "Require files in a layer folder to be kebab-case and end with the layer suffix (e.g. `orders-stepper.ts`).",
797
1238
  url: docsUrl("file-naming")
798
1239
  },
799
1240
  schema: [],
800
- messages: { suffix: "Files in '{{folder}}/' must be named '*-{{suffix}}.ts' (found '{{name}}')." }
1241
+ messages: {
1242
+ suffix: "Files in '{{folder}}/' must be named '*-{{suffix}}.ts' (found '{{name}}').",
1243
+ kebabCase: "File name '{{name}}' must be kebab-case: '{{expected}}'."
1244
+ }
801
1245
  },
802
1246
  create(context) {
803
1247
  const conventions = conventionsFor(context);
804
1248
  const folder = layerFolder(context.filename, conventions, rootFor(context, conventions));
805
1249
  const suffix = layerSuffix(folder);
806
1250
  const name = node_path.default.basename(context.filename);
807
- if (folder === void 0 || suffix === void 0 || name === "index.ts" || name.endsWith(`-${suffix}.ts`)) return {};
1251
+ const module = moduleName(context.filename);
1252
+ if (folder === void 0 || suffix === void 0 || isDeclarationFile(name) || module === "index") return {};
1253
+ const hasSuffix = module.endsWith(`-${suffix}`);
1254
+ const isKebabCase = KEBAB_CASE.test(module);
1255
+ if (hasSuffix && isKebabCase) return {};
808
1256
  return { Program(node) {
809
- context.report({
1257
+ if (!hasSuffix) context.report({
810
1258
  node,
811
1259
  messageId: "suffix",
812
1260
  data: {
@@ -815,30 +1263,61 @@ const rule$9 = {
815
1263
  name
816
1264
  }
817
1265
  });
1266
+ if (!isKebabCase) {
1267
+ const expected = `${toKebabCase(module)}${name.slice(module.length)}`;
1268
+ context.report({
1269
+ node,
1270
+ messageId: "kebabCase",
1271
+ data: {
1272
+ name,
1273
+ expected
1274
+ }
1275
+ });
1276
+ }
818
1277
  } };
819
1278
  }
820
1279
  };
821
1280
  // src/rules/lines-between-class-members.ts
822
1281
  const BLANK_LINE$1 = /\r?\n[\t ]*\r?\n/;
1282
+ const BLANK_LINES$1 = /(\r?\n)(?:[\t ]*\r?\n)+/g;
1283
+ /** An overload signature (or abstract method): a method without a body. */
1284
+ const isSignature = (member) => isMethod(member) && member.value.body === null;
823
1285
  const rule$8 = {
824
1286
  meta: {
825
1287
  type: "layout",
826
1288
  docs: {
827
- description: "Require a blank line after every multi-line class member.",
1289
+ description: "Require a blank line after every multi-line method-like class member, and disallow blank lines between method overloads.",
828
1290
  url: docsUrl("lines-between-class-members")
829
1291
  },
830
1292
  fixable: "whitespace",
831
1293
  schema: [],
832
- messages: { expectedBlankLine: "Expected a blank line between class members." }
1294
+ messages: {
1295
+ expectedBlankLine: "Expected a blank line between class members.",
1296
+ unexpectedBlankLine: "Unexpected blank line between overloads of the same method."
1297
+ }
833
1298
  },
834
1299
  create(context) {
835
- const { text } = context.sourceCode;
1300
+ const { sourceCode } = context;
1301
+ const { text } = sourceCode;
1302
+ const keyOf = (method) => `${method.static ? "static " : ""}${method.computed ? "[]" : ""}${sourceCode.getText(method.key)}`;
1303
+ /** `current` continues the overload group that `previous` (a bodyless signature) belongs to. */
1304
+ const isOverloadOf = (previous, current) => isSignature(previous) && isMethod(current) && current.kind === previous.kind && keyOf(current) === keyOf(previous);
836
1305
  return { ClassBody(node) {
837
1306
  for (let index = 1; index < node.body.length; index++) {
838
1307
  const previous = node.body[index - 1];
839
1308
  const current = node.body[index];
840
- if (previous.loc.start.line === previous.loc.end.line) continue;
841
1309
  const textBetween = text.slice(previous.range[1], current.range[0]);
1310
+ if (isOverloadOf(previous, current)) {
1311
+ if (!BLANK_LINE$1.test(textBetween)) continue;
1312
+ context.report({
1313
+ node: current,
1314
+ messageId: "unexpectedBlankLine",
1315
+ fix: (fixer) => fixer.replaceTextRange([previous.range[1], current.range[0]], textBetween.replace(BLANK_LINES$1, "$1"))
1316
+ });
1317
+ continue;
1318
+ }
1319
+ if (previous.loc.start.line === previous.loc.end.line) continue;
1320
+ if (isPlainProperty(previous)) continue;
842
1321
  if (BLANK_LINE$1.test(textBetween)) continue;
843
1322
  context.report({
844
1323
  node: current,
@@ -853,9 +1332,154 @@ const rule$8 = {
853
1332
  } };
854
1333
  }
855
1334
  };
856
- // src/rules/no-direct-construction-in-tests.ts
857
- const LAYER_CLASS = /(Stepper|Asserter|Scenario|Service|Client|Repository|Page|Screen|Component|Builder|Director|Factory|Provider)$/;
1335
+ // src/rules/member-ordering.ts
1336
+ const KINDS = [
1337
+ "property",
1338
+ "constructor",
1339
+ "method"
1340
+ ];
1341
+ const ACCESSES = [
1342
+ "public",
1343
+ "protected",
1344
+ "private"
1345
+ ];
1346
+ /** Properties (incl. index signatures) and methods; a property holding a function or class counts as a method. */
1347
+ const kindOf = (member) => {
1348
+ if (isMethod(member)) return member.kind === "constructor" ? "constructor" : "method";
1349
+ if (member.type === "StaticBlock") return void 0;
1350
+ return isPlainProperty(member) ? "property" : "method";
1351
+ };
1352
+ const accessOf = (member) => {
1353
+ if (isPrivate(member)) return "private";
1354
+ if ("accessibility" in member && member.accessibility === "protected") return "protected";
1355
+ return "public";
1356
+ };
1357
+ /**
1358
+ * The required order: static properties, instance properties, constructor, static methods, instance methods,
1359
+ * each from public to protected to private.
1360
+ */
1361
+ const groupOf = (member) => {
1362
+ const kind = kindOf(member);
1363
+ if (kind === void 0) return void 0;
1364
+ if (kind === "constructor") return {
1365
+ rank: KINDS.indexOf(kind) * 6,
1366
+ label: "constructor"
1367
+ };
1368
+ const isStatic = "static" in member && member.static;
1369
+ const access = accessOf(member);
1370
+ return {
1371
+ rank: KINDS.indexOf(kind) * 6 + (isStatic ? 0 : 3) + ACCESSES.indexOf(access),
1372
+ label: `${isStatic ? "static " : ""}${access} ${kind}`
1373
+ };
1374
+ };
1375
+ const SKIPPED_KEYS$1 = /* @__PURE__ */ new Set([
1376
+ "parent",
1377
+ "loc",
1378
+ "range",
1379
+ "start",
1380
+ "end",
1381
+ "typeAnnotation"
1382
+ ]);
1383
+ const isNode$1 = (value) => typeof value === "object" && value !== null && typeof value.type === "string";
1384
+ const FUNCTIONS = /* @__PURE__ */ new Set([
1385
+ "ArrowFunctionExpression",
1386
+ "FunctionExpression",
1387
+ "ClassExpression"
1388
+ ]);
1389
+ /** `x` for `this.x`, `this.#x` and `ClassName.x`. */
1390
+ const ownPropertyRead = (node, className) => {
1391
+ if (node.type !== "MemberExpression" || node.computed) return void 0;
1392
+ const { object, property } = node;
1393
+ return (object.type === "ThisExpression" || className !== void 0 && object.type === "Identifier" && object.name === className) && (property.type === "Identifier" || property.type === "PrivateIdentifier") ? property.name : void 0;
1394
+ };
1395
+ /**
1396
+ * The property names an initializer reads while it runs, as `this.x`, `this.#x` or `ClassName.x`. Code inside
1397
+ * functions is left out: it runs later, when every property is initialized.
1398
+ */
1399
+ function readsDuringInit(value, className) {
1400
+ const names = /* @__PURE__ */ new Set();
1401
+ const visit = (node) => {
1402
+ if (FUNCTIONS.has(node.type)) return;
1403
+ const read = ownPropertyRead(node, className);
1404
+ if (read !== void 0) names.add(read);
1405
+ for (const [key, child] of Object.entries(node)) {
1406
+ if (SKIPPED_KEYS$1.has(key)) continue;
1407
+ if (Array.isArray(child)) {
1408
+ for (const item of child) if (isNode$1(item)) visit(item);
1409
+ } else if (isNode$1(child)) visit(child);
1410
+ }
1411
+ };
1412
+ visit(value);
1413
+ return names;
1414
+ }
1415
+ /**
1416
+ * Initializers run in source order, so a property that reads a property declared before it must stay below it,
1417
+ * even when the order of the groups says otherwise.
1418
+ */
1419
+ const dependsOnEarlier = (member, earlier, className) => {
1420
+ if (member.type !== "PropertyDefinition" && member.type !== "AccessorProperty") return false;
1421
+ if (!member.value) return false;
1422
+ return [...readsDuringInit(member.value, className)].some((name) => earlier.has(name));
1423
+ };
858
1424
  const rule$7 = {
1425
+ meta: {
1426
+ type: "suggestion",
1427
+ docs: {
1428
+ description: "Require class members in a fixed order: properties, constructor, methods; static before instance; public before protected before private.",
1429
+ url: docsUrl("member-ordering")
1430
+ },
1431
+ schema: [],
1432
+ messages: { memberOrdering: "'{{name}}' ({{group}}) must come before '{{otherName}}' ({{otherGroup}})." }
1433
+ },
1434
+ create(context) {
1435
+ return { ClassBody(node) {
1436
+ let highest;
1437
+ const { parent } = node;
1438
+ const className = (parent.type === "ClassDeclaration" || parent.type === "ClassExpression") && parent.id ? parent.id.name : void 0;
1439
+ /** Names of the properties declared so far. */
1440
+ const earlier = /* @__PURE__ */ new Set();
1441
+ for (const member of node.body) {
1442
+ const group = groupOf(member);
1443
+ const dependent = dependsOnEarlier(member, earlier, className);
1444
+ if (isPlainProperty(member) && member.type !== "TSIndexSignature") earlier.add(memberName$1(member));
1445
+ if (group === void 0) continue;
1446
+ if (highest === void 0 || group.rank >= highest.group.rank) {
1447
+ highest = {
1448
+ member,
1449
+ group
1450
+ };
1451
+ continue;
1452
+ }
1453
+ if (dependent) continue;
1454
+ context.report({
1455
+ node: member,
1456
+ messageId: "memberOrdering",
1457
+ data: {
1458
+ name: memberName$1(member),
1459
+ group: group.label,
1460
+ otherName: memberName$1(highest.member),
1461
+ otherGroup: highest.group.label
1462
+ }
1463
+ });
1464
+ }
1465
+ } };
1466
+ }
1467
+ };
1468
+ // src/rules/no-direct-construction-in-tests.ts
1469
+ /** Names of SPARTA layer classes, for classes whose import does not tell their layer. */
1470
+ const LAYER_CLASS = /(Stepper|Asserter|Scenario|Service|Client|Repository|Page|Screen|Window|Component|Builder|Director|Factory|Provider|Container|Database)$/;
1471
+ /** The class a `new` expression constructs: `X` for `new X()`, `ns` and `X` for `new ns.X()`. */
1472
+ const constructed = (callee) => {
1473
+ if (callee.type === "Identifier") return {
1474
+ binding: callee.name,
1475
+ name: callee.name
1476
+ };
1477
+ if (callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && callee.property.type === "Identifier") return {
1478
+ binding: callee.object.name,
1479
+ name: callee.property.name
1480
+ };
1481
+ };
1482
+ const rule$6 = {
859
1483
  meta: {
860
1484
  type: "problem",
861
1485
  docs: {
@@ -867,15 +1491,36 @@ const rule$7 = {
867
1491
  },
868
1492
  create(context) {
869
1493
  const conventions = conventionsFor(context);
870
- if (classify(context.filename, conventions, rootFor(context, conventions))?.kind !== "test") return {};
871
- return { NewExpression(node) {
872
- const { callee } = node;
873
- if (callee.type === "Identifier" && LAYER_CLASS.test(callee.name)) context.report({
874
- node,
875
- messageId: "useFixture",
876
- data: { name: callee.name }
877
- });
878
- } };
1494
+ const root = rootFor(context, conventions);
1495
+ if (classify(context.filename, conventions, root)?.kind !== "test") return {};
1496
+ /** Local names of imports (named, default and namespace) to their module. */
1497
+ const imports = /* @__PURE__ */ new Map();
1498
+ /**
1499
+ * Whether constructing `name` (bound to the local `binding`) creates a SPARTA layer object. An import decides by
1500
+ * where it points: never for packages, always for layer folders. Otherwise the class name decides.
1501
+ */
1502
+ const isLayerClass = (binding, name) => {
1503
+ const source = imports.get(binding);
1504
+ if (source === void 0) return LAYER_CLASS.test(name);
1505
+ const resolved = resolveImport(context.filename, source, root, conventions);
1506
+ if (resolved === void 0) return false;
1507
+ const target = classify(resolved, conventions, root);
1508
+ return target?.layer !== void 0 || target?.kind === "top-scenario" || layerSuffix(layerFolder(resolved, conventions, root)) !== void 0 || LAYER_CLASS.test(name);
1509
+ };
1510
+ return {
1511
+ ImportDeclaration(node) {
1512
+ if (typeof node.source.value !== "string") return;
1513
+ for (const specifier of node.specifiers) imports.set(specifier.local.name, node.source.value);
1514
+ },
1515
+ NewExpression(node) {
1516
+ const found = constructed(node.callee);
1517
+ if (found && isLayerClass(found.binding, found.name)) context.report({
1518
+ node,
1519
+ messageId: "useFixture",
1520
+ data: { name: context.sourceCode.getText(node.callee) }
1521
+ });
1522
+ }
1523
+ };
879
1524
  }
880
1525
  };
881
1526
  // src/rules/no-expect-in-tests.ts
@@ -884,7 +1529,7 @@ const rule$7 = {
884
1529
  * `expected`, `expecting` and the like are left alone. `settings.sparta.expectNames` adds exact names.
885
1530
  */
886
1531
  const EXPECT_NAME = /^expect(?:ly)?(?:[A-Z_$\d]|$)/;
887
- const rule$6 = {
1532
+ const rule$5 = {
888
1533
  meta: {
889
1534
  type: "problem",
890
1535
  docs: {
@@ -947,7 +1592,15 @@ const resolvesPromise = (callback, resolve) => {
947
1592
  const call = body.type === "CallExpression" ? body : body.type === "BlockStatement" && body.body.length === 1 && body.body[0].type === "ExpressionStatement" ? body.body[0].expression : void 0;
948
1593
  return call?.type === "CallExpression" && isIdentifier(call.callee, resolve);
949
1594
  };
950
- const rule$5 = {
1595
+ /** The name of an import specifier or object pattern key (`setTimeout`, `"setTimeout"`). */
1596
+ const propertyName = (node) => node.type === "Identifier" ? node.name : stringValue(node);
1597
+ /** `require("timers/promises")` or `require("node:timers/promises")`. */
1598
+ const isTimersRequire = (node) => {
1599
+ if (node?.type !== "CallExpression" || !isIdentifier(node.callee, "require")) return false;
1600
+ const source = staticString(node.arguments[0]);
1601
+ return source !== void 0 && TIMER_MODULES.has(source);
1602
+ };
1603
+ const rule$4 = {
951
1604
  meta: {
952
1605
  type: "problem",
953
1606
  docs: {
@@ -962,17 +1615,47 @@ const rule$5 = {
962
1615
  const { patterns } = conventions;
963
1616
  const file = projectPath(context.filename, rootFor(context, conventions));
964
1617
  if (file === void 0 || !patterns.checked.test(file) || patterns.framework.test(file)) return {};
1618
+ /** Local names bound to the `timers/promises` module (`timers`) and to its `scheduler` (`schedulers`). */
1619
+ const timers = /* @__PURE__ */ new Set();
1620
+ const schedulers = /* @__PURE__ */ new Set();
1621
+ /** Records a named binding from `timers/promises`; `setTimeout` itself is reported where it is bound. */
1622
+ const bindNamed = (imported, local, node) => {
1623
+ if (imported === "setTimeout") context.report({
1624
+ node,
1625
+ messageId: "hardWait"
1626
+ });
1627
+ if (imported === "scheduler" && local?.type === "Identifier") schedulers.add(local.name);
1628
+ };
1629
+ /** `timers.setTimeout(...)`, `scheduler.wait(...)` and `timers.scheduler.wait(...)`. */
1630
+ const isTimersSleep = (callee) => {
1631
+ if (callee.type !== "MemberExpression") return false;
1632
+ const { object, property } = callee;
1633
+ if (isIdentifier(property, "setTimeout")) return object.type === "Identifier" && timers.has(object.name);
1634
+ if (!isIdentifier(property, "wait")) return false;
1635
+ if (object.type === "Identifier") return schedulers.has(object.name);
1636
+ return object.type === "MemberExpression" && object.object.type === "Identifier" && timers.has(object.object.name) && isIdentifier(object.property, "scheduler");
1637
+ };
965
1638
  return {
966
1639
  ImportDeclaration(node) {
967
1640
  if (typeof node.source.value !== "string" || !TIMER_MODULES.has(node.source.value)) return;
968
- for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier" && isIdentifier(specifier.imported, "setTimeout")) context.report({
969
- node: specifier,
970
- messageId: "hardWait"
971
- });
1641
+ for (const specifier of node.specifiers) if (specifier.type === "ImportSpecifier") bindNamed(propertyName(specifier.imported) ?? "", specifier.local, specifier);
1642
+ else timers.add(specifier.local.name);
1643
+ },
1644
+ VariableDeclarator(node) {
1645
+ if (!isTimersRequire(node.init)) return;
1646
+ if (node.id.type === "Identifier") {
1647
+ timers.add(node.id.name);
1648
+ return;
1649
+ }
1650
+ if (node.id.type !== "ObjectPattern") return;
1651
+ for (const property of node.id.properties) {
1652
+ if (property.type !== "Property" || property.computed) continue;
1653
+ bindNamed(propertyName(property.key) ?? "", property.value, property);
1654
+ }
972
1655
  },
973
1656
  CallExpression(node) {
974
1657
  const { callee } = node;
975
- if (callee.type === "MemberExpression" && isIdentifier(callee.property, "waitForTimeout")) {
1658
+ if (callee.type === "MemberExpression" && isIdentifier(callee.property, "waitForTimeout") || isTimersSleep(callee)) {
976
1659
  context.report({
977
1660
  node,
978
1661
  messageId: "hardWait"
@@ -1000,7 +1683,7 @@ const CALLBACK_ARGUMENT_METHODS = /* @__PURE__ */ new Set(["poll", "pollAndRetur
1000
1683
  /** Methods that retry the callback given to the start of their chain (`expect(cb).toPass()`). */
1001
1684
  const CALLBACK_SUBJECT_METHODS = /* @__PURE__ */ new Set(["toPass", "toPassAndReturn"]);
1002
1685
  /** The static name of a member access (`a.b`, `a["b"]`), or `undefined` for computed or private access. */
1003
- const memberName$1 = (node) => {
1686
+ const memberName = (node) => {
1004
1687
  if (node.type !== "MemberExpression") return void 0;
1005
1688
  const { property } = node;
1006
1689
  if (!node.computed && property.type === "Identifier") return property.name;
@@ -1009,7 +1692,7 @@ const memberName$1 = (node) => {
1009
1692
  /** The polling method a call invokes (`toPass` for `expect(cb).toPass()`), or `undefined` for any other node. */
1010
1693
  const pollingMethod = (node, methods) => {
1011
1694
  if (node.type !== "CallExpression") return void 0;
1012
- const name = memberName$1(node.callee);
1695
+ const name = memberName(node.callee);
1013
1696
  return name !== void 0 && methods.has(name) ? name : void 0;
1014
1697
  };
1015
1698
  const isFunction$1 = (node) => node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression";
@@ -1051,14 +1734,6 @@ const SKIPPED_KEYS = /* @__PURE__ */ new Set([
1051
1734
  "returnType",
1052
1735
  "decorators"
1053
1736
  ]);
1054
- const MODULE_EXTENSIONS = [
1055
- "",
1056
- ".ts",
1057
- ".tsx",
1058
- ".mts",
1059
- ".cts",
1060
- "/index.ts"
1061
- ];
1062
1737
  const isNode = (value) => typeof value === "object" && value !== null && typeof value.type === "string";
1063
1738
  /** Visits `node` and its descendants depth-first. Returning `false` from `visit` skips the node's children. */
1064
1739
  function walk(node, visit) {
@@ -1093,11 +1768,16 @@ function summarizeClass(name, node) {
1093
1768
  }
1094
1769
  return info;
1095
1770
  }
1096
- /** A typed field (`x: X`) or a field created with `new X()`. */
1771
+ /** A typed field (`x: X`), a field created with `new X()`, or a function-valued field, which acts as a method. */
1097
1772
  function summarizeField(info, member) {
1098
1773
  const field = member.computed ? void 0 : keyName(member.key);
1774
+ if (field === void 0) return;
1775
+ if (isFunctionLike(member.value)) {
1776
+ info.methods.set(field, member.value);
1777
+ return;
1778
+ }
1099
1779
  const type = typeName(member.typeAnnotation) ?? newName(member.value);
1100
- if (field !== void 0 && type !== void 0) info.fields.set(field, type);
1780
+ if (type !== void 0) info.fields.set(field, type);
1101
1781
  }
1102
1782
  /** Methods, getters (whose return type acts as a field type) and the constructor. */
1103
1783
  function summarizeMethod(info, member) {
@@ -1122,7 +1802,7 @@ function summarizeConstructor(info, constructor) {
1122
1802
  walk(constructor.body, (node) => {
1123
1803
  if (node.type !== "AssignmentExpression" || node.left.type !== "MemberExpression") return;
1124
1804
  if (node.left.object.type !== "ThisExpression") return;
1125
- const field = memberName$1(node.left);
1805
+ const field = memberName(node.left);
1126
1806
  const type = newName(node.right);
1127
1807
  if (field !== void 0 && type !== void 0 && !info.fields.has(field)) info.fields.set(field, type);
1128
1808
  });
@@ -1194,13 +1874,10 @@ function summarizeNamedExport(summary, statement) {
1194
1874
  else summary.exports.set(exported, local);
1195
1875
  }
1196
1876
  }
1197
- const isFile = (file) => (0, node_fs.statSync)(file, { throwIfNoEntry: false })?.isFile() ?? false;
1198
- /** Resolves a relative or aliased import to a TypeScript file. Package imports resolve to `undefined`. */
1877
+ /** Resolves a relative, aliased or tsconfig-mapped import to a TypeScript file. Package imports resolve to `undefined`. */
1199
1878
  function resolveModule(fromFile, request, root, conventions) {
1200
1879
  const base = resolveImport(fromFile, request, root, conventions);
1201
- if (base === void 0) return void 0;
1202
- const stripped = base.replace(/\.(?:m|c)?js$/, "");
1203
- for (const candidate of [base, ...MODULE_EXTENSIONS.map((extension) => `${stripped}${extension}`)]) if (isFile(candidate)) return normalize(candidate);
1880
+ return base === void 0 ? void 0 : moduleFile(base);
1204
1881
  }
1205
1882
  /**
1206
1883
  * Summaries of files on disk per project root and conventions (imports resolve against them), kept for the lifetime of the
@@ -1305,7 +1982,7 @@ var ProjectIndex = class {
1305
1982
  fn
1306
1983
  } : void 0;
1307
1984
  }
1308
- const method = memberName$1(node);
1985
+ const method = memberName(node);
1309
1986
  if (method === void 0 || node.type !== "MemberExpression") return void 0;
1310
1987
  const receiver = this.receiverClass(node.object, scope);
1311
1988
  return receiver ? this.findMethod(receiver, method) : void 0;
@@ -1335,13 +2012,13 @@ var ProjectIndex = class {
1335
2012
  case "ThisExpression": return scope.cls;
1336
2013
  case "Identifier": {
1337
2014
  const type = scope.locals.get(node.name);
1338
- return type === void 0 ? void 0 : this.resolveClass(scope.file, type);
2015
+ return this.resolveClass(scope.file, type ?? node.name);
1339
2016
  }
1340
2017
  case "NewExpression": return node.callee.type === "Identifier" ? this.resolveClass(scope.file, node.callee.name) : void 0;
1341
2018
  case "TSNonNullExpression":
1342
2019
  case "ParenthesizedExpression": return this.receiverClass(node.expression, scope, depth + 1);
1343
2020
  case "MemberExpression": {
1344
- const field = memberName$1(node);
2021
+ const field = memberName(node);
1345
2022
  const owner = field === void 0 ? void 0 : this.receiverClass(node.object, scope, depth + 1);
1346
2023
  return owner && field !== void 0 ? this.fieldClass(owner, field) : void 0;
1347
2024
  }
@@ -1403,11 +2080,29 @@ var ProjectIndex = class {
1403
2080
  }
1404
2081
  }
1405
2082
  };
1406
- /** Local variables whose class is known: `const x = new X()` and `const x: X = ...`. */
2083
+ /** `x` and `X` for a parameter `x: X` or `x = new X()`. Parameter properties are fields, not locals. */
2084
+ function typedParameter(param) {
2085
+ const binding = param.type === "AssignmentPattern" ? param.left : param;
2086
+ if (binding.type !== "Identifier") return void 0;
2087
+ const type = typeName(binding.typeAnnotation) ?? (param.type === "AssignmentPattern" ? newName(param.right) : void 0);
2088
+ return type === void 0 ? void 0 : [binding.name, type];
2089
+ }
2090
+ /**
2091
+ * Locals whose class is known: typed parameters of `fn` and the functions inside it, `const x = new X()` and
2092
+ * `const x: X = ...`.
2093
+ */
1407
2094
  function collectLocals(fn) {
1408
2095
  const locals = /* @__PURE__ */ new Map();
2096
+ const addParameters = (node) => {
2097
+ for (const param of node.params) {
2098
+ const found = typedParameter(param);
2099
+ if (found) locals.set(...found);
2100
+ }
2101
+ };
2102
+ addParameters(fn);
1409
2103
  if (!fn.body) return locals;
1410
2104
  walk(fn.body, (node) => {
2105
+ if (isFunctionLike(node)) addParameters(node);
1411
2106
  if (node.type !== "VariableDeclarator" || node.id.type !== "Identifier") return;
1412
2107
  const type = typeName(node.id.typeAnnotation) ?? newName(node.init);
1413
2108
  if (type !== void 0) locals.set(node.id.name, type);
@@ -1428,7 +2123,7 @@ function enclosing(node) {
1428
2123
  }
1429
2124
  return { fn };
1430
2125
  }
1431
- const rule$4 = {
2126
+ const rule$3 = {
1432
2127
  meta: {
1433
2128
  type: "problem",
1434
2129
  docs: {
@@ -1499,6 +2194,7 @@ const rule$4 = {
1499
2194
  };
1500
2195
  // src/rules/padding-lines.ts
1501
2196
  const BLANK_LINE = /\r?\n[\t ]*\r?\n/;
2197
+ const BLANK_LINES = /(\r?\n)(?:[\t ]*\r?\n)+/g;
1502
2198
  const unwrapExport = (node) => (node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") && node.declaration ? node.declaration : node;
1503
2199
  const isFunctionValue = (node) => node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression" || node?.type === "TSEmptyBodyFunctionExpression";
1504
2200
  const isImport = (node) => node.type === "ImportDeclaration" || node.type === "TSImportEqualsDeclaration" && node.moduleReference.type === "TSExternalModuleReference";
@@ -1515,12 +2211,16 @@ const isOverloadPair = (previous, current) => {
1515
2211
  const name = functionStatementName(previous);
1516
2212
  return unwrapExport(previous).type === "TSDeclareFunction" && name !== void 0 && name === functionStatementName(current);
1517
2213
  };
1518
- const isMethodProperty = (property) => property.type === "Property" && (property.method || property.kind !== "init" || isFunctionValue(property.value));
1519
- const rule$3 = {
2214
+ /**
2215
+ * A multi-line method, getter, setter or property holding a function. Single-line ones need no blank lines,
2216
+ * as in `lines-between-class-members`.
2217
+ */
2218
+ const isMethodProperty = (property) => property.type === "Property" && property.loc.start.line !== property.loc.end.line && (property.method || property.kind !== "init" || isFunctionValue(property.value));
2219
+ const rule$2 = {
1520
2220
  meta: {
1521
2221
  type: "layout",
1522
2222
  docs: {
1523
- description: "Require blank lines after imports, around top-level functions and around object methods.",
2223
+ description: "Require blank lines after imports, around top-level functions and around object methods, and disallow blank lines between function overloads.",
1524
2224
  url: docsUrl("padding-lines")
1525
2225
  },
1526
2226
  fixable: "whitespace",
@@ -1528,7 +2228,8 @@ const rule$3 = {
1528
2228
  messages: {
1529
2229
  afterImports: "Expected a blank line after the import declarations.",
1530
2230
  aroundFunctions: "Expected a blank line between a function and the adjacent statement.",
1531
- betweenObjectMethods: "Expected a blank line around methods in an object literal."
2231
+ betweenObjectMethods: "Expected a blank line around methods in an object literal.",
2232
+ betweenOverloads: "Unexpected blank line between overloads of the same function."
1532
2233
  }
1533
2234
  },
1534
2235
  create(context) {
@@ -1547,12 +2248,23 @@ const rule$3 = {
1547
2248
  }
1548
2249
  });
1549
2250
  };
2251
+ /** Overload signatures and the implementation form one group without blank lines; comments are kept. */
2252
+ const forbidBlankLines = (previous, current) => {
2253
+ const textBetween = text.slice(previous.range[1], current.range[0]);
2254
+ if (!BLANK_LINE.test(textBetween)) return;
2255
+ context.report({
2256
+ node: current,
2257
+ messageId: "betweenOverloads",
2258
+ fix: (fixer) => fixer.replaceTextRange([previous.range[1], current.range[0]], textBetween.replace(BLANK_LINES, "$1"))
2259
+ });
2260
+ };
1550
2261
  const checkStatements = (statements) => {
1551
2262
  for (let index = 1; index < statements.length; index++) {
1552
2263
  const previous = statements[index - 1];
1553
2264
  const current = statements[index];
1554
2265
  if (isImport(previous) && !isImport(current)) requireBlankLine(previous, current, "afterImports");
1555
- else if ((isFunctionStatement(previous) || isFunctionStatement(current)) && !isOverloadPair(previous, current)) requireBlankLine(previous, current, "aroundFunctions");
2266
+ else if (isOverloadPair(previous, current)) forbidBlankLines(previous, current);
2267
+ else if (isFunctionStatement(previous) || isFunctionStatement(current)) requireBlankLine(previous, current, "aroundFunctions");
1556
2268
  }
1557
2269
  };
1558
2270
  return {
@@ -1569,51 +2281,12 @@ const rule$3 = {
1569
2281
  };
1570
2282
  }
1571
2283
  };
1572
- // src/rules/private-members-last.ts
1573
- const isMethodLike = (member) => (member.type === "MethodDefinition" || member.type === "TSAbstractMethodDefinition") && member.kind !== "constructor";
1574
- const isPrivate = (member) => "accessibility" in member && member.accessibility === "private" || "key" in member && member.key.type === "PrivateIdentifier";
1575
- const memberName = (member) => {
1576
- const key = "key" in member ? member.key : void 0;
1577
- if (key && "name" in key && typeof key.name === "string") return key.name;
1578
- if (key && "value" in key && typeof key.value === "string") return key.value;
1579
- return "<computed>";
1580
- };
1581
- const rule$2 = {
1582
- meta: {
1583
- type: "suggestion",
1584
- docs: {
1585
- description: "Require public methods to be placed above private methods.",
1586
- url: docsUrl("private-members-last")
1587
- },
1588
- schema: [],
1589
- messages: { privateMembersLast: "Public method '{{name}}' must be placed above all private methods (private method '{{privateName}}' comes first)." }
1590
- },
1591
- create(context) {
1592
- return { ClassBody(node) {
1593
- let firstPrivate;
1594
- for (const member of node.body) {
1595
- if (!isMethodLike(member)) continue;
1596
- if (isPrivate(member)) {
1597
- firstPrivate ??= member;
1598
- continue;
1599
- }
1600
- if (firstPrivate !== void 0) context.report({
1601
- node: member,
1602
- messageId: "privateMembersLast",
1603
- data: {
1604
- name: memberName(member),
1605
- privateName: memberName(firstPrivate)
1606
- }
1607
- });
1608
- }
1609
- } };
1610
- }
1611
- };
1612
2284
  // src/rules/step-placeholders.ts
1613
2285
  /** The same pattern `@step` uses at runtime: the path is taken as written, so `{{ name }}` looks up " name ". */
1614
2286
  const NAMED = /\{\{(.*?)\}\}/g;
1615
2287
  const INDEX = /\[\[(\d+)\]\]/g;
1616
- const SINGLE_BRACES = /(^|[^{])\{([A-Za-z_$][\w$]*(?:\.[\w$]+)*)\}(?!\})/g;
2288
+ /** A lookbehind instead of a consumed prefix character, so adjacent placeholders (`{a}{b}`) are all found. */
2289
+ const SINGLE_BRACES = /(?<!\{)\{([A-Za-z_$][\w$]*(?:\.[\w$]+)*)\}(?!\})/g;
1617
2290
  const findAll = (pattern, text) => {
1618
2291
  const regex = new RegExp(pattern.source, "g");
1619
2292
  const found = [];
@@ -1625,13 +2298,18 @@ const paramName = (param) => {
1625
2298
  const binding = target.type === "AssignmentPattern" ? target.left : target.type === "RestElement" ? target.argument : target;
1626
2299
  return binding.type === "Identifier" ? binding.name : void 0;
1627
2300
  };
2301
+ /** True when a placeholder path starts at a parameter, or at `this` (a property of the instance). */
2302
+ const isKnownRoot = (path, names) => {
2303
+ const [root] = path.split(".");
2304
+ return root === "this" || names.includes(root);
2305
+ };
1628
2306
  /**
1629
2307
  * What is wrong with the path of a `{{path}}` placeholder, if anything. `@step` reads the path exactly as written,
1630
2308
  * so spaces around it either fail the parameter lookup or read a property that does not exist.
1631
2309
  */
1632
2310
  const namedProblem = (path, names) => {
1633
2311
  const trimmed = path.trim();
1634
- const isParameter = (value) => names.includes(value.split(".")[0]);
2312
+ const isParameter = (value) => isKnownRoot(value, names);
1635
2313
  if (trimmed !== path && isParameter(trimmed)) return "whitespace";
1636
2314
  return trimmed === path && isParameter(path) ? void 0 : "unknownParameter";
1637
2315
  };
@@ -1713,14 +2391,14 @@ const rule$1 = {
1713
2391
  });
1714
2392
  }
1715
2393
  for (const match of findAll(SINGLE_BRACES, raw)) {
1716
- const placeholder = match[2];
1717
- const from = start + match.index + match[1].length;
2394
+ const placeholder = match[1];
2395
+ const from = start + match.index;
1718
2396
  const range = [from, from + placeholder.length + 2];
1719
2397
  const data = {
1720
2398
  found: `{${placeholder}}`,
1721
2399
  expected: `{{${placeholder}}}`
1722
2400
  };
1723
- if (names.includes(placeholder.split(".")[0])) context.report({
2401
+ if (isKnownRoot(placeholder, names)) context.report({
1724
2402
  node: description,
1725
2403
  messageId: "singleBraces",
1726
2404
  data,
@@ -1741,19 +2419,23 @@ const STEP_LAYERS = /* @__PURE__ */ new Set([
1741
2419
  "asserter",
1742
2420
  "scenario"
1743
2421
  ]);
2422
+ const FUNCTION_VALUES = /* @__PURE__ */ new Set(["ArrowFunctionExpression", "FunctionExpression"]);
2423
+ /** Public instance members are steps; static members are helpers (such as factories). */
2424
+ const isPublicInstance = (member) => !member.static && member.key.type !== "PrivateIdentifier" && member.accessibility !== "private" && member.accessibility !== "protected";
1744
2425
  // src/rules/index.ts
1745
2426
  const rules = {
1746
- "architecture-boundaries": rule$12,
1747
- "class-matches-filename": rule$11,
2427
+ "architecture-boundaries": rule$13,
2428
+ "class-matches-filename": rule$12,
2429
+ "director-composes-builders": rule$11,
1748
2430
  "expect-from-support": rule$10,
1749
2431
  "file-naming": rule$9,
1750
2432
  "lines-between-class-members": rule$8,
1751
- "no-direct-construction-in-tests": rule$7,
1752
- "no-expect-in-tests": rule$6,
1753
- "no-hard-waits": rule$5,
1754
- "no-nested-polling": rule$4,
1755
- "padding-lines": rule$3,
1756
- "private-members-last": rule$2,
2433
+ "member-ordering": rule$7,
2434
+ "no-direct-construction-in-tests": rule$6,
2435
+ "no-expect-in-tests": rule$5,
2436
+ "no-hard-waits": rule$4,
2437
+ "no-nested-polling": rule$3,
2438
+ "padding-lines": rule$2,
1757
2439
  "step-placeholders": rule$1,
1758
2440
  "step-required": {
1759
2441
  meta: {
@@ -1763,24 +2445,35 @@ const rules = {
1763
2445
  url: docsUrl("step-required")
1764
2446
  },
1765
2447
  schema: [],
1766
- messages: { missingStep: "Public method '{{method}}' in a {{layer}} needs a @step decorator so it is visible in the report." }
2448
+ messages: {
2449
+ missingStep: "Public method '{{method}}' in a {{layer}} needs a @step decorator so it is visible in the report.",
2450
+ functionProperty: "Public function property '{{method}}' in a {{layer}} cannot carry a @step decorator; make it a method with @step."
2451
+ }
1767
2452
  },
1768
2453
  create(context) {
1769
2454
  const conventions = conventionsFor(context);
1770
2455
  const info = classify(context.filename, conventions, rootFor(context, conventions));
1771
2456
  const layer = info?.kind === "top-scenario" ? "scenario" : info?.layer;
1772
2457
  if (layer === void 0 || !STEP_LAYERS.has(layer)) return {};
1773
- return { MethodDefinition(node) {
1774
- if (node.kind !== "method" || node.key.type === "PrivateIdentifier" || node.accessibility === "private" || node.accessibility === "protected" || node.value.type === "TSEmptyBodyFunctionExpression" || node.decorators.some((decorator) => isStepDecorator(decorator, conventions.stepDecorators))) return;
2458
+ const report = (key, messageId) => {
1775
2459
  context.report({
1776
- node: node.key,
1777
- messageId: "missingStep",
2460
+ node: key,
2461
+ messageId,
1778
2462
  data: {
1779
- method: context.sourceCode.getText(node.key),
2463
+ method: context.sourceCode.getText(key),
1780
2464
  layer
1781
2465
  }
1782
2466
  });
1783
- } };
2467
+ };
2468
+ return {
2469
+ MethodDefinition(node) {
2470
+ if (node.kind !== "method" || !isPublicInstance(node) || node.value.type === "TSEmptyBodyFunctionExpression" || node.decorators.some((decorator) => isStepDecorator(decorator, conventions.stepDecorators))) return;
2471
+ report(node.key, "missingStep");
2472
+ },
2473
+ PropertyDefinition(node) {
2474
+ if (isPublicInstance(node) && node.value && FUNCTION_VALUES.has(node.value.type)) report(node.key, "functionProperty");
2475
+ }
2476
+ };
1784
2477
  }
1785
2478
  }
1786
2479
  };
@@ -1806,4 +2499,4 @@ Object.defineProperty(exports, "rules", {
1806
2499
  }
1807
2500
  });
1808
2501
 
1809
- //# sourceMappingURL=rules-COk7kmEU.cjs.map
2502
+ //# sourceMappingURL=rules-5VZcw4ds.cjs.map