@tianjos/eslint-plugin-elegant 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +38 -13
  2. package/dist/index.js +27 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -63,14 +63,25 @@ export default [
63
63
  ];
64
64
  ```
65
65
 
66
+ Adopting this on a codebase that already exists? Spread
67
+ `elegant.configs.starter` instead — same rules, with the four heaviest demoted
68
+ so the first run gives you a list you can work through. See
69
+ [Adopting on an existing codebase](#adopting-on-an-existing-codebase).
70
+
66
71
  A complete, copy-pasteable example (including test-file overrides) lives in
67
72
  [`eslint.config.example.mjs`](./eslint.config.example.mjs).
68
73
 
69
74
  ## Rules
70
75
 
71
- The `recommended` config enables every custom rule plus two native ones,
72
- [`max-params`](https://eslint.org/docs/latest/rules/max-params) and
73
- [`no-else-return`](https://eslint.org/docs/latest/rules/no-else-return).
76
+ The plugin exports two configs, both carrying every rule below plus two native
77
+ ones, [`max-params`](https://eslint.org/docs/latest/rules/max-params) and
78
+ [`no-else-return`](https://eslint.org/docs/latest/rules/no-else-return):
79
+
80
+ - **`recommended`** — the severities in the table below. What the plugin
81
+ argues for.
82
+ - **`starter`** — the same rules with the four heaviest demoted, for adopting
83
+ on a codebase that already exists. See
84
+ [Adopting on an existing codebase](#adopting-on-an-existing-codebase).
74
85
 
75
86
  | Rule | Source | What it catches | `recommended` |
76
87
  | -------------------------------------- | ------ | ------------------------------------------------------------------------------- | ------------- |
@@ -768,19 +779,31 @@ value from the wire format of a database column. `no-type-assertion` counts
768
779
  `x as unknown as T` twice, once per assertion, which is arguably correct.
769
780
 
770
781
  None of that makes them wrong — it makes them rules you adopt on purpose
771
- rather than inherit. **Enable the preset, then take the top of that table back
772
- to `warn` or `off` and work down it.** The rules below `no-type-assertion` sum
773
- to 1.75 per file, which is a starting point you can actually clear:
782
+ rather than inherit. That is what `starter` is: every rule `recommended`
783
+ carries, with those four demoted, leaving the 1.75 per file below them — a
784
+ list somebody can actually work through.
774
785
 
775
786
  ```js
776
787
  rules: {
777
- ...elegant.configs.recommended.rules,
788
+ ...elegant.configs.starter.rules,
789
+ }
790
+ ```
778
791
 
779
- // The four that need a plan of their own. Re-enable one at a time.
780
- 'elegant/no-comments-in-function-body': 'off',
781
- 'elegant/no-interpolated-log-message': 'warn',
782
- 'elegant/no-null': 'warn',
783
- 'elegant/no-type-assertion': 'warn',
792
+ | | `recommended` | `starter` |
793
+ | --- | --- | --- |
794
+ | `no-comments-in-function-body` | `error` | `off` |
795
+ | `no-interpolated-log-message` | `error` | `warn` |
796
+ | `no-null` | `error` | `warn` |
797
+ | `no-type-assertion` | `error` | `warn` |
798
+ | everything else | unchanged | unchanged |
799
+
800
+ Promote them back one at a time as you clear them, and switch to
801
+ `recommended` once nothing is left:
802
+
803
+ ```js
804
+ rules: {
805
+ ...elegant.configs.starter.rules,
806
+ 'elegant/no-null': 'error', // cleared, so hold the line
784
807
  }
785
808
  ```
786
809
 
@@ -813,7 +836,9 @@ block scoped to your spec globs:
813
836
  The package ships a single CommonJS build that is consumable as both
814
837
  `require('@tianjos/eslint-plugin-elegant')` and an ESM
815
838
  `import elegant from '@tianjos/eslint-plugin-elegant'`. The exported object
816
- exposes `{ meta, rules, configs }`.
839
+ exposes `{ meta, rules, configs }`, where `configs` holds `recommended` and
840
+ `starter`. All three load paths are exercised against the built output by
841
+ `tests/dist.test.ts`.
817
842
 
818
843
  ## Prior art
819
844
 
package/dist/index.js CHANGED
@@ -88,5 +88,32 @@ plugin.configs.recommended = {
88
88
  'no-else-return': ['error', { allowElseIf: false }],
89
89
  },
90
90
  };
91
+ /**
92
+ * The four rules that carry most of the friction on code that already exists.
93
+ * Each encodes a defensible position whose boundary this plugin cannot see —
94
+ * a comment that wants to be a function, a logging convention already chosen,
95
+ * `null` as the wire format of a column, an assertion widening a type — so on
96
+ * a mature codebase they report by the thousand. `recommended` keeps them at
97
+ * `error` on purpose; `starter` is the door in.
98
+ */
99
+ const NOISIEST = {
100
+ 'elegant/no-comments-in-function-body': 'off',
101
+ 'elegant/no-interpolated-log-message': 'warn',
102
+ 'elegant/no-null': 'warn',
103
+ 'elegant/no-type-assertion': 'warn',
104
+ };
105
+ /**
106
+ * Every rule `recommended` carries, with the four heaviest demoted so the
107
+ * first run on an existing codebase produces a list somebody can work through.
108
+ * Promote them back one at a time; see "Adopting on an existing codebase".
109
+ */
110
+ plugin.configs.starter = {
111
+ name: 'elegant/starter',
112
+ plugins: { elegant: plugin },
113
+ rules: {
114
+ ...plugin.configs.recommended.rules,
115
+ ...NOISIEST,
116
+ },
117
+ };
91
118
  plugin.default = plugin;
92
119
  module.exports = plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tianjos/eslint-plugin-elegant",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Opinionated ESLint rules for elegant, behavior-rich TypeScript: honest types, encapsulated state, small uncoupled classes, guard-clause flow, and structured logging. Built for NestJS and DDD codebases.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -43,7 +43,7 @@
43
43
  "build": "tsc -p tsconfig.json",
44
44
  "lint": "npm run build && eslint .",
45
45
  "typecheck": "tsc -p tsconfig.test.json",
46
- "test": "jest",
46
+ "test": "npm run build && jest",
47
47
  "release": "standard-version --release-as minor",
48
48
  "release:patch": "standard-version --release-as patch",
49
49
  "prepublishOnly": "npm run build && npm test"