sadist 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,354 @@
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You.
80
+ For purposes of this definition, "control" means (a) the power,
81
+ direct or indirect, to cause the direction or management of such
82
+ entity, whether by contract or otherwise, or (b) ownership of more
83
+ than fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+
87
+ 2. License Grants and Conditions
88
+ --------------------------------
89
+
90
+ 2.1. Grants. Each Contributor hereby grants You a world-wide,
91
+ royalty-free, non-exclusive license:
92
+
93
+ (a) under intellectual property rights (other than patent or
94
+ trademark) Licensable by such Contributor to use, reproduce,
95
+ make available, modify, display, perform, distribute, and
96
+ otherwise exploit its Contributions, either on an unmodified
97
+ basis, with Modifications, or as part of a Larger Work; and
98
+
99
+ (b) under Patent Claims of such Contributor to make, use, sell,
100
+ offer for sale, have made, import, and otherwise transfer
101
+ either its Contributions or its Contributor Version.
102
+
103
+ 2.2. Effective Date. The licenses granted in Section 2.1 with respect
104
+ to any Contribution become effective for each Contribution on the
105
+ date the Contributor first distributes such Contribution.
106
+
107
+ 2.3. Limitations on Grant Scope. The licenses granted in this Section 2
108
+ are the only rights granted under this License. No additional
109
+ rights or licenses will be implied from the distribution or
110
+ licensing of Covered Software under this License. Notwithstanding
111
+ Section 2.1(b) above, no patent license is granted by a
112
+ Contributor:
113
+
114
+ (a) for any code that a Contributor has removed from Covered
115
+ Software; or
116
+
117
+ (b) for infringements caused by: (i) Your and any other third
118
+ party's modifications of Covered Software, or (ii) the
119
+ combination of its Contributions with other software (except
120
+ as part of its Contributor Version); or
121
+
122
+ (c) under Patent Claims infringed by Covered Software in the
123
+ absence of its Contributions.
124
+
125
+ This License does not grant any rights in the trademarks, service
126
+ marks, or logos of any Contributor (except as may be necessary to
127
+ comply with the notice requirements in Section 3.4).
128
+
129
+ 2.4. Subsequent Licenses. No Contributor makes additional grants as a
130
+ result of Your choice to distribute the Covered Software under a
131
+ subsequent version of this License (see Section 10.2) or under the
132
+ terms of a Secondary License (if permitted under the terms of
133
+ Section 3.3).
134
+
135
+ 2.5. Representation. Each Contributor represents that the Contributor
136
+ believes its Contributions are its original creation(s) or it has
137
+ sufficient rights to grant the rights to its Contributions conveyed
138
+ by this License.
139
+
140
+ 2.6. Fair Use. This License is not intended to limit any rights You
141
+ have under applicable copyright doctrines of fair use, fair
142
+ dealing, or other equivalents.
143
+
144
+ 2.7. Conditions. Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the
145
+ licenses granted in Section 2.1.
146
+
147
+
148
+ 3. Responsibilities
149
+ -------------------
150
+
151
+ 3.1. Distribution of Source Form. All distribution of Covered Software
152
+ in Source Code Form, including any Modifications that You create or
153
+ to which You contribute, must be under the terms of this License.
154
+ You must inform recipients that the Source Code Form of the Covered
155
+ Software is governed by the terms of this License, and how they can
156
+ obtain a copy of this License. You may not attempt to alter or
157
+ restrict the recipients' rights in the Source Code Form.
158
+
159
+ 3.2. Distribution of Executable Form. If You distribute Covered
160
+ Software in Executable Form then:
161
+
162
+ (a) such Covered Software must also be made available in Source
163
+ Code Form, as described in Section 3.1, and You must inform
164
+ recipients of the Executable Form how they can obtain a copy of
165
+ such Source Code Form by reasonable means in a timely manner,
166
+ at a charge no more than the cost of distribution to the
167
+ recipient; and
168
+
169
+ (b) You may distribute such Executable Form under the terms of
170
+ this License, or sublicense it under different terms, provided
171
+ that the license for the Executable Form does not attempt to
172
+ limit or alter the recipients' rights in the Source Code Form
173
+ under this License.
174
+
175
+ 3.3. Distribution of a Larger Work. You may create and distribute a
176
+ Larger Work under terms of Your choice, provided that You also
177
+ comply with the requirements of this License for the Covered
178
+ Software. If the Larger Work is a combination of Covered Software
179
+ with a work governed by one or more Secondary Licenses, and the
180
+ Covered Software is not Incompatible With Secondary Licenses, this
181
+ License permits You to additionally distribute such Covered
182
+ Software under the terms of such Secondary License(s), so that the
183
+ recipient of the Larger Work may, at their option, further
184
+ distribute the Covered Software under the terms of either this
185
+ License or such Secondary License(s).
186
+
187
+ 3.4. Notices. You may not remove or alter the substance of any license
188
+ notices (including copyright notices, patent notices, disclaimers
189
+ of warranty, or limitations of liability) contained within the
190
+ Source Code Form of the Covered Software, except that You may
191
+ alter any license notices to the extent required to remedy known
192
+ factual inaccuracies.
193
+
194
+ 3.5. Application of Additional Terms. You may choose to offer, and to
195
+ charge a fee for, warranty, support, indemnity or liability
196
+ obligations to one or more recipients of Covered Software.
197
+ However, You may do so only on Your own behalf, and not on behalf
198
+ of any Contributor. You must make it absolutely clear that any
199
+ such warranty, support, indemnity, or liability obligation is
200
+ offered by You alone, and You hereby agree to indemnify every
201
+ Contributor for any liability incurred by such Contributor as a
202
+ result of warranty, support, indemnity or liability terms You
203
+ offer. You may include additional disclaimers of warranty and
204
+ limitations of liability specific to any jurisdiction.
205
+
206
+
207
+ 4. Inability to Comply Due to Statute or Regulation
208
+ ---------------------------------------------------
209
+
210
+ If it is impossible for You to comply with any of the terms of this
211
+ License with respect to some or all of the Covered Software due to
212
+ statute, judicial order, or regulation then You must: (a) comply with
213
+ the terms of this License to the maximum extent possible; and (b)
214
+ describe the limitations and the code they affect. Such description
215
+ must be placed in a text file included with all distributions of the
216
+ Covered Software under this License. Except to the extent prohibited
217
+ by statute or regulation, such description must be sufficiently
218
+ detailed for a recipient of ordinary skill to be able to understand
219
+ it.
220
+
221
+
222
+ 5. Termination
223
+ --------------
224
+
225
+ 5.1. The rights granted under this License will terminate automatically
226
+ if You fail to comply with any of its terms. However, if You
227
+ become compliant, then the rights granted under this License from
228
+ a particular Contributor are reinstated (a) provisionally, unless
229
+ and until such Contributor explicitly and finally terminates Your
230
+ grants, and (b) on an ongoing basis, if such Contributor fails to
231
+ notify You of the non-compliance by some reasonable means prior to
232
+ 60 days after You have come back into compliance. Moreover, Your
233
+ grants from a particular Contributor are reinstated on an ongoing
234
+ basis if such Contributor notifies You of the non-compliance by
235
+ some reasonable means, this is the first time You have received
236
+ notice of non-compliance with this License from such Contributor,
237
+ and You become compliant prior to 30 days after Your receipt of
238
+ the notice.
239
+
240
+ 5.2. If You initiate litigation against any entity by asserting a
241
+ patent infringement claim (excluding declaratory judgment actions,
242
+ counter-claims, and cross-claims) alleging that a Contributor
243
+ Version directly or indirectly infringes any patent, then the
244
+ rights granted to You by any and all Contributors for the Covered
245
+ Software under Section 2.1 of this License shall terminate.
246
+
247
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
248
+ end user license agreements (excluding distributors and resellers)
249
+ which have been validly granted by You or Your distributors under
250
+ this License prior to termination shall survive termination.
251
+
252
+
253
+ 6. Disclaimer of Warranty
254
+ -------------------------
255
+
256
+ Covered Software is provided under this License on an "as is" basis,
257
+ without warranty of any kind, either expressed, implied, or
258
+ statutory, including, without limitation, warranties that the Covered
259
+ Software is free of defects, merchantable, fit for a particular
260
+ purpose or non-infringing. The entire risk as to the quality and
261
+ performance of the Covered Software is with You. Should any Covered
262
+ Software prove defective in any respect, You (not any Contributor)
263
+ assume the cost of any necessary servicing, repair, or correction.
264
+ This disclaimer of warranty constitutes an essential part of this
265
+ License. No use of any Covered Software is authorized under this
266
+ License except under this disclaimer.
267
+
268
+
269
+ 7. Limitation of Liability
270
+ --------------------------
271
+
272
+ Under no circumstances and under no legal theory, whether tort
273
+ (including negligence), contract, or otherwise, shall any Contributor,
274
+ or anyone who distributes Covered Software as permitted above, be
275
+ liable to You for any direct, indirect, special, incidental, or
276
+ consequential damages of any character including, without limitation,
277
+ damages for lost profits, loss of goodwill, work stoppage, computer
278
+ failure or malfunction, or any and all other commercial damages or
279
+ losses, even if such party shall have been informed of the possibility
280
+ of such damages. This limitation of liability shall not apply to
281
+ liability for death or personal injury resulting from such party's
282
+ negligence to the extent applicable law prohibits such limitation.
283
+ Some jurisdictions do not allow the exclusion or limitation of
284
+ incidental or consequential damages, so this exclusion and limitation
285
+ may not apply to You.
286
+
287
+
288
+ 8. Litigation
289
+ -------------
290
+
291
+ Any litigation relating to this License may be brought only in the
292
+ courts of a jurisdiction where the defendant maintains its principal
293
+ place of business and such litigation shall be governed by laws of
294
+ that jurisdiction, without reference to its conflict-of-law
295
+ provisions. Nothing in this Section shall prevent a party's ability to
296
+ bring cross-claims or counter-claims.
297
+
298
+
299
+ 9. Miscellaneous
300
+ ----------------
301
+
302
+ This License represents the complete agreement concerning the subject
303
+ matter hereof. If any provision of this License is held to be
304
+ unenforceable, such provision shall be reformed only to the extent
305
+ necessary to make it enforceable. Any law or regulation which provides
306
+ that the language of a contract shall be construed against the drafter
307
+ shall not be used to construe this License against a Contributor.
308
+
309
+
310
+ 10. Versions of the License
311
+ ---------------------------
312
+
313
+ 10.1. New Versions. Mozilla Foundation is the license steward. Except
314
+ as provided in Section 10.3, no one other than the license steward
315
+ has the right to modify or publish new versions of this License.
316
+ Each version will be given a distinguishing version number.
317
+
318
+ 10.2. Effect of New Versions. You may distribute the Covered Software
319
+ under the terms of the version of the License under which You
320
+ originally received the Covered Software, or under the terms of
321
+ any subsequent version published by the license steward.
322
+
323
+ 10.3. Modified Versions. If you create software not governed by this
324
+ License, and you want to create a new license for such software,
325
+ you may create and use a modified version of this License if you
326
+ rename the license and remove any references to the name of the
327
+ license steward (except to note that such modified license differs
328
+ from this License).
329
+
330
+ 10.4. Distributing Source Code Form that is Incompatible With
331
+ Secondary Licenses. If You choose to distribute Source Code Form
332
+ that is Incompatible With Secondary Licenses under the terms of
333
+ this version of the License, the notice described in Exhibit B of
334
+ this License must be attached.
335
+
336
+ Exhibit A - Source Code Form License Notice
337
+ -------------------------------------------
338
+
339
+ This Source Code Form is subject to the terms of the Mozilla Public
340
+ License, v. 2.0. If a copy of the MPL was not distributed with this
341
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
342
+
343
+ If it is not possible or desirable to put the notice in a
344
+ particular file, then You may include the notice in a location
345
+ (such as a LICENSE file in a relevant directory) where a recipient
346
+ would be likely to look for such a notice.
347
+
348
+ You may add additional accurate notices of copyright ownership.
349
+
350
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
351
+ ----------------------------------------------------------
352
+
353
+ This Source Code Form is "Incompatible With Secondary Licenses",
354
+ as defined by the Mozilla Public License, v. 2.0.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # sadist
2
+
3
+ [![License: MPL-2.0](https://img.shields.io/badge/License-MPL--2.0-blue.svg)](LICENSE)
4
+ [![npm version](https://img.shields.io/npm/v/sadist.svg)](https://www.npmjs.com/package/sadist)
5
+ [![CI](https://github.com/ElBenjaMasLindo/sadist/actions/workflows/ci.yml/badge.svg)](https://github.com/ElBenjaMasLindo/sadist/actions/workflows/ci.yml)
6
+
7
+ A merciless TypeScript code quality gate.
8
+
9
+ `sadist` combines strict `tsc` compilation, exhaustive pattern matching via
10
+ `ts-pattern`, and a small set of architectural ESLint rules into a single
11
+ pre-commit gate. Code either passes all three layers or it doesn't get
12
+ committed — there is no partial pass, no warning-only mode, no override
13
+ flag for convenience.
14
+
15
+ ## Why
16
+
17
+ `any`, silent `null`, unhandled `catch` blocks, and `class` abuse are the
18
+ most common sources of preventable bugs in TypeScript codebases. This isn't
19
+ a style linter that nudges; it's a structural gate that refuses to compile
20
+ or lint code that leaves room for them — see
21
+ [docs/SKILL.md](docs/SKILL.md) for the complete rule set and
22
+ honest coverage (this gate does not, and cannot, catch business-logic bugs;
23
+ only structural ones).
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ npm install --save-dev sadist
29
+ # or
30
+ pnpm add -D sadist
31
+ ```
32
+
33
+ Requires `typescript >=5.4` and `eslint >=9` as peer dependencies (likely already in your project).
34
+
35
+ Create `eslint.config.mjs`:
36
+
37
+ ```js
38
+ import strict from "sadist/config/strict";
39
+ export default [...strict];
40
+ ```
41
+
42
+ Add a gate script to `package.json`:
43
+
44
+ ```json
45
+ {
46
+ "scripts": {
47
+ "lax": "eslint . && tsc --noEmit"
48
+ }
49
+ }
50
+ ```
51
+
52
+ Run the gate:
53
+
54
+ ```bash
55
+ npm run lax
56
+ ```
57
+
58
+ If it passes, commit. If it fails, fix the errors first.
59
+
60
+ ## Usage
61
+
62
+ Example violation of `no-null-in-domain-types`:
63
+
64
+ ```ts
65
+ // ❌ Fails the gate
66
+ type User = {
67
+ id: string;
68
+ email: string | null;
69
+ };
70
+ ```
71
+
72
+ Error output:
73
+
74
+ ```
75
+ src/user.ts:3:10 - error: Domain types must not contain null or undefined. Use Option<T> instead.
76
+ ```
77
+
78
+ Fix with `Option<T>`:
79
+
80
+ ```ts
81
+ // ✅ Passes the gate
82
+ import { Option } from "sadist";
83
+
84
+ type User = {
85
+ id: string;
86
+ email: Option<string>;
87
+ };
88
+ ```
89
+
90
+ ## API
91
+
92
+ ### Rules
93
+
94
+ | Rule | What it blocks |
95
+ |------|----------------|
96
+ | `no-any-in-domain-types` | `any` in type aliases, interfaces, function signatures |
97
+ | `no-null-in-domain-types` | `null`/`undefined` in type aliases, interfaces, properties |
98
+ | `no-primitive-obsession` | Raw primitives (`string`, `number`, `boolean`) in object properties |
99
+ | `no-throw-outside-adapters` | `throw` statements outside `src/adapters/` |
100
+
101
+ ### Config
102
+
103
+ ```js
104
+ import strict from "sadist/config/strict";
105
+ export default [...strict];
106
+ ```
107
+
108
+ Enables all 4 rules as errors. No warning-only mode, no partial overrides.
109
+
110
+ ## Versioning
111
+
112
+ `0.x` — breaking changes allowed in MINOR versions. `1.0.0` means a public API commitment; don't expect it until the rule set is stable.
113
+
114
+ ## Known limitations
115
+
116
+ - Does not catch business-logic bugs (only structural ones)
117
+ - Requires `ts-pattern` for exhaustive pattern matching (not enforced by rules)
118
+ - No autofix for architectural violations (by design)
119
+ - Assumes `src/adapters/` directory exists for throw statements
120
+
121
+ ## Contributing
122
+
123
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for rules on adding new rules and pre-PR checks.
124
+
125
+ ## License
126
+
127
+ [Mozilla Public License 2.0](https://mozilla.org/MPL/2.0/) — behaves like MIT when you
128
+ `npm install` and use it as-is: no copyleft obligation on your code. Only
129
+ applies if you modify sadist's own source files. See [LICENSE](LICENSE) for
130
+ full terms.
@@ -0,0 +1,3 @@
1
+ import type { Linter } from "eslint";
2
+ declare const strictConfig: Linter.Config[];
3
+ export default strictConfig;
@@ -0,0 +1,37 @@
1
+ import { rules } from "../rules/index.js";
2
+ const strictConfig = [
3
+ {
4
+ plugins: {
5
+ sadist: { rules },
6
+ },
7
+ rules: {
8
+ "sadist/no-throw-outside-adapters": "error",
9
+ "sadist/no-null-in-domain-types": "error",
10
+ "sadist/no-single-use-generics": "error",
11
+ "sadist/no-primitive-obsession": "error",
12
+ complexity: ["error", 6],
13
+ "max-lines-per-function": ["error", 20],
14
+ "max-params": ["error", 3],
15
+ "no-restricted-syntax": [
16
+ "error",
17
+ {
18
+ selector: "ClassDeclaration",
19
+ message: "No classes in domain logic. Use functions and discriminated unions.",
20
+ },
21
+ {
22
+ selector: "ClassExpression",
23
+ message: "No classes in domain logic. Use functions and discriminated unions.",
24
+ },
25
+ {
26
+ selector: "TSAnyKeyword",
27
+ message: "No any. Use a specific type.",
28
+ },
29
+ {
30
+ selector: "TSNonNullExpression",
31
+ message: "No non-null assertions (!). Handle the nullable case explicitly.",
32
+ },
33
+ ],
34
+ },
35
+ },
36
+ ];
37
+ export default strictConfig;
@@ -0,0 +1,13 @@
1
+ export type Option<T> = {
2
+ some: true;
3
+ value: T;
4
+ } | {
5
+ some: false;
6
+ };
7
+ export type Result<T, E> = {
8
+ ok: true;
9
+ value: T;
10
+ } | {
11
+ ok: false;
12
+ error: E;
13
+ };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Rule } from "eslint";
2
+ export declare const rules: Record<string, Rule.RuleModule>;
@@ -0,0 +1,10 @@
1
+ import noThrowOutsideAdapters from "./no-throw-outside-adapters.js";
2
+ import noNullInDomainTypes from "./no-null-in-domain-types.js";
3
+ import noSingleUseGenerics from "./no-single-use-generics.js";
4
+ import noPrimitiveObsession from "./no-primitive-obsession.js";
5
+ export const rules = {
6
+ "no-throw-outside-adapters": noThrowOutsideAdapters,
7
+ "no-null-in-domain-types": noNullInDomainTypes,
8
+ "no-single-use-generics": noSingleUseGenerics,
9
+ "no-primitive-obsession": noPrimitiveObsession,
10
+ };
@@ -0,0 +1,22 @@
1
+ import type { Rule } from "eslint";
2
+ declare const noNullInDomainTypes: {
3
+ meta: {
4
+ type: "problem";
5
+ docs: {
6
+ description: string;
7
+ };
8
+ schema: never[];
9
+ };
10
+ create(context: Rule.RuleContext): {
11
+ "TSTypeAliasDeclaration TSNullKeyword"?: never;
12
+ "TSTypeAliasDeclaration TSUndefinedKeyword"?: never;
13
+ "TSInterfaceDeclaration TSNullKeyword"?: never;
14
+ "TSInterfaceDeclaration TSUndefinedKeyword"?: never;
15
+ } | {
16
+ "TSTypeAliasDeclaration TSNullKeyword": (node: Rule.Node) => void;
17
+ "TSTypeAliasDeclaration TSUndefinedKeyword": (node: Rule.Node) => void;
18
+ "TSInterfaceDeclaration TSNullKeyword": (node: Rule.Node) => void;
19
+ "TSInterfaceDeclaration TSUndefinedKeyword": (node: Rule.Node) => void;
20
+ };
21
+ };
22
+ export default noNullInDomainTypes;
@@ -0,0 +1,29 @@
1
+ const noNullInDomainTypes = {
2
+ meta: {
3
+ type: "problem",
4
+ docs: {
5
+ description: "No null or undefined in type aliases or interfaces outside src/adapters/.",
6
+ },
7
+ schema: [],
8
+ },
9
+ create(context) {
10
+ const filename = context.filename ?? context.getFilename();
11
+ if (filename.includes("/adapters/"))
12
+ return {};
13
+ function report(msg) {
14
+ return (node) => {
15
+ context.report({
16
+ node,
17
+ message: `No ${msg} in domain types. Use Option<T> instead.`,
18
+ });
19
+ };
20
+ }
21
+ return {
22
+ "TSTypeAliasDeclaration TSNullKeyword": report("null"),
23
+ "TSTypeAliasDeclaration TSUndefinedKeyword": report("undefined"),
24
+ "TSInterfaceDeclaration TSNullKeyword": report("null"),
25
+ "TSInterfaceDeclaration TSUndefinedKeyword": report("undefined"),
26
+ };
27
+ },
28
+ };
29
+ export default noNullInDomainTypes;
@@ -0,0 +1,22 @@
1
+ import type { Rule } from "eslint";
2
+ type TSPropertyNode = Rule.Node & {
3
+ key?: Record<string, unknown>;
4
+ typeAnnotation?: {
5
+ typeAnnotation?: {
6
+ type: string;
7
+ };
8
+ };
9
+ };
10
+ declare const noPrimitiveObsession: {
11
+ meta: {
12
+ type: "problem";
13
+ docs: {
14
+ description: string;
15
+ };
16
+ schema: never[];
17
+ };
18
+ create(context: Rule.RuleContext): {
19
+ TSPropertySignature(node: TSPropertyNode): void;
20
+ };
21
+ };
22
+ export default noPrimitiveObsession;
@@ -0,0 +1,37 @@
1
+ function getIdName(node) {
2
+ const key = node.key;
3
+ return key?.name?.endsWith("Id") ? key.name : null;
4
+ }
5
+ function isBarePrimitive(node) {
6
+ return node.typeAnnotation?.typeAnnotation?.type === "TSStringKeyword"
7
+ || node.typeAnnotation?.typeAnnotation?.type === "TSNumberKeyword";
8
+ }
9
+ function isBarePrimitiveId(node) {
10
+ const name = getIdName(node);
11
+ if (!name)
12
+ return null;
13
+ return isBarePrimitive(node) ? name : null;
14
+ }
15
+ const noPrimitiveObsession = {
16
+ meta: {
17
+ type: "problem",
18
+ docs: {
19
+ description: "ID properties must use branded types, not bare primitives.",
20
+ },
21
+ schema: [],
22
+ },
23
+ create(context) {
24
+ return {
25
+ TSPropertySignature(node) {
26
+ const idName = isBarePrimitiveId(node);
27
+ if (idName) {
28
+ context.report({
29
+ node,
30
+ message: `Property "${idName}" is a bare primitive. Use a branded type: string & { readonly __brand: "${idName}" }.`,
31
+ });
32
+ }
33
+ },
34
+ };
35
+ },
36
+ };
37
+ export default noPrimitiveObsession;
@@ -0,0 +1,26 @@
1
+ import type { Rule } from "eslint";
2
+ type TypeParams = {
3
+ params: Array<{
4
+ name: {
5
+ name: string;
6
+ };
7
+ }>;
8
+ };
9
+ type GenericNode = Rule.Node & {
10
+ typeParameters?: TypeParams;
11
+ };
12
+ declare const noSingleUseGenerics: {
13
+ meta: {
14
+ type: "problem";
15
+ docs: {
16
+ description: string;
17
+ };
18
+ schema: never[];
19
+ };
20
+ create(context: Rule.RuleContext): {
21
+ FunctionDeclaration: (node: GenericNode) => void;
22
+ FunctionExpression: (node: GenericNode) => void;
23
+ ArrowFunctionExpression: (node: GenericNode) => void;
24
+ };
25
+ };
26
+ export default noSingleUseGenerics;
@@ -0,0 +1,31 @@
1
+ function check(context, node) {
2
+ if (!node.typeParameters)
3
+ return;
4
+ const fullText = (context.sourceCode ?? context.getSourceCode()).getText(node);
5
+ for (const param of node.typeParameters.params) {
6
+ const name = param.name.name;
7
+ const matches = fullText.match(new RegExp(`\\b${name}\\b`, "g")) ?? [];
8
+ if (matches.length <= 2) {
9
+ context.report({
10
+ node,
11
+ message: `Generic "${name}" is used only once. Remove it or use it in more than one place.`,
12
+ });
13
+ }
14
+ }
15
+ }
16
+ const noSingleUseGenerics = {
17
+ meta: {
18
+ type: "problem",
19
+ docs: { description: "No generic type parameter used only once." },
20
+ schema: [],
21
+ },
22
+ create(context) {
23
+ const visitor = (node) => check(context, node);
24
+ return {
25
+ FunctionDeclaration: visitor,
26
+ FunctionExpression: visitor,
27
+ ArrowFunctionExpression: visitor,
28
+ };
29
+ },
30
+ };
31
+ export default noSingleUseGenerics;
@@ -0,0 +1,16 @@
1
+ import type { Rule } from "eslint";
2
+ declare const noThrowOutsideAdapters: {
3
+ meta: {
4
+ type: "problem";
5
+ docs: {
6
+ description: string;
7
+ };
8
+ schema: never[];
9
+ };
10
+ create(context: Rule.RuleContext): {
11
+ ThrowStatement?: never;
12
+ } | {
13
+ ThrowStatement(node: Rule.Node): void;
14
+ };
15
+ };
16
+ export default noThrowOutsideAdapters;
@@ -0,0 +1,21 @@
1
+ const noThrowOutsideAdapters = {
2
+ meta: {
3
+ type: "problem",
4
+ docs: { description: "No throw statements outside src/adapters/." },
5
+ schema: [],
6
+ },
7
+ create(context) {
8
+ const filename = context.filename ?? context.getFilename();
9
+ if (filename.includes("/adapters/"))
10
+ return {};
11
+ return {
12
+ ThrowStatement(node) {
13
+ context.report({
14
+ node,
15
+ message: "No throw outside src/adapters/. Return a Result instead.",
16
+ });
17
+ },
18
+ };
19
+ },
20
+ };
21
+ export default noThrowOutsideAdapters;
package/docs/SKILL.md ADDED
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: sadist-gate
3
+ description: Use when writing or editing TypeScript code inside a repository that has the sadist gate installed (a strict tsc + ts-pattern + ESLint pre-commit gate). Apply before writing any function, type, or commit in such a repo — code that violates these rules will not compile or will fail lint, blocking the commit.
4
+ ---
5
+
6
+ # sadist-gate
7
+
8
+ Write code that passes on the first attempt. These are hard rules, not style preferences.
9
+
10
+ ## Rules
11
+
12
+ 1. **No `null`/`undefined` in domain types.** Use:
13
+ ```ts
14
+ type Option<T> = { some: true; value: T } | { some: false };
15
+ ```
16
+
17
+ 2. **No `throw` outside `src/adapters/`.** Return instead:
18
+ ```ts
19
+ type Result<T, E> = { ok: true; value: T } | { ok: false; error: E };
20
+ ```
21
+
22
+ 3. **Every match on a union uses `ts-pattern` with `.exhaustive()`.**
23
+ ```ts
24
+ import { match } from "ts-pattern";
25
+ match(result)
26
+ .with({ ok: true }, (r) => r.value)
27
+ .with({ ok: false }, (r) => handleError(r.error))
28
+ .exhaustive();
29
+ ```
30
+ Never `.otherwise()` as a shortcut to skip a case — add the missing `.with()`.
31
+
32
+ 4. **No `class` in domain logic.** Use functions and discriminated unions. Classes are allowed only in `src/adapters/` when an external framework requires them.
33
+
34
+ 5. **No `any`, `as unknown as X`, `@ts-ignore`, `@ts-expect-error`, or `!` (non-null assertion).** No exception without a `// sadist-exception: <ticket>` comment.
35
+
36
+ 6. **Cyclomatic complexity ≤ 6, function length ≤ 20 lines, ≤ 3 parameters.** If it doesn't fit, decompose it — don't suppress the rule.
37
+
38
+ 7. **No generic type parameter used only once.** If `<T>` appears in one place, delete it.
39
+
40
+ 8. **Primitive IDs use branded types, never bare `string`/`number`.**
41
+ ```ts
42
+ type UserId = string & { readonly __brand: "UserId" };
43
+ ```
44
+
45
+ ## Before writing any function
46
+
47
+ Check: does this function throw, return null, use `any`, or exceed 20 lines? If yes, restructure before writing, not after the gate rejects it.
48
+
49
+ ## When the gate rejects a commit
50
+
51
+ Read the `tsc`/ESLint error verbatim — it names the exact rule and location. Fix that, re-run `tsc --noEmit && eslint .` locally, don't guess and recommit blind.
52
+
53
+ ## Scope
54
+
55
+ This gate catches structural bugs (null handling, unhandled cases, exceptions, unsafe casts). It does not catch business-logic errors — correct types with wrong logic still pass. Test logic separately.
56
+
57
+ ## Gate coverage
58
+
59
+ Rules enforced by the ESLint gate (commit-blocking):
60
+ 1, 2, 4, 6, 7, 8 — plus `any` and `!` from rule 5.
61
+
62
+ Rules enforced by convention only (not commit-blocking):
63
+ - Rule 3: `.exhaustive()` on `ts-pattern` matches. The gate cannot detect
64
+ `.otherwise()` misuse — this is a human-review rule.
65
+ - Rule 5 partial: `@ts-ignore`, `@ts-expect-error`, and `as unknown as X`
66
+ are not machine-enforced. These require `@typescript-eslint` plugin rules
67
+ which this gate does not bundle.
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "sadist",
3
+ "version": "0.1.0",
4
+ "description": "A merciless TypeScript code quality gate.",
5
+ "license": "MPL-2.0",
6
+ "keywords": [
7
+ "typescript",
8
+ "eslint",
9
+ "pre-commit",
10
+ "code-quality",
11
+ "strict",
12
+ "lint"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/ElBenjaMasLindo/sadist.git"
17
+ },
18
+ "author": "ElBenjaMasLindo",
19
+ "bugs": {
20
+ "url": "https://github.com/ElBenjaMasLindo/sadist/issues"
21
+ },
22
+ "type": "module",
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": "./dist/index.js",
27
+ "./config/strict": "./dist/config/strict.js"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "docs/SKILL.md"
32
+ ],
33
+ "peerDependencies": {
34
+ "typescript": ">=5.4",
35
+ "eslint": ">=9"
36
+ },
37
+ "dependencies": {
38
+ "ts-pattern": "5.9.0"
39
+ },
40
+ "devDependencies": {
41
+ "husky": "9.1.7",
42
+ "vitest": "2.1.9",
43
+ "typescript": "5.6.3",
44
+ "eslint": "9.39.5",
45
+ "@typescript-eslint/parser": "8.48.1"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "test": "vitest run",
50
+ "lint": "eslint ."
51
+ }
52
+ }