dlinter-ts-react 0.2.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 +21 -0
- package/README.md +151 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +57 -0
- package/dist/index.d.mts +1157 -0
- package/dist/index.mjs +775 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Disble
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# dlinter-ts-react
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Disble/dlinter-ts-react/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/dlinter-ts-react)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
**Deterministic architecture governance for TypeScript + React projects.** One install brings first-class ESLint rules that enforce your architecture — Dumb UI, strict colocation, hook anatomy, layer boundaries — plus the entire third-party plugin stack, pre-composed, and a CLI that scaffolds your pre-commit gate.
|
|
8
|
+
|
|
9
|
+
Architecture documents don't stop violations; linters do. This package turns architectural constraints that usually live as prose (and get silently violated by humans and AI agents alike) into build-time guarantees.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -D dlinter-ts-react eslint lefthook
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// eslint.config.js
|
|
17
|
+
import dlinter from 'dlinter-ts-react';
|
|
18
|
+
|
|
19
|
+
export default [...dlinter.configs.recommended];
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx dlinter init # scaffolds the lefthook pre-commit gate
|
|
24
|
+
npx lefthook install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
That's it. No plugin shopping: `import-x`, `jsdoc`, `sonarjs`, `check-file`, `react`, `react-hooks`, `react-doctor`, and `@typescript-eslint` ship as dependencies of this package, already composed and scoped.
|
|
28
|
+
|
|
29
|
+
## The architecture it enforces
|
|
30
|
+
|
|
31
|
+
Every file in `src/` has one role, and every role has a contract:
|
|
32
|
+
|
|
33
|
+
| File | Role | Contract |
|
|
34
|
+
|------|------|----------|
|
|
35
|
+
| `*.tsx` | Presentational view | No `useEffect`, no runtime/infrastructure access, `Readonly<Props>` boundaries |
|
|
36
|
+
| `use-*.ts` | Colocated hook | Owns side effects; anatomy: `useMemo` → `useCallback` → `useEffect` → `return` |
|
|
37
|
+
| `*.types.ts` | Type contract | Interfaces and type aliases; `*Props` fields are `readonly` |
|
|
38
|
+
| `*.helpers.ts` | Helpers | Functions only — no inline type declarations |
|
|
39
|
+
| `*.constants.ts` / `*.schema.ts` | Constants / Zod schemas | The only home for root-level constants and `zod` imports |
|
|
40
|
+
| `index.ts` | Barrel entrypoint | Pure re-exports only — no logic, no side effects |
|
|
41
|
+
| `App.tsx`, `src/app/**` | Delivery layer | Composition only: no React hooks, no custom hook imports |
|
|
42
|
+
| `__tests__/**` | Tests | Exempt from all architecture rules — tests describe behavior, not shape |
|
|
43
|
+
|
|
44
|
+
When a module splits into role files, the whole unit moves into a folder named after the module with a pure `index.ts` entrypoint — enforced by reading the real filesystem, not by convention.
|
|
45
|
+
|
|
46
|
+
## Rules
|
|
47
|
+
|
|
48
|
+
All rules ship under the `dlinter/` namespace and are individually configurable:
|
|
49
|
+
|
|
50
|
+
| Rule | Enforces |
|
|
51
|
+
|------|----------|
|
|
52
|
+
| `dlinter/no-view-effects` | Views never call `useEffect`/`useLayoutEffect` (including `React.*` forms) |
|
|
53
|
+
| `dlinter/strict-colocation` | Declarations live in their role file; main modules export named functions. `checks` option narrows enforcement per file role |
|
|
54
|
+
| `dlinter/hook-anatomy` | Derived state before callbacks before effects; hooks end with `return` |
|
|
55
|
+
| `dlinter/readonly-props` | `Readonly<Props>` at function boundaries; `readonly` fields in Props interfaces |
|
|
56
|
+
| `dlinter/no-infrastructure-in-view` | Views never touch the infrastructure edge — **you** define the edge (see below) |
|
|
57
|
+
| `dlinter/composition-only-delivery` | Delivery files compose feature entrypoints; they never orchestrate |
|
|
58
|
+
| `dlinter/pure-index-barrel` | `index.ts` contains re-export statements only |
|
|
59
|
+
| `dlinter/folder-ownership` | Modules with role-file siblings are folder-owned with an `index.ts` entrypoint |
|
|
60
|
+
| `dlinter/require-exported-variable-jsdoc` | Every exported variable carries a JSDoc block |
|
|
61
|
+
|
|
62
|
+
## Configuring your infrastructure edge
|
|
63
|
+
|
|
64
|
+
The boundary concept is universal; the edge is yours. Wails, tRPC clients, generated API bindings — pass them as options:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import { createRecommendedConfig } from 'dlinter-ts-react';
|
|
68
|
+
|
|
69
|
+
export default createRecommendedConfig({
|
|
70
|
+
infrastructure: {
|
|
71
|
+
importPatterns: ['(^|/)wailsjs(/|$)'], // regex sources matched against import specifiers
|
|
72
|
+
runtimeGlobals: ['window.go'], // object.property member paths
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Option | Default | Purpose |
|
|
78
|
+
|--------|---------|---------|
|
|
79
|
+
| `infrastructure` | `undefined` (rule off) | Import patterns + runtime globals that views must never touch directly |
|
|
80
|
+
| `deliveryGlobs` | `['src/App.tsx', 'src/app/**/*.{ts,tsx}']` | Which files form the composition-only delivery layer |
|
|
81
|
+
| `tsconfigPath` | `./tsconfig.json` | tsconfig used by the import resolver |
|
|
82
|
+
|
|
83
|
+
Presets are named after **architecture concepts** (`recommended`, `dumb-ui`), never after projects. Your project's specifics are options, not preset names.
|
|
84
|
+
|
|
85
|
+
## What else is in `recommended`
|
|
86
|
+
|
|
87
|
+
Beyond the `dlinter/` rules, the preset composes the bundled ecosystem with proven settings:
|
|
88
|
+
|
|
89
|
+
- **`tsc` owns `no-undef`** — ESLint's version only false-positives on TS globals. Keep a typecheck job in your gate; it is load-bearing.
|
|
90
|
+
- **`import-x`**: cycle detection (`no-cycle`), duplicate imports, TypeScript-aware resolution.
|
|
91
|
+
- **`jsdoc/require-jsdoc`** on every exported function, interface, and type alias.
|
|
92
|
+
- **`check-file`**: tests belong in `__tests__/`, feature folders are kebab-case, `utils.ts` is banned (name the role: `*.helpers.ts`).
|
|
93
|
+
- **`sonarjs` + `react-doctor` as warnings** — advisory signal, never gate failures.
|
|
94
|
+
- **`max-lines`**: 500 effective lines, hard error.
|
|
95
|
+
- **`react-hooks`**: `rules-of-hooks` stays an error; nothing else replaces that safety net.
|
|
96
|
+
|
|
97
|
+
## CLI
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npx dlinter init
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Scaffolds `lefthook.yml` with a lint + typecheck + test pre-commit gate. Never overwrites an existing file — a hand-tuned gate always wins over the template.
|
|
104
|
+
|
|
105
|
+
## Compatibility
|
|
106
|
+
|
|
107
|
+
| Peer | Range |
|
|
108
|
+
|------|-------|
|
|
109
|
+
| `eslint` | `>=9` (ESLint 10 supported) |
|
|
110
|
+
| `typescript` | `>=5.0.0 <6.1.0` — TypeScript 7 (native) is not yet supported by `@typescript-eslint`; the ceiling moves when the ecosystem does |
|
|
111
|
+
| `node` | `>=20.19.0` |
|
|
112
|
+
|
|
113
|
+
## Design principles
|
|
114
|
+
|
|
115
|
+
| Principle | In practice |
|
|
116
|
+
|-----------|-------------|
|
|
117
|
+
| First-class rules, never selector catalogs | `no-restricted-syntax` is a single rule slot consumers can silently override; every constraint here has its own rule ID, its own docs, and per-rule disable |
|
|
118
|
+
| Don't reinvent the wheel | Existing plugins are bundled wheels (`max-lines`, `check-file`, `import-x`, …). Custom rules exist only for contracts no plugin ships — e.g. conditional folder ownership, pure-barrel enforcement |
|
|
119
|
+
| Tests are the proof | Every rule is TDD-built with RED/GREEN `RuleTester` cases; presets are tested through a real `ESLint` instance; releases are gated by installing the actual tarball into a fresh consumer project |
|
|
120
|
+
| Validated against production | The full preset reproduces the source system's lint verdicts at exact file:line parity (30/30) on the codebase it was extracted from |
|
|
121
|
+
|
|
122
|
+
## Development
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
bun install
|
|
126
|
+
bun run test # vitest: RuleTester per rule + ESLint-instance integration harness
|
|
127
|
+
bun run typecheck # tsc --noEmit
|
|
128
|
+
bun run build # tsdown → dist/*.mjs
|
|
129
|
+
bun run e2e:pack # pack the tarball, install it into a fresh consumer, verify plugin + preset + CLI
|
|
130
|
+
bun run validate # typecheck + test
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The repo self-hosts its own gate (lefthook: fallow audit + typecheck + test). Contributions follow strict TDD — a rule without a failing test proving it fires is a disabled rule — and conventional commits.
|
|
134
|
+
|
|
135
|
+
### Releasing
|
|
136
|
+
|
|
137
|
+
Releases are automated with [release-please](https://github.com/googleapis/release-please): conventional commits on `main` drive the next semver (`fix:` → patch, `feat:` → minor, `feat!:`/`BREAKING CHANGE:` → major). The bot maintains a Release PR with the computed version and CHANGELOG; **merging that PR** cuts the GitHub release and publishes to npm with provenance — after the tarball end-to-end gate passes.
|
|
138
|
+
|
|
139
|
+
Manual escape hatch: pushing a `v*` tag triggers the same publish pipeline directly.
|
|
140
|
+
|
|
141
|
+
Requires the `NPM_TOKEN` secret in the repository settings.
|
|
142
|
+
|
|
143
|
+
## Roadmap
|
|
144
|
+
|
|
145
|
+
- File-size advisory (400-line warning tier ahead of the 500 hard limit)
|
|
146
|
+
- `dlinter init`: prettier scaffold + package-manager detection (bun/pnpm/npm)
|
|
147
|
+
- Layer/boundary preset built on `eslint-plugin-boundaries`
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
[MIT](./LICENSE) © Disble
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/cli/init.ts
|
|
5
|
+
const lefthookTemplate = `pre-commit:
|
|
6
|
+
parallel: false
|
|
7
|
+
jobs:
|
|
8
|
+
- name: lint
|
|
9
|
+
run: npx eslint .
|
|
10
|
+
|
|
11
|
+
- name: typecheck
|
|
12
|
+
run: npx tsc --noEmit
|
|
13
|
+
|
|
14
|
+
- name: test
|
|
15
|
+
run: npm run test
|
|
16
|
+
`;
|
|
17
|
+
/**
|
|
18
|
+
* Scaffolds the dlinter pre-commit gate into a consumer project. Existing
|
|
19
|
+
* files are never overwritten — a hand-tuned gate always wins over the template.
|
|
20
|
+
* @param options - target project location.
|
|
21
|
+
* @returns which files were created and which were left untouched.
|
|
22
|
+
*/
|
|
23
|
+
async function runInit({ cwd }) {
|
|
24
|
+
const created = [];
|
|
25
|
+
const skipped = [];
|
|
26
|
+
const lefthookPath = path.join(cwd, "lefthook.yml");
|
|
27
|
+
if (existsSync(lefthookPath)) skipped.push("lefthook.yml");
|
|
28
|
+
else {
|
|
29
|
+
writeFileSync(lefthookPath, lefthookTemplate);
|
|
30
|
+
created.push("lefthook.yml");
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
created,
|
|
34
|
+
skipped
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/cli/index.ts
|
|
39
|
+
/**
|
|
40
|
+
* CLI entrypoint: `dlinter init` scaffolds the pre-commit gate in the current project.
|
|
41
|
+
*/
|
|
42
|
+
async function main() {
|
|
43
|
+
if (process.argv[2] !== "init") {
|
|
44
|
+
process.stderr.write("Usage: dlinter init\n");
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const result = await runInit({ cwd: process.cwd() });
|
|
49
|
+
for (const file of result.created) process.stdout.write(`created ${file}\n`);
|
|
50
|
+
for (const file of result.skipped) process.stdout.write(`skipped ${file} (already exists)\n`);
|
|
51
|
+
}
|
|
52
|
+
main().catch((error) => {
|
|
53
|
+
process.stderr.write(`dlinter failed: ${error.message}\n`);
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
});
|
|
56
|
+
//#endregion
|
|
57
|
+
export {};
|