@tianjos/eslint-plugin-elegant 0.3.1 → 0.3.2
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 +65 -41
- package/dist/utils/createRule.d.ts +2 -1
- package/dist/utils/createRule.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,47 +87,71 @@ The `recommended` config enables every custom rule plus the native
|
|
|
87
87
|
|
|
88
88
|
### Rule details
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
90
|
+
#### `no-boolean-param`
|
|
91
|
+
|
|
92
|
+
A boolean argument almost always means the callee does two things. Prefer two
|
|
93
|
+
intention-revealing functions or an options object. Flags both annotated
|
|
94
|
+
(`flag: boolean`) and boolean-defaulted (`flag = false`) parameters.
|
|
95
|
+
|
|
96
|
+
#### `max-class-methods`
|
|
97
|
+
|
|
98
|
+
A proxy for the Single Responsibility Principle. Constructors are not counted;
|
|
99
|
+
getters and setters are. Configurable via `{ max: number }` (default `10`).
|
|
100
|
+
|
|
101
|
+
#### `no-type-assertion`
|
|
102
|
+
|
|
103
|
+
Assertions silence the type checker. Reach for a type guard, a generic, or a
|
|
104
|
+
correctly typed value instead. `as const` is permitted because it narrows rather
|
|
105
|
+
than widens.
|
|
106
|
+
|
|
107
|
+
#### `no-null-return`
|
|
108
|
+
|
|
109
|
+
Keeps absence out of return values; model it with an explicit domain type or
|
|
110
|
+
throw.
|
|
111
|
+
|
|
112
|
+
#### `no-public-mutable-props`
|
|
113
|
+
|
|
114
|
+
Public state should be `readonly` so callers cannot break an aggregate's
|
|
115
|
+
invariants. `private`/`protected` members and `readonly` members are allowed.
|
|
116
|
+
|
|
117
|
+
#### `no-logic-in-constructor`
|
|
118
|
+
|
|
119
|
+
A constructor should only wire arguments to fields. Validation, transformation,
|
|
120
|
+
and I/O belong in a static factory or a method, keeping object construction
|
|
121
|
+
predictable. Parameter properties (`constructor(private readonly x: T)`) and a
|
|
122
|
+
leading `super(...)` are allowed; computed right-hand sides (`this.x = x * 2`,
|
|
123
|
+
`this.items = items.slice()`) and any non-assignment statement are flagged.
|
|
124
|
+
|
|
125
|
+
#### `no-getters-setters`
|
|
126
|
+
|
|
127
|
+
Getters and setters turn objects into data bags; prefer methods that expose
|
|
128
|
+
behavior. Native `get`/`set` accessors (and `accessor` fields) are always
|
|
129
|
+
flagged. The opt-in `{ methods: true }` option also flags conventional
|
|
130
|
+
`getX`/`setX` methods — useful for strict Elegant Objects style, but noisy
|
|
131
|
+
around repositories and framework hooks, so it stays off in `recommended`.
|
|
132
|
+
|
|
133
|
+
#### `no-instanceof`
|
|
134
|
+
|
|
135
|
+
`instanceof` is type discrimination that belongs inside a polymorphic method on
|
|
136
|
+
the object. Pairs with `no-type-assertion` to keep type-based branching out of
|
|
137
|
+
the codebase.
|
|
138
|
+
|
|
139
|
+
#### `no-static-members`
|
|
140
|
+
|
|
141
|
+
Static state and behavior cannot be injected, substituted, or mocked. Prefer
|
|
142
|
+
instances (with dependency injection) and a module-level `const` for shared
|
|
143
|
+
values. The `{ allowReadonly: true }` option permits `static readonly`
|
|
144
|
+
constants. Note this also flags `static` factory methods (`static create()`),
|
|
145
|
+
which are common; relax per-file if your design relies on them.
|
|
146
|
+
|
|
147
|
+
#### `no-null`
|
|
148
|
+
|
|
149
|
+
Completes `no-null-return` by banning the `null` literal as a value everywhere
|
|
150
|
+
(`const x = null`, `x === null`, `fn(null)`), pushing absence into explicit types
|
|
151
|
+
or `undefined`. `null` in type positions (`string | null`) and a direct
|
|
152
|
+
`return null` (owned by `no-null-return`) are left alone. This is strict and will
|
|
153
|
+
flag idioms like `JSON.stringify(x, null, 2)` — relax it in the files where you
|
|
154
|
+
interoperate with null-based APIs.
|
|
131
155
|
|
|
132
156
|
## Configuration
|
|
133
157
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Factory for all rules in this plugin. Centralises the docs URL convention so
|
|
4
|
-
* every rule links back to its
|
|
4
|
+
* every rule links back to its section in the README. The anchor matches the
|
|
5
|
+
* `#### \`<name>\`` heading GitHub generates for each rule under "Rule details".
|
|
5
6
|
*/
|
|
6
7
|
export declare const createRule: <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener> & {
|
|
7
8
|
name: string;
|
package/dist/utils/createRule.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.createRule = void 0;
|
|
|
4
4
|
const utils_1 = require("@typescript-eslint/utils");
|
|
5
5
|
/**
|
|
6
6
|
* Factory for all rules in this plugin. Centralises the docs URL convention so
|
|
7
|
-
* every rule links back to its
|
|
7
|
+
* every rule links back to its section in the README. The anchor matches the
|
|
8
|
+
* `#### \`<name>\`` heading GitHub generates for each rule under "Rule details".
|
|
8
9
|
*/
|
|
9
|
-
exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/tianjos/eslint-plugin-elegant/blob/main/
|
|
10
|
+
exports.createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/tianjos/eslint-plugin-elegant/blob/main/README.md#${name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tianjos/eslint-plugin-elegant",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Opinionated ESLint rules for elegant, behavior-rich TypeScript: no flag arguments, no type assertions, no null returns, no public mutable state, and small focused classes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|