@memberjunction/standards 6.1.4 → 6.2.0-edge.1

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
@@ -107,6 +107,7 @@ Every registered standard, when it was introduced, and what this repo does with
107
107
  | Id | Since | What it enforces |
108
108
  |---|---|---|
109
109
  | `ui-layers` | 6.0.0 | The four-layer UI architecture — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/UI_LAYERING_GUIDE.md). Widgets may not import `@angular/router` or MJ Explorer, and may not construct a global-provider `RunView`/`Metadata`. Packages opt in with `"mjUILayer"` in their own `package.json`. |
110
+ | `naming-conventions` | 6.2.0 | MJ's inverted naming convention — [guide](https://github.com/MemberJunction/MJ/blob/next/guides/NAMING_CONVENTIONS_GUIDE.md). Public class members and the whole exported API surface are PascalCase — including the members of an exported interface, type literal or enum, and public constructor parameter properties; `private` members are camelCase. `protected` is exempt (MJ base classes declare PascalCase extension points). Framework contracts — Angular `ng*` hooks, oclif command members, base-class overrides, SCREAMING_SNAKE constants — are exempt automatically. Severity says whether a compatible fix exists: anything a `@deprecated` delegating stub can fix is an error; members of an exported data shape are a warn, since an interface has no runtime carrier for a stub (`enforceTypeMembers` opts into the type-only break). Anything tagged `@deprecated` is exempt. Marker: `case-violation-ok-legacy-back-compat`. |
110
111
 
111
112
  ## Adding a standard
112
113
 
@@ -124,6 +125,19 @@ Every registered standard, when it was introduced, and what this repo does with
124
125
  is one more thing that can conflict with their tree. The only non-trivial thing it needed was
125
126
  semver comparison, which is twenty lines.
126
127
 
128
+ The one exception is `typescript`, declared as an **optional peer** for `naming-conventions`, which
129
+ needs a real parser: the naming rule turns on visibility modifiers, decorators and heritage clauses,
130
+ and a text-matching version of it produces false positives in both directions. Optional-peer rather
131
+ than a hard dependency so the host repo pins its own version — any repo with TypeScript source
132
+ already has the compiler, and one without it has nothing for that check to read, so it reports a
133
+ skip instead of failing to install. Every other check stays dependency-free.
134
+
135
+ **Severity can vary within one check.** A `Violation` may carry its own `Severity`, overriding the
136
+ check's configured one. `naming-conventions` uses it to hard-fail the packages a repo has already
137
+ cleaned while only reporting the rest — a rule with a five-figure tail has no usable single
138
+ severity, because `error` is unadoptable until the tail is gone and `warn` does nothing to stop it
139
+ growing. Omit the field and a finding takes its check's severity, which is what `ui-layers` does.
140
+
127
141
  **Comments are stripped before matching.** MJ source documents itself heavily — a JSDoc block
128
142
  explaining "this calls `new RunView()` on the global provider" is a comment about a violation, not
129
143
  a violation. A gate that cannot tell the difference gets switched off.
package/bin/run.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * Argument handling is deliberately minimal — anyone who wants rich flags can install the CLI.
13
13
  */
14
14
  import { LoadConfig, HasConfig, RunStandards, FormatSummary, ExitCodeFor, Adopt, STANDARD_CHECKS, IsNewerThan } from '../dist/index.js';
15
- import { readFileSync } from 'node:fs';
15
+ import { readFileSync, writeFileSync } from 'node:fs';
16
16
  import { dirname, join } from 'node:path';
17
17
  import { fileURLToPath } from 'node:url';
18
18
 
@@ -35,6 +35,7 @@ function usage() {
35
35
  check run the standards this repo has adopted
36
36
  --strict treat warnings as errors
37
37
  --quiet summary line only
38
+ --json <file> also write every finding to <file> as JSON
38
39
 
39
40
  adopt write .mj-standards.json and optional scaffolding
40
41
  --ci github also write a GitHub Actions workflow
@@ -58,6 +59,25 @@ if (command === 'check') {
58
59
  const config = LoadConfig(repoRoot);
59
60
  const summary = await RunStandards(repoRoot, config);
60
61
  if (!flag('quiet')) console.log(FormatSummary(summary, config));
62
+
63
+ // The terminal view is capped on purpose, so a standard adopted against a large codebase needs
64
+ // somewhere the COMPLETE list still lives — a worklist to burn down, and something CI can keep
65
+ // as an artifact rather than asking a reader to scroll a truncated log.
66
+ const jsonPath = value('json');
67
+ if (jsonPath) {
68
+ const findings = summary.Outcomes.flatMap((o) =>
69
+ o.Violations.map((v) => ({
70
+ Check: o.Check.Id,
71
+ Severity: v.Severity ?? o.Severity,
72
+ File: v.File,
73
+ Line: v.Line,
74
+ Package: v.Package ?? null,
75
+ Message: v.Message,
76
+ })),
77
+ );
78
+ writeFileSync(jsonPath, `${JSON.stringify({ ErrorCount: summary.ErrorCount, WarningCount: summary.WarningCount, Findings: findings }, null, 2)}\n`);
79
+ if (!flag('quiet')) console.log(`\nWrote ${findings.length} finding(s) to ${jsonPath}`);
80
+ }
61
81
  const failed = ExitCodeFor(summary) !== 0 || (flag('strict') && summary.WarningCount > 0);
62
82
  process.exit(failed ? 1 : 0);
63
83
  } else if (command === 'adopt') {
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @fileoverview The naming-convention standard.
3
+ *
4
+ * Enforces the convention documented in the MJ repo's `.claude/rules/typescript-style.md`, which is
5
+ * deliberately inverted from ordinary TypeScript style:
6
+ *
7
+ * public class members PascalCase `public IsLoading`, `@Input() QueryId`
8
+ * private class members camelCase `private destroy$`, `private _internalState`
9
+ * exported functions PascalCase `export function EscapeSQLString()`
10
+ * exported types PascalCase classes, interfaces, type aliases, enums
11
+ *
12
+ * ## Why an AST and not a regex
13
+ *
14
+ * The rule keys off information only a parser has. Visibility is the obvious part — TypeScript's
15
+ * default is *public*, so `foo()` with no modifier is a public member and must be PascalCase, which
16
+ * no regex can tell from a local function. But the exemptions matter more: whether a member
17
+ * implements a framework contract depends on its class's heritage clause, and whether it carries
18
+ * `@HostListener` depends on its decorators. A text-matching gate gets those wrong in both
19
+ * directions, and a gate with false positives gets switched off.
20
+ *
21
+ * Parsing is syntax-only — `createSourceFile` per file, no `Program`, no type checker. There is no
22
+ * root tsconfig in MJ that could build a repo-wide `Program` (the two at the root are bare
23
+ * `compilerOptions` bases with no `include`/`references`), and a `Program` per package tsconfig
24
+ * across 300+ packages is far too slow for a PR gate. Everything this rule needs is syntactic, so a
25
+ * full-repo pass over ~7,900 files runs in well under a minute (about 44s on a developer laptop),
26
+ * against the many minutes a type-aware pass would take.
27
+ *
28
+ * ## What it deliberately does not check
29
+ *
30
+ * - **`protected` members.** MJ's own base classes declare PascalCase protected extension points —
31
+ * `BaseAction.InternalRunAction` (overridden 300+ times), `BaseEngine.AdditionalLoading`,
32
+ * `BaseResourceComponent.OnQueryParamsChanged`, `ProviderToUse`. That is the template-method
33
+ * pattern, it is load-bearing, and subclasses cannot deviate from the parent's casing. The
34
+ * documented "camelCase for private/protected" rule is simply wrong for the protected half.
35
+ *
36
+ * Constructor parameter properties and interface / type-literal members WERE on this list while the
37
+ * rule was being rolled out. Both are checked now — `checkParameterProperties` and
38
+ * `checkTypeMembers` — and both are covered by tests.
39
+ *
40
+ * @module @memberjunction/standards
41
+ */
42
+ import type * as TSApi from 'typescript';
43
+ import type { StandardCheck } from '../types.js';
44
+ type TypeScriptApi = typeof TSApi;
45
+ /** `Foo`, `FooBar`, `HTTPClient` — an initial capital and nothing but letters and digits after. */
46
+ export declare function IsPascalCase(name: string): boolean;
47
+ /**
48
+ * `MAX_ROWS`, `PREFS_KEY`, `URL` — a constant, not a misnamed member.
49
+ *
50
+ * Accepted wherever a capital would otherwise be a violation, because SCREAMING_SNAKE for constants
51
+ * is universal and MJ uses it heavily: 419 private `static readonly` fields and 700+ exported
52
+ * `const`s. A literal reading of "private members are camelCase" would flag every one of them, and
53
+ * that alone would have made the rule unadoptable.
54
+ */
55
+ export declare function IsScreamingSnake(name: string): boolean;
56
+ /**
57
+ * The PascalCase form of a name, for the "rename to …" half of a message.
58
+ *
59
+ * Splits on `_` and `-` so `output_config` suggests `OutputConfig` rather than `Output_config`,
60
+ * which is what a naive first-character uppercase produces and which is not PascalCase at all — a
61
+ * suggestion that is itself a violation teaches the reader the wrong rule.
62
+ */
63
+ export declare function SuggestPascalCase(name: string): string;
64
+ /**
65
+ * `destroy$`, `_internalState` — the shape a private member must have.
66
+ *
67
+ * The optional leading underscore is deliberate: `private _config` paired with `public get Config()`
68
+ * is the documented backing-field idiom and appears ~1,960 times. Both it and the bare form are
69
+ * correct; this check does not try to normalise between them.
70
+ */
71
+ export declare function IsPrivateShaped(name: string): boolean;
72
+ /** One finding, before it is given a file and a package. */
73
+ interface Finding {
74
+ Line: number;
75
+ Message: string;
76
+ /**
77
+ * For a finding on the member of an exported type: the declaration that owns it.
78
+ *
79
+ * Present only when the owning type is a plain data shape — not one a class implements, and so
80
+ * with no runtime carrier that could hold both an old and a new name. `Run` uses it to decide
81
+ * whether this finding has a compatible fix at all; see the severity model there.
82
+ */
83
+ DataShapeOwner?: string;
84
+ }
85
+ /** Everything a file needs in order to be judged. */
86
+ interface FileContext {
87
+ Ts: TypeScriptApi;
88
+ Source: TSApi.SourceFile;
89
+ /** Original text, split into lines — allow-markers live in comments, so this is not stripped. */
90
+ Lines: string[];
91
+ /** Member names declared by classes that something in the repo extends. */
92
+ Contract: ReadonlySet<string>;
93
+ /** Names of interfaces some class in the repo `implements`. */
94
+ Implemented: ReadonlySet<string>;
95
+ /** Mutable tally of findings dropped because their declaration is `@deprecated`. */
96
+ DeprecatedSuppressed: {
97
+ Count: number;
98
+ };
99
+ AllowedNames: ReadonlySet<string>;
100
+ AllowedPrefixes: readonly string[];
101
+ }
102
+ /** Judge one file. */
103
+ export declare function CheckSourceFile(context: FileContext): Finding[];
104
+ /** The registered naming-convention standard. */
105
+ export declare const NamingConventionsCheck: StandardCheck;
106
+ /**
107
+ * Packages that currently have zero violations.
108
+ *
109
+ * Progress tracking for a cleanup campaign: which packages are done. Answers it by running the
110
+ * rules, never by writing to the repo and reverting — the same discipline as
111
+ * `ProbeUndeclaredPackages` in `ui-layers`.
112
+ */
113
+ export declare function FindCleanPackages(repoRoot: string, roots: string[]): Promise<string[]>;
114
+ export {};
115
+ //# sourceMappingURL=naming-conventions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"naming-conventions.d.ts","sourceRoot":"","sources":["../../src/checks/naming-conventions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAIH,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAuC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