@krizaka/config 0.0.0-stage → 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/.editorconfig +17 -0
- package/LICENSE +202 -0
- package/README.md +167 -2
- package/bin/krizaka-ratchet.mjs +94 -0
- package/dependency-cruiser.cjs +31 -0
- package/eslint/index.js +70 -0
- package/eslint/krizaka-ui.js +61 -0
- package/eslint/next.js +18 -0
- package/eslint/no-locale-ternary.js +41 -0
- package/eslint/plugin.js +16 -0
- package/eslint/rules.js +129 -0
- package/eslint/stack.js +40 -0
- package/package.json +117 -3
- package/patterns.js +117 -0
- package/prettier.config.js +15 -0
- package/ratchet/ratchet.js +259 -0
- package/tsconfig/base.json +18 -0
- package/tsconfig/next.json +14 -0
- package/tsconfig/react-library.json +9 -0
- package/tsconfig/react-native.json +12 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Krizaka EditorConfig — copy to the repository root: cp node_modules/@krizaka/config/.editorconfig .
|
|
2
|
+
root = true
|
|
3
|
+
|
|
4
|
+
[*]
|
|
5
|
+
charset = utf-8
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
indent_style = space
|
|
8
|
+
indent_size = 2
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
max_line_length = 120
|
|
12
|
+
|
|
13
|
+
[*.md]
|
|
14
|
+
trim_trailing_whitespace = false
|
|
15
|
+
|
|
16
|
+
[{Makefile,*.mk}]
|
|
17
|
+
indent_style = tab
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @krizaka/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**The shared configuration of every Krizaka JavaScript repository.** ESLint flat configs (base, Next.js, the four UI
|
|
4
|
+
rules, the three stack rules, no locale ternary), the dependency-cruiser boundary, tsconfig bases, Prettier,
|
|
5
|
+
EditorConfig — and `krizaka-ratchet`, the counter that keeps the UI and stack debts from coming back.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@krizaka/config)
|
|
8
|
+
[](../../LICENSE)
|
|
9
|
+
|
|
10
|
+
## Adopt it in three lines
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -D @krizaka/config eslint typescript # + eslint-config-next for a Next.js app, prettier if you format
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
// eslint.config.mjs — a Next.js app (a library: `krizakaBase` from "@krizaka/config/eslint")
|
|
18
|
+
import { krizakaNext } from "@krizaka/config/eslint/next";
|
|
19
|
+
import { krizakaUi } from "@krizaka/config/eslint/krizaka-ui";
|
|
20
|
+
import { noLocaleTernary } from "@krizaka/config/eslint/no-locale-ternary";
|
|
21
|
+
import { krizakaStack } from "@krizaka/config/eslint/stack";
|
|
22
|
+
|
|
23
|
+
export default [...krizakaNext, ...krizakaUi(), ...krizakaStack(), ...noLocaleTernary()];
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// .dependency-cruiser.cjs — the TanStack boundary, plus the app's own rules
|
|
28
|
+
module.exports = { extends: "@krizaka/config/dependency-cruiser", forbidden: [] };
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```jsonc
|
|
32
|
+
// tsconfig.json — base · react-library · next · react-native
|
|
33
|
+
{ "extends": "@krizaka/config/tsconfig/next.json", "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Prettier: `export { default } from "@krizaka/config/prettier";` in `prettier.config.js` (120 columns, double quotes,
|
|
37
|
+
trailing commas). EditorConfig: `cp node_modules/@krizaka/config/.editorconfig .`.
|
|
38
|
+
|
|
39
|
+
`eslint` ^9 and `typescript` ^5 are peer dependencies; `eslint-config-next` (Next.js apps) and `prettier` are optional
|
|
40
|
+
peers. The plugins (`typescript-eslint`, `eslint-plugin-react-hooks`, `eslint-plugin-simple-import-sort`) come with
|
|
41
|
+
the package.
|
|
42
|
+
|
|
43
|
+
## What is inside
|
|
44
|
+
|
|
45
|
+
| Export | What it gives |
|
|
46
|
+
| :-- | :-- |
|
|
47
|
+
| `@krizaka/config/eslint` | `krizakaBase`: `@eslint/js` + `typescript-eslint` recommended, React hooks, import ordering (a warning, autofixable), ignores of generated output, `_`-prefixed unused arguments allowed. |
|
|
48
|
+
| `@krizaka/config/eslint/next` | `krizakaNext`: `eslint-config-next` (core web vitals + TypeScript, which already carry typescript-eslint, React hooks and import) + the same basics. |
|
|
49
|
+
| `@krizaka/config/eslint/krizaka-ui` | `krizakaUi(options?)`: the four UI rules below. Also `krizakaUiRules` and `krizakaUiRestrictedSyntax(options?)`. |
|
|
50
|
+
| `@krizaka/config/eslint/no-locale-ternary` | `noLocaleTernary(options?)`: `krizaka/no-locale-ternary` — no `locale === "fr" ? … : …` outside routing code. |
|
|
51
|
+
| `@krizaka/config/eslint/stack` | `krizakaStack(options?)`: the three stack rules below (warnings). Also `STACK_RULES`. |
|
|
52
|
+
| `@krizaka/config/eslint/plugin` | `krizakaPlugin`: the `krizaka` plugin carrying every rule, for a hand-written config. |
|
|
53
|
+
| `@krizaka/config/dependency-cruiser` | The shared dependency-cruiser config: `krizaka-no-direct-tanstack` (no `@tanstack/*` from an app). |
|
|
54
|
+
| `@krizaka/config/tsconfig/*.json` | `base` (strict, ES2022, bundler resolution), `react-library` (+ DOM, `react-jsx`), `next` (+ the Next plugin, `noEmit`, `incremental`), `react-native` (`jsx: react-native`, `customConditions`; with Expo: `"extends": ["expo/tsconfig.base", "@krizaka/config/tsconfig/react-native.json"]`). |
|
|
55
|
+
| `@krizaka/config/prettier` · `.editorconfig` | The formatting. |
|
|
56
|
+
| `krizaka-ratchet` (bin) | The debt counter, see below. |
|
|
57
|
+
|
|
58
|
+
### The four UI rules
|
|
59
|
+
|
|
60
|
+
On every string literal inside a `className` (in `cn(…)`, a ternary…), with no plugin — `no-restricted-syntax`
|
|
61
|
+
selectors:
|
|
62
|
+
|
|
63
|
+
1. **No raw palette colour** — `bg-zinc-900`, `text-violet-400/80`: use a role of
|
|
64
|
+
[`@krizaka/tailwind`](../tailwind) (`bg-surface-1`, `text-fg-secondary`, `border-border-default`, `text-accent`,
|
|
65
|
+
`text-danger`).
|
|
66
|
+
2. **No `light:`** — a theme is a set of tokens; a dark island takes `.theme-dark` on its ancestor.
|
|
67
|
+
3. **No arbitrary `[var(--…)]` utility** — the variable has a utility in `@krizaka/tailwind`.
|
|
68
|
+
4. **No template literal in `className`** — `cn(…)` merges the classes and lets the override win.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
krizakaUi({
|
|
72
|
+
allow: ["emerald"], // palette families tolerated for documented, isolated cases
|
|
73
|
+
files: ["**/*.{jsx,tsx}"], // default
|
|
74
|
+
ignores: ["app/og/**"], // e.g. generated OG images
|
|
75
|
+
severity: "error", // "warn" while the ratchet brings the debt down
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Flat config replaces a rule's options instead of concatenating them: a repository that already sets
|
|
80
|
+
`no-restricted-syntax` merges both lists with `krizakaUiRestrictedSyntax()`. `no-locale-ternary` is a plugin rule for
|
|
81
|
+
that reason — it composes with anything.
|
|
82
|
+
|
|
83
|
+
### The three stack rules
|
|
84
|
+
|
|
85
|
+
From [ADR-001](../../docs/adr/ADR-001-tanstack-under-krizaka-facades.md) — the TanStack engines run headless, behind
|
|
86
|
+
`@krizaka/*` facades; a product never imports them. Warnings: `krizaka-ratchet` counts the same patterns, so an app
|
|
87
|
+
adopts them before it is clean and brings each count to 0 by the end of its adoption.
|
|
88
|
+
|
|
89
|
+
1. **`krizaka/no-fetch-in-client-effect`** — a `fetch` / `krizakaFetch` inside a `useEffect` (or `useLayoutEffect`)
|
|
90
|
+
of a `"use client"` file: render the first screen in a Server Component, read the rest with `@krizaka/query`.
|
|
91
|
+
2. **`krizaka/no-direct-tanstack-import`** — an import of `@tanstack/*` (static, dynamic, `require`, re-export): use
|
|
92
|
+
the facade (`@krizaka/query`, `@krizaka/ui/data-table`, `@krizaka/ui/form`, `@krizaka/ui/virtual`, `@krizaka/pacer`).
|
|
93
|
+
3. **`krizaka/no-local-table-or-form`** — a `<table>`, or a `<form>` of more than one field (native fields and the field
|
|
94
|
+
primitives of `@krizaka/ui`; a hidden or submit `<input>` is not a field): use `DataTable` and `createKrizakaForm`.
|
|
95
|
+
A search box or a one-field newsletter stays a plain form.
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
krizakaStack({
|
|
99
|
+
files: ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"], // default
|
|
100
|
+
ignores: ["packages/**"], // e.g. the facades of a monorepo
|
|
101
|
+
severity: "warn", // default; "error" once the app's counts are at 0
|
|
102
|
+
maxFormFields: 1, // default
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The dependency-cruiser config forbids `@tanstack/*` from an app's own files, resolved or not (a package installed
|
|
107
|
+
only as a dependency of a facade is caught too), and allows it from `node_modules/@krizaka/*`.
|
|
108
|
+
|
|
109
|
+
`noLocaleTernary({ files, routing })`: `routing` lists the files allowed to compare locales (default: `proxy.ts`,
|
|
110
|
+
`middleware.ts`, `i18n.ts`, `seo.ts`, `app/[locale]/layout.tsx`, `I18nProvider.tsx`).
|
|
111
|
+
|
|
112
|
+
## The ratchet
|
|
113
|
+
|
|
114
|
+
A repository with debt cannot turn the rules on in one pull request. The ratchet lets it adopt them now: it counts
|
|
115
|
+
the four UI debts and the four stack debts, records the counts in `lint-ratchet.json` at the root, and **fails when a
|
|
116
|
+
count goes up**. Every migration pull request lowers them; when a count reaches zero, the matching rule becomes a
|
|
117
|
+
strict `error`.
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
npx krizaka-ratchet --init # once: creates lint-ratchet.json with today's counts — commit it
|
|
121
|
+
npx krizaka-ratchet # locally: compares (exit 1 when a count went up)
|
|
122
|
+
npx krizaka-ratchet --update # after a migration: lowers the recorded counts (never raises them), records new counters — commit it
|
|
123
|
+
npx krizaka-ratchet --json # in CI: the same check, machine-readable
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| Counter | Pattern (same regex as the ESLint rule) |
|
|
127
|
+
| :-- | :-- |
|
|
128
|
+
| `palette` | `\b(bg\|text\|border\|from\|via\|to\|ring\|shadow\|fill\|stroke)-(zinc\|slate\|…\|indigo)-[0-9]` |
|
|
129
|
+
| `light` | `\blight:` |
|
|
130
|
+
| `arbitraryVar` | `\[var\(--` |
|
|
131
|
+
| `classNameTemplate` | `` className=\{\s*` `` |
|
|
132
|
+
| `fetchInClientEffect` | in a file opening with `"use client"`: `fetch(` / `krizakaFetch(` between the parentheses of a `useEffect(` / `useLayoutEffect(` |
|
|
133
|
+
| `directTanstackImport` | `from` / `import` / `import(` / `require(` of `"@tanstack/…"` |
|
|
134
|
+
| `localTableOrForm` | `<table`, and `<form` … `</form>` holding more fields than `maxFormFields` (default 1) |
|
|
135
|
+
| `retiredImport` | an import of a dependency listed in `retire` (e.g. `["framer-motion"]`): the way out of a dependency |
|
|
136
|
+
|
|
137
|
+
The UI counters scan `app/**/*.tsx`, `components/**/*.tsx` and `src/**/*.tsx` by default (`node_modules`, `dist`,
|
|
138
|
+
`.next` never), or the globs given on the command line; the stack counters scan every source file (`js`, `jsx`, `mjs`,
|
|
139
|
+
`ts`, `tsx`, `mts`) of `app`, `components`, `src`, `lib`, `hooks` and `features` (`stackGlobs`). `--init` stores both
|
|
140
|
+
in the file so that every later run counts the same set. A file written before the stack counters still checks; the
|
|
141
|
+
next `--update` records them at their current value.
|
|
142
|
+
The counts apply the regex to the whole source text — a class held in a constant or a `cn()` argument counts too —
|
|
143
|
+
so the ratchet is never looser than the rule. Exit codes: `0` ok, `1` a count went up, `2` usage or file error.
|
|
144
|
+
|
|
145
|
+
```jsonc
|
|
146
|
+
// lint-ratchet.json
|
|
147
|
+
{
|
|
148
|
+
"globs": ["app/**/*.tsx", "components/**/*.tsx", "src/**/*.tsx"],
|
|
149
|
+
"stackGlobs": ["app/**/*.{js,jsx,mjs,ts,tsx,mts}", "…"],
|
|
150
|
+
"allow": [], // optional: same families as krizakaUi({ allow })
|
|
151
|
+
"retire": ["framer-motion"], // optional: dependencies on their way out
|
|
152
|
+
"maxFormFields": 1, // optional: same option as krizakaStack({ maxFormFields })
|
|
153
|
+
"counters": {
|
|
154
|
+
"palette": 2400, "light": 1151, "arbitraryVar": 0, "classNameTemplate": 128,
|
|
155
|
+
"fetchInClientEffect": 41, "directTanstackImport": 3, "localTableOrForm": 38, "retiredImport": 4
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The CI step, after the install:
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
- run: npx krizaka-ratchet --json
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
[Apache-2.0](../../LICENSE)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// krizaka-ratchet — the UI debt can only go down. See the README of @krizaka/config.
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
|
|
5
|
+
import { COUNTERS, RatchetError, runRatchet } from "../ratchet/ratchet.js";
|
|
6
|
+
|
|
7
|
+
const USAGE = `Usage: krizaka-ratchet [globs…] [--init | --update] [--json] [--root <dir>] [--file <name>]
|
|
8
|
+
|
|
9
|
+
Counts the UI debts — raw palette colours, light: variants, [var(--…)] utilities, className template strings — in the
|
|
10
|
+
source files (default: app/**/*.tsx components/**/*.tsx src/**/*.tsx), and the stack debts — fetch in a client effect,
|
|
11
|
+
direct @tanstack/* imports, hand-written tables and forms, imports of the dependencies listed in "retire" — in every
|
|
12
|
+
source file of app, components, src, lib, hooks and features; compares them with lint-ratchet.json.
|
|
13
|
+
|
|
14
|
+
(no flag) fail (exit 1) when a counter is above its recorded value
|
|
15
|
+
--init create lint-ratchet.json with the current counters
|
|
16
|
+
--update lower the recorded counters to the current values (never raises them), record the new ones
|
|
17
|
+
--json machine-readable report on stdout (for CI)
|
|
18
|
+
--root repository root (default: current directory)
|
|
19
|
+
--file ratchet file name (default: lint-ratchet.json)`;
|
|
20
|
+
|
|
21
|
+
const LABELS = {
|
|
22
|
+
palette: "raw palette colours",
|
|
23
|
+
light: "light: variants",
|
|
24
|
+
arbitraryVar: "[var(--…)] utilities",
|
|
25
|
+
classNameTemplate: "className template strings",
|
|
26
|
+
fetchInClientEffect: "fetch in a client effect",
|
|
27
|
+
directTanstackImport: "direct @tanstack/* imports",
|
|
28
|
+
localTableOrForm: "hand-written tables / forms",
|
|
29
|
+
retiredImport: "imports of retired deps",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
let args;
|
|
33
|
+
try {
|
|
34
|
+
args = parseArgs({
|
|
35
|
+
allowPositionals: true,
|
|
36
|
+
options: {
|
|
37
|
+
init: { type: "boolean" },
|
|
38
|
+
update: { type: "boolean" },
|
|
39
|
+
json: { type: "boolean" },
|
|
40
|
+
root: { type: "string" },
|
|
41
|
+
file: { type: "string" },
|
|
42
|
+
help: { type: "boolean", short: "h" },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`${error instanceof Error ? error.message : error}\n\n${USAGE}`);
|
|
47
|
+
process.exit(2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const { values, positionals } = args;
|
|
51
|
+
if (values.help) {
|
|
52
|
+
console.log(USAGE);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
if (values.init && values.update) {
|
|
56
|
+
console.error("--init and --update are exclusive.");
|
|
57
|
+
process.exit(2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const result = await runRatchet({
|
|
62
|
+
root: values.root ?? process.cwd(),
|
|
63
|
+
mode: values.init ? "init" : values.update ? "update" : "check",
|
|
64
|
+
globs: positionals,
|
|
65
|
+
file: values.file,
|
|
66
|
+
});
|
|
67
|
+
if (values.json) {
|
|
68
|
+
console.log(JSON.stringify(result, null, 2));
|
|
69
|
+
} else {
|
|
70
|
+
console.log(`krizaka-ratchet — ${result.files} files for the UI, ${result.stackFiles} for the stack`);
|
|
71
|
+
for (const name of COUNTERS) {
|
|
72
|
+
const { recorded, current, delta } = result.counters[name];
|
|
73
|
+
const mark = delta > 0 ? "✗" : delta < 0 ? "↓" : "=";
|
|
74
|
+
const sign = delta > 0 ? `+${delta}` : `${delta}`;
|
|
75
|
+
console.log(` ${mark} ${LABELS[name].padEnd(28)} ${String(current).padStart(6)} (recorded ${recorded}, ${sign})`);
|
|
76
|
+
}
|
|
77
|
+
if (result.mode === "init") console.log(`Created ${result.file}.`);
|
|
78
|
+
else if (result.written) console.log(`${result.decreased.length > 0 ? "Lowered" : "Completed"} ${result.file}: commit it.`);
|
|
79
|
+
else if (result.decreased.length > 0) console.log(`Debt went down: run krizaka-ratchet --update and commit ${result.file}.`);
|
|
80
|
+
else if (result.added.length > 0) console.log(`New counters (${result.added.join(", ")}): run krizaka-ratchet --update and commit ${result.file}.`);
|
|
81
|
+
if (!result.ok) {
|
|
82
|
+
console.error(
|
|
83
|
+
`Debt went up (${result.increased.join(", ")}): roles of @krizaka/tailwind and cn() for the UI; @krizaka/query, @krizaka/ui/data-table and @krizaka/ui/form for the stack.`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
process.exit(result.ok ? 0 : 1);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error instanceof RatchetError || error instanceof SyntaxError) {
|
|
90
|
+
console.error(`krizaka-ratchet: ${error.message}`);
|
|
91
|
+
process.exit(2);
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// The shared dependency-cruiser rules of a Krizaka app (the stack ADR, decision S11). An app extends it and adds its own:
|
|
2
|
+
//
|
|
3
|
+
// // .dependency-cruiser.cjs
|
|
4
|
+
// module.exports = { extends: "@krizaka/config/dependency-cruiser", forbidden: [/* the app's rules */] };
|
|
5
|
+
//
|
|
6
|
+
// dependency-cruiser concatenates `forbidden` and merges `options`. CommonJS: dependency-cruiser requires its configs.
|
|
7
|
+
|
|
8
|
+
/** @type {import("dependency-cruiser").IConfiguration} */
|
|
9
|
+
module.exports = {
|
|
10
|
+
forbidden: [
|
|
11
|
+
{
|
|
12
|
+
name: "krizaka-no-direct-tanstack",
|
|
13
|
+
severity: "error",
|
|
14
|
+
comment:
|
|
15
|
+
"@tanstack/* enters an app only through its @krizaka facade (@krizaka/query, @krizaka/ui/data-table, @krizaka/ui/form, " +
|
|
16
|
+
"@krizaka/ui/virtual, @krizaka/pacer…): the facade's version is the contract, a TanStack break is fixed in one place.",
|
|
17
|
+
// the app's own sources; the @krizaka/* packages in node_modules are where TanStack belongs
|
|
18
|
+
from: { pathNot: "(^|/)node_modules/" },
|
|
19
|
+
// resolved (node_modules/…/@tanstack/…) or not (a transitive package the app does not declare)
|
|
20
|
+
to: { path: "(^|/)@tanstack/" },
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
options: {
|
|
24
|
+
doNotFollow: { path: "(^|/)node_modules/" },
|
|
25
|
+
tsPreCompilationDeps: true,
|
|
26
|
+
enhancedResolveOptions: {
|
|
27
|
+
exportsFields: ["exports"],
|
|
28
|
+
conditionNames: ["import", "require", "node", "default"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
package/eslint/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The base flat config of every Krizaka JavaScript repository: @eslint/js and typescript-eslint recommended,
|
|
2
|
+
// the React hooks rules, and a light import ordering (autofixable, a warning).
|
|
3
|
+
import js from "@eslint/js";
|
|
4
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
5
|
+
import simpleImportSort from "eslint-plugin-simple-import-sort";
|
|
6
|
+
import globals from "globals";
|
|
7
|
+
import tseslint from "typescript-eslint";
|
|
8
|
+
|
|
9
|
+
/** Generated or vendored output, never linted. */
|
|
10
|
+
export const KRIZAKA_IGNORES = Object.freeze([
|
|
11
|
+
"**/node_modules/**",
|
|
12
|
+
"**/dist/**",
|
|
13
|
+
"**/build/**",
|
|
14
|
+
"**/coverage/**",
|
|
15
|
+
"**/.next/**",
|
|
16
|
+
"**/out/**",
|
|
17
|
+
"**/.turbo/**",
|
|
18
|
+
"**/.expo/**",
|
|
19
|
+
"**/storybook-static/**",
|
|
20
|
+
"**/next-env.d.ts",
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Shared by krizakaBase and krizakaNext: ignores, globals, import ordering.
|
|
25
|
+
* @type {import("eslint").Linter.Config[]}
|
|
26
|
+
*/
|
|
27
|
+
export const krizakaCommon = [
|
|
28
|
+
{ name: "krizaka/ignores", ignores: [...KRIZAKA_IGNORES] },
|
|
29
|
+
{
|
|
30
|
+
name: "krizaka/language",
|
|
31
|
+
languageOptions: {
|
|
32
|
+
ecmaVersion: "latest",
|
|
33
|
+
sourceType: "module",
|
|
34
|
+
globals: { ...globals.browser, ...globals.node },
|
|
35
|
+
},
|
|
36
|
+
linterOptions: { reportUnusedDisableDirectives: "error" },
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "krizaka/imports",
|
|
40
|
+
plugins: { "simple-import-sort": simpleImportSort },
|
|
41
|
+
rules: {
|
|
42
|
+
"simple-import-sort/imports": "warn",
|
|
43
|
+
"simple-import-sort/exports": "warn",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Unused variables are errors, except the `_`-prefixed ones (an intentionally ignored argument).
|
|
50
|
+
* @type {import("eslint").Linter.RuleEntry}
|
|
51
|
+
*/
|
|
52
|
+
const UNUSED_VARS = [
|
|
53
|
+
"error",
|
|
54
|
+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
58
|
+
export const krizakaBase = [
|
|
59
|
+
...krizakaCommon,
|
|
60
|
+
{ name: "krizaka/js", ...js.configs.recommended },
|
|
61
|
+
.../** @type {import("eslint").Linter.Config[]} */ (tseslint.configs.recommended),
|
|
62
|
+
{ name: "krizaka/react-hooks", files: ["**/*.{js,jsx,ts,tsx}"], ...reactHooks.configs.flat.recommended },
|
|
63
|
+
{
|
|
64
|
+
name: "krizaka/typescript",
|
|
65
|
+
files: ["**/*.{ts,tsx,mts,cts}"],
|
|
66
|
+
rules: { "@typescript-eslint/no-unused-vars": UNUSED_VARS },
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
export default krizakaBase;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// The four non-negotiable UI rules of the refactor (study §2.12), with no plugin: AST selectors on className literals.
|
|
2
|
+
// The ratchet (bin/krizaka-ratchet.mjs) counts the same patterns, so a repository can adopt the rules before it is clean.
|
|
3
|
+
import { ARBITRARY_VAR_SOURCE, LIGHT_VARIANT_SOURCE, paletteSource } from "../patterns.js";
|
|
4
|
+
|
|
5
|
+
const CLASSNAME = "JSXAttribute[name.name='className']";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The `no-restricted-syntax` entries, for a repository that already uses that rule and must merge both lists
|
|
9
|
+
* (flat config replaces a rule's options, it never concatenates them).
|
|
10
|
+
* @param {{ allow?: string[] }} [options] `allow`: palette families tolerated for documented, isolated cases.
|
|
11
|
+
* @returns {{ selector: string, message: string }[]}
|
|
12
|
+
*/
|
|
13
|
+
export function krizakaUiRestrictedSyntax({ allow = [] } = {}) {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
selector: `${CLASSNAME} Literal[value=/${paletteSource(allow)}/]`,
|
|
17
|
+
message:
|
|
18
|
+
"Raw palette colour: use a role (bg-surface-1, text-fg-secondary, border-border-default, text-accent, text-danger).",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
selector: `${CLASSNAME} Literal[value=/${LIGHT_VARIANT_SOURCE}/]`,
|
|
22
|
+
message: "`light:` is forbidden in products: a theme is a set of tokens. A dark island? `.theme-dark` on the ancestor.",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
selector: `${CLASSNAME} Literal[value=/${ARBITRARY_VAR_SOURCE}/]`,
|
|
26
|
+
message: "Arbitrary utility: the variable has a utility in @krizaka/tailwind.",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
selector: `${CLASSNAME} TemplateLiteral`,
|
|
30
|
+
message: "No template string in className: cn(...) merges classes and lets the override win.",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The rule set, for a spread into a config object's `rules`. */
|
|
36
|
+
export const krizakaUiRules = {
|
|
37
|
+
"no-restricted-syntax": ["error", ...krizakaUiRestrictedSyntax()],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Flat config: the four UI rules on the given files.
|
|
42
|
+
* @param {{ allow?: string[], files?: string[], ignores?: string[], severity?: "error" | "warn" }} [options]
|
|
43
|
+
* @returns {import("eslint").Linter.Config[]}
|
|
44
|
+
*/
|
|
45
|
+
export function krizakaUi({
|
|
46
|
+
allow = [],
|
|
47
|
+
files = ["**/*.{jsx,tsx}"],
|
|
48
|
+
ignores = [],
|
|
49
|
+
severity = "error",
|
|
50
|
+
} = {}) {
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
name: "krizaka/ui",
|
|
54
|
+
files,
|
|
55
|
+
...(ignores.length > 0 ? { ignores } : {}),
|
|
56
|
+
rules: { "no-restricted-syntax": [severity, ...krizakaUiRestrictedSyntax({ allow })] },
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default krizakaUi;
|
package/eslint/next.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The flat config of a Next.js app: eslint-config-next (core web vitals + TypeScript, which already carry
|
|
2
|
+
// typescript-eslint, React hooks and import), on top of the shared Krizaka basics. eslint-config-next is an
|
|
3
|
+
// optional peer dependency: only Next.js apps install it.
|
|
4
|
+
import js from "@eslint/js";
|
|
5
|
+
import nextVitals from "eslint-config-next/core-web-vitals";
|
|
6
|
+
import nextTs from "eslint-config-next/typescript";
|
|
7
|
+
|
|
8
|
+
import { krizakaCommon } from "./index.js";
|
|
9
|
+
|
|
10
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
11
|
+
export const krizakaNext = [
|
|
12
|
+
...krizakaCommon,
|
|
13
|
+
{ name: "krizaka/js", ...js.configs.recommended },
|
|
14
|
+
...nextVitals,
|
|
15
|
+
...nextTs,
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export default krizakaNext;
|