@ref0/workspace 0.0.0-stage → 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 +201 -0
- package/README.md +69 -2
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +30 -0
- package/dist/docs-budget.mjs +122 -0
- package/dist/lint/anti-slop/LICENSE +21 -0
- package/dist/lint/anti-slop/UPSTREAM.md +11 -0
- package/dist/lint/anti-slop/effect/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/effect/plugin.mjs +19 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-effect-error-tag.mjs +33 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tag-comparison.mjs +32 -0
- package/dist/lint/anti-slop/effect/rules/no-manual-tagged-construction.mjs +22 -0
- package/dist/lint/anti-slop/effect/rules/no-service-constructor-imports.mjs +36 -0
- package/dist/lint/anti-slop/effect/rules/prefer-effect-match.mjs +40 -0
- package/dist/lint/anti-slop/effect/shared/tagged-values.mjs +40 -0
- package/dist/lint/anti-slop/plugin.d.mts +3 -0
- package/dist/lint/anti-slop/plugin.mjs +45 -0
- package/dist/lint/anti-slop/rules/no-array-filter-map.mjs +31 -0
- package/dist/lint/anti-slop/rules/no-chained-type-assertions.mjs +56 -0
- package/dist/lint/anti-slop/rules/no-conditional-empty-object-spread.mjs +32 -0
- package/dist/lint/anti-slop/rules/no-known-value-widening.mjs +236 -0
- package/dist/lint/anti-slop/rules/no-module-mocking.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-object-parameters.mjs +48 -0
- package/dist/lint/anti-slop/rules/no-reduce-accumulator-copy.mjs +85 -0
- package/dist/lint/anti-slop/rules/no-reflect-apply.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-reflect-get.mjs +21 -0
- package/dist/lint/anti-slop/rules/no-runtime-typeof.mjs +52 -0
- package/dist/lint/anti-slop/rules/no-shape-in-symbol-names.mjs +36 -0
- package/dist/lint/anti-slop/rules/no-unknown-parameters.mjs +44 -0
- package/dist/lint/anti-slop/rules/no-unknown-returns.mjs +47 -0
- package/dist/lint/anti-slop/rules/no-unknown-type-aliases.mjs +33 -0
- package/dist/lint/anti-slop/rules/no-unsafe-dictionary-type.mjs +121 -0
- package/dist/lint/anti-slop/rules/no-widen-then-assert.mjs +191 -0
- package/dist/lint/anti-slop/rules/require-readable-spacing.mjs +86 -0
- package/dist/lint/anti-slop/rules/require-safety-comment-for-type-assertion.mjs +82 -0
- package/dist/lint/anti-slop/shared/array-method.mjs +70 -0
- package/dist/lint/anti-slop/shared/child-nodes.mjs +24 -0
- package/dist/lint/anti-slop/shared/dictionary-types.mjs +248 -0
- package/dist/lint/anti-slop/shared/function-parameters.mjs +25 -0
- package/dist/lint/anti-slop/shared/lexical-type-parameters.mjs +21 -0
- package/dist/lint/anti-slop/shared/reflect-method.mjs +16 -0
- package/dist/lint/anti-slop/shared/scope.mjs +12 -0
- package/dist/lint/anti-slop/shared/string-literal.mjs +6 -0
- package/dist/lint/anti-slop/shared/type-alias-resolution.mjs +134 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +29 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-ast.mjs +32 -0
- package/dist/lint/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.mjs +608 -0
- package/dist/lint/config.d.mts +20 -0
- package/dist/lint/config.mjs +135 -0
- package/dist/lint/generic/effect-encoding.mjs +45 -0
- package/dist/lint/generic/entry-reexports.mjs +81 -0
- package/dist/lint/generic/env-at-entrypoints.mjs +65 -0
- package/dist/lint/generic/export-type-side-effects.mjs +22 -0
- package/dist/lint/generic/index-barrel.mjs +14 -0
- package/dist/lint/generic/log-messages.mjs +39 -0
- package/dist/lint/generic/plugin.d.mts +6 -0
- package/dist/lint/generic/plugin.mjs +26 -0
- package/dist/lint/generic/seeded-properties.mjs +78 -0
- package/dist/lint/plugins.d.mts +9 -0
- package/dist/lint/plugins.mjs +14 -0
- package/dist/lint/t3code/LICENSE +21 -0
- package/dist/lint/t3code/UPSTREAM.md +24 -0
- package/dist/lint/t3code/plugin.d.mts +2 -0
- package/dist/lint/t3code/plugin.mjs +20 -0
- package/dist/lint/t3code/rules/no-global-process-runtime.mjs +76 -0
- package/dist/lint/t3code/rules/no-inline-schema-compile.mjs +112 -0
- package/dist/lint/t3code/rules/no-manual-effect-runtime-in-tests.mjs +67 -0
- package/dist/lint/t3code/rules/no-native-title-tooltip.mjs +33 -0
- package/dist/lint/t3code/rules/no-test-in-loop.mjs +69 -0
- package/dist/lint/t3code/rules/no-unscoped-has.mjs +147 -0
- package/dist/lint/t3code/utils.mjs +21 -0
- package/package.json +52 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ref0/workspace
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The lint and workspace checks every ref-0 repo shares: Oxlint's shared settings and plugins, for
|
|
4
|
+
Vite+, and the `ref0-workspace` command. A repo takes it at one exact version through its catalog,
|
|
5
|
+
and a new version reaches the repo in the pull request that moves the catalog and fixes what it
|
|
6
|
+
finds.
|
|
7
|
+
|
|
8
|
+
## Lint
|
|
9
|
+
|
|
10
|
+
A repo's `lint/config.ts` merges its own settings over the shared ones, and registers the shared
|
|
11
|
+
plugins beside its own:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { base, merge } from '@ref0/workspace/lint/config';
|
|
15
|
+
import { antiSlop, antiSlopEffect, t3code, generic } from '@ref0/workspace/lint/plugins';
|
|
16
|
+
|
|
17
|
+
export const fmt = merge(base.fmt, { ignorePatterns: ['vendor/**'] });
|
|
18
|
+
|
|
19
|
+
export const lint = merge(base.lint, {
|
|
20
|
+
jsPlugins: [antiSlop, antiSlopEffect, t3code, generic, './lint/workspace.ts'],
|
|
21
|
+
overrides: [/* the repo's own */],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- `base.fmt` and `base.lint`: the shared format and lint settings. `REF0_LINT_TYPES=none` turns off
|
|
26
|
+
the type-aware rules, for a local check that runs them only on changed files.
|
|
27
|
+
- `merge(base, local)`: base first, local last. Ignores, plugins and overrides are joined, rules
|
|
28
|
+
and options merged, so a local rule wins; any other setting is local's.
|
|
29
|
+
- `@ref0/workspace/lint/plugins`: each plugin's file, as an absolute path for `jsPlugins`.
|
|
30
|
+
|
|
31
|
+
| Plugin | Rules | From |
|
|
32
|
+
| ---------------- | -------------------- | ---------------------------------------------------------------- |
|
|
33
|
+
| `antiSlop` | `anti-slop/*` | [dmmulroy/anti-slop](https://github.com/dmmulroy/anti-slop), MIT |
|
|
34
|
+
| `antiSlopEffect` | `anti-slop-effect/*` | the same |
|
|
35
|
+
| `t3code` | `t3code/*` | [pingdotgg/t3code](https://github.com/pingdotgg/t3code), MIT |
|
|
36
|
+
| `generic` | `ref0-generic/*` | ref-0 |
|
|
37
|
+
|
|
38
|
+
Each copied plugin keeps its licence and its `UPSTREAM.md`, which records its source commit and
|
|
39
|
+
changes, beside its code, in the package too.
|
|
40
|
+
|
|
41
|
+
`ref0-generic`'s rules: `seeded-properties`, `index-barrel-only` and `export-type-side-effects`,
|
|
42
|
+
which `base.lint` turns on, and `effect-encoding`, `log-messages`, `env-at-entrypoints` and
|
|
43
|
+
`entry-reexports`, which a repo turns on for its own files. `entry-reexports` takes the repo's root,
|
|
44
|
+
the folders of the packages whose entry files it checks, and the export condition that names an
|
|
45
|
+
entry point's source:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
'ref0-generic/entry-reexports': [
|
|
49
|
+
'error',
|
|
50
|
+
{ root: '/abs/repo', entries: ['packages/ui'], condition: '@ref0/source' },
|
|
51
|
+
],
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Checks
|
|
55
|
+
|
|
56
|
+
`ref0-workspace <check>`, from anywhere in the repo's checkout:
|
|
57
|
+
|
|
58
|
+
- `docs-budget`: the docs agents load, each within its budget: every skill's description, the
|
|
59
|
+
repo's own `SKILL.md`s, `AGENTS.md`s, the root's `RULES.md`, and `GLOSSARY.md`. It reads the
|
|
60
|
+
Markdown Git tracks. Skills the root's `skills-lock.json` names are upstream copies; without the
|
|
61
|
+
lock there are none.
|
|
62
|
+
|
|
63
|
+
## Releasing
|
|
64
|
+
|
|
65
|
+
From [ref-0/home](https://github.com/ref-0/home): bump `version` in this package's `package.json`
|
|
66
|
+
on main, a patch for a fix and a minor for a new rule, and once CI passes that commit, push the
|
|
67
|
+
tag `workspace-v<version>` at it. `release.yml` checks that CI passed exactly that commit and
|
|
68
|
+
publishes it.
|
|
69
|
+
|
|
70
|
+
Apache-2.0, but for the copied plugins, which keep their MIT licences.
|
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { docsBudget } from "./docs-budget.mjs";
|
|
3
|
+
import { argv, cwd, exit } from "node:process";
|
|
4
|
+
// src/bin.ts
|
|
5
|
+
/**
|
|
6
|
+
* `ref0-workspace <check>`: the checks every ref-0 repo runs, each a subcommand, run from anywhere
|
|
7
|
+
* in the repo's checkout.
|
|
8
|
+
*
|
|
9
|
+
* ref0-workspace docs-budget the docs agents load, each within its budget
|
|
10
|
+
*/
|
|
11
|
+
/** Each check: what it does, for the usage line, and its run, which answers its exit code. */
|
|
12
|
+
const checks = /* @__PURE__ */ new Map([["docs-budget", {
|
|
13
|
+
about: "the docs agents load, each within its budget",
|
|
14
|
+
run: () => {
|
|
15
|
+
const { docs, problems } = docsBudget(cwd());
|
|
16
|
+
for (const line of problems) console.error(line);
|
|
17
|
+
if (problems.length > 0) return 1;
|
|
18
|
+
console.error(`docs-budget: ${docs.length} Markdown files within budget`);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
}]]);
|
|
22
|
+
const usage = ["usage: ref0-workspace <check>", ...[...checks].map(([name, { about }]) => ` ${name.padEnd(14)}${about}`)].join("\n");
|
|
23
|
+
const [name, ...rest] = argv.slice(2);
|
|
24
|
+
const check = name === void 0 ? void 0 : checks.get(name);
|
|
25
|
+
if (check === void 0 || rest.length > 0) {
|
|
26
|
+
console.error(name === void 0 || check !== void 0 ? usage : `ref0-workspace: no check ${name}\n${usage}`);
|
|
27
|
+
exit(2);
|
|
28
|
+
}
|
|
29
|
+
exit(check.run());
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// src/docs-budget.ts
|
|
5
|
+
/**
|
|
6
|
+
* Fails when a doc agents load outgrows its budget, so the bloat compacted in ref0's #2265 can't
|
|
7
|
+
* grow back.
|
|
8
|
+
*
|
|
9
|
+
* ref0-workspace docs-budget
|
|
10
|
+
*
|
|
11
|
+
* It reads the Markdown the current repo tracks, from the root of the checkout it runs in. Root
|
|
12
|
+
* `AGENTS.md` and every skill's description load into every agent session, and an app's
|
|
13
|
+
* `AGENTS.md` or a `SKILL.md` whenever an agent works there, so each byte costs on each run. The
|
|
14
|
+
* skill list has a budget of its own, and a skill past it loses its description. `GLOSSARY.md` is
|
|
15
|
+
* read and searched often. The budgets, from what each held after #2265, with headroom:
|
|
16
|
+
*
|
|
17
|
+
* - Every skill's description, upstream copies too: at most 320 characters. An upkeep run that
|
|
18
|
+
* updates a copy can bring its source's longer description back, and fails here until it's cut.
|
|
19
|
+
* - The repo's own `SKILL.md`: at most 10 KB. Upstream copies, those the root's `skills-lock.json`
|
|
20
|
+
* names and Cloudflare's `cf-*`, are left as their source wrote them. A repo without the lock
|
|
21
|
+
* has no upstream copies.
|
|
22
|
+
* - Root `AGENTS.md`: at most 12 KB. Any other `AGENTS.md`: at most 8 KB. Root `RULES.md`, the rules
|
|
23
|
+
* every repo's `AGENTS.md` imports, so they load beside each one: at most 8 KB.
|
|
24
|
+
* - `GLOSSARY.md`: no tables, since `vp fmt` pads each cell to its column's widest, and no entry
|
|
25
|
+
* over 400 characters.
|
|
26
|
+
* - None of these keeps history, such as "Changed 15 Oct 2026": `git log` holds it.
|
|
27
|
+
*/
|
|
28
|
+
const budgets = {
|
|
29
|
+
description: 320,
|
|
30
|
+
skill: 1e4,
|
|
31
|
+
rootAgents: 12e3,
|
|
32
|
+
agents: 8e3,
|
|
33
|
+
rules: 8e3,
|
|
34
|
+
glossaryEntry: 400
|
|
35
|
+
};
|
|
36
|
+
const history = /\b(?:Changed|Decided|Renamed|Hidden|Dropped|Added) \d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{4}\b/;
|
|
37
|
+
/**
|
|
38
|
+
* A `SKILL.md`'s frontmatter description, as one line: plain, quoted, or a folded `>-` block.
|
|
39
|
+
* `undefined` when it has none.
|
|
40
|
+
*/
|
|
41
|
+
const description = (text) => {
|
|
42
|
+
const lines = (/^---\n([\s\S]*?)\n---/.exec(text)?.[1])?.split("\n") ?? [];
|
|
43
|
+
const start = lines.findIndex((line) => line.startsWith("description:"));
|
|
44
|
+
if (start === -1) return void 0;
|
|
45
|
+
const first = lines[start].slice(12).trim();
|
|
46
|
+
const rest = lines.slice(start + 1);
|
|
47
|
+
const end = rest.findIndex((line) => !line.startsWith(" "));
|
|
48
|
+
const folded = (end === -1 ? rest : rest.slice(0, end)).map((line) => line.trim());
|
|
49
|
+
return (/^[>|]-?$/.test(first) ? folded.join(" ") : first).replace(/^(["'])([\s\S]*)\1$/, "$2");
|
|
50
|
+
};
|
|
51
|
+
const bytes = (text) => Buffer.byteLength(text, "utf8");
|
|
52
|
+
const kb = (size) => `${(size / 1e3).toFixed(1)} KB`;
|
|
53
|
+
/** What the docs break, one line each, with what to do about it. */
|
|
54
|
+
const problems = (docs, upstream) => {
|
|
55
|
+
const found = [];
|
|
56
|
+
for (const { path, text } of docs) {
|
|
57
|
+
const skill = /^\.agents\/skills\/([^/]+)\/SKILL\.md$/.exec(path)?.[1];
|
|
58
|
+
const agents = path === "AGENTS.md" || path.endsWith("/AGENTS.md");
|
|
59
|
+
const rules = path === "RULES.md";
|
|
60
|
+
const glossary = path === "GLOSSARY.md";
|
|
61
|
+
if (skill === void 0 && !agents && !rules && !glossary) continue;
|
|
62
|
+
const ours = skill === void 0 || !(upstream.has(skill) || skill.startsWith("cf-"));
|
|
63
|
+
const said = history.exec(text)?.[0];
|
|
64
|
+
if (ours && said !== void 0) found.push(`${path}: "${said}" is history; leave it to git log and say what holds now.`);
|
|
65
|
+
if (skill !== void 0) {
|
|
66
|
+
const about = description(text) ?? "";
|
|
67
|
+
if (about.length > budgets.description) found.push(`${path}: its description is ${about.length} characters, over ${budgets.description}. Say what it does, when to use it and which sibling to use instead; cut the method.`);
|
|
68
|
+
if (ours && bytes(text) > budgets.skill) found.push(`${path}: ${kb(bytes(text))}, over ${kb(budgets.skill)}. Move what one step or case needs to references/, and point to code instead of restating it.`);
|
|
69
|
+
}
|
|
70
|
+
if (agents || rules) {
|
|
71
|
+
const limit = rules ? budgets.rules : path === "AGENTS.md" ? budgets.rootAgents : budgets.agents;
|
|
72
|
+
if (bytes(text) > limit) found.push(`${path}: ${kb(bytes(text))}, over ${kb(limit)}. Keep each rule in one place, link the skill or script that owns the detail, and point to code for values.`);
|
|
73
|
+
}
|
|
74
|
+
if (glossary) {
|
|
75
|
+
const lines = text.split("\n");
|
|
76
|
+
if (lines.some((line) => line.startsWith("|"))) found.push(`${path}: has a table. Write each term as \`**Term**: meaning\`, since vp fmt pads table cells.`);
|
|
77
|
+
for (const entry of lines.filter((line) => line.startsWith("**"))) {
|
|
78
|
+
if (entry.length <= budgets.glossaryEntry) continue;
|
|
79
|
+
const term = /^\*\*(.+?)\*\*/.exec(entry)?.[1] ?? entry.slice(0, 40);
|
|
80
|
+
found.push(`${path}: ${term} is ${entry.length} characters, over ${budgets.glossaryEntry}. Keep its meaning, the word to use and where it lives in code; the code says how it behaves.`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return found;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The skills the skills CLI installed, by folder name, from the lock at `root`: none when there's
|
|
88
|
+
* no lock.
|
|
89
|
+
*/
|
|
90
|
+
const upstreamSkills = (root) => {
|
|
91
|
+
const path = join(root, "skills-lock.json");
|
|
92
|
+
if (!existsSync(path)) return /* @__PURE__ */ new Set();
|
|
93
|
+
const lock = JSON.parse(readFileSync(path, "utf8"));
|
|
94
|
+
return new Set(Object.keys(lock.skills));
|
|
95
|
+
};
|
|
96
|
+
/** The Markdown the checkout at `root` tracks, each by its path from the root, with its text. */
|
|
97
|
+
const trackedDocs = (root) => execFileSync("git", [
|
|
98
|
+
"ls-files",
|
|
99
|
+
"-z",
|
|
100
|
+
"--",
|
|
101
|
+
"*.md"
|
|
102
|
+
], {
|
|
103
|
+
cwd: root,
|
|
104
|
+
encoding: "utf8"
|
|
105
|
+
}).split("\0").filter((path) => path !== "").map((path) => ({
|
|
106
|
+
path,
|
|
107
|
+
text: readFileSync(join(root, path), "utf8")
|
|
108
|
+
}));
|
|
109
|
+
/** The checkout `from` is in: its root, its tracked docs, and what they break. */
|
|
110
|
+
const docsBudget = (from) => {
|
|
111
|
+
const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
112
|
+
cwd: from,
|
|
113
|
+
encoding: "utf8"
|
|
114
|
+
}).trim();
|
|
115
|
+
const docs = trackedDocs(root);
|
|
116
|
+
return {
|
|
117
|
+
root,
|
|
118
|
+
docs,
|
|
119
|
+
problems: problems(docs, upstreamSkills(root))
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export { budgets, description, docsBudget, problems, trackedDocs, upstreamSkills };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dillon Mulroy
|
|
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.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Anti-slop provenance
|
|
2
|
+
|
|
3
|
+
- Source: <https://github.com/dmmulroy/anti-slop>
|
|
4
|
+
- Source commit: `c44ef22ca116d0ba62a3ff663a0bd13a3f3fa40b`
|
|
5
|
+
- Source snapshot: `skills/install-anti-slop/assets/anti-slop/` at that commit
|
|
6
|
+
- Source licence: MIT, `LICENSE` beside this file, copied from the source commit
|
|
7
|
+
- Installed generic plugin: `src/lint/anti-slop/plugin.ts`, which `@ref0/workspace/lint/plugins` exports as `antiSlop`
|
|
8
|
+
- Installed Effect plugin: `src/lint/anti-slop/effect/plugin.ts`, exported as `antiSlopEffect`
|
|
9
|
+
- Oxlint plugin API: imported from `vite-plus/lint/plugins` instead of `@oxlint/plugins`, so it always matches the Oxlint version bundled by Vite+. `vp migrate` rewrote the imports for Vite+ 1.0.
|
|
10
|
+
- Performance deviations, each reporting the same: `no-widen-then-assert` reads a file's scopes only at its first assertion of a binding; `no-known-value-widening` keeps a file's calls and assignments and resolves them at its end only when it declares a type predicate or a binding with a widening type; `no-module-mocking` resolves a call's object only once its method is a mock's; and `shared/child-nodes.ts` tests each value without a Schema guard. Each kept lint from analysing scopes, or walking with a Schema, on every file, which made the anti-slop rules most of a lint run.
|
|
11
|
+
- Intentional source deviation: `require-readable-spacing` does not split related declarations merely because one wraps, and it requires an unbraced guard to remain attached to its declaration. This keeps formatting aligned with ref-0's semantic-paragraph policy in `RULES.md`.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { noManualEffectErrorTagRule } from "./rules/no-manual-effect-error-tag.mjs";
|
|
2
|
+
import { noManualTagComparisonRule } from "./rules/no-manual-tag-comparison.mjs";
|
|
3
|
+
import { noManualTaggedConstructionRule } from "./rules/no-manual-tagged-construction.mjs";
|
|
4
|
+
import { noServiceConstructorImportsRule } from "./rules/no-service-constructor-imports.mjs";
|
|
5
|
+
import { preferEffectMatchRule } from "./rules/prefer-effect-match.mjs";
|
|
6
|
+
import { eslintCompatPlugin } from "vite-plus/lint/plugins";
|
|
7
|
+
// src/lint/anti-slop/effect/plugin.ts
|
|
8
|
+
/** Opt-in Oxlint rules for Effect service and Layer architecture. */
|
|
9
|
+
const antiSlopEffectPlugin = eslintCompatPlugin({
|
|
10
|
+
meta: { name: "anti-slop-effect" },
|
|
11
|
+
rules: {
|
|
12
|
+
"no-manual-effect-error-tag": noManualEffectErrorTagRule,
|
|
13
|
+
"no-manual-tag-comparison": noManualTagComparisonRule,
|
|
14
|
+
"no-manual-tagged-construction": noManualTaggedConstructionRule,
|
|
15
|
+
"no-service-constructor-imports": noServiceConstructorImportsRule,
|
|
16
|
+
"prefer-effect-match": preferEffectMatchRule
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
export { antiSlopEffectPlugin as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isInsideBroadEffectHandler, isReasonTagMember, isTagMember, tagMemberFromComparison } from "../shared/tagged-values.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/effect/rules/no-manual-effect-error-tag.ts
|
|
4
|
+
const noManualEffectErrorTagRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: { description: "Use Effect tagged error handlers instead of manually branching on `_tag` in a catch handler." },
|
|
8
|
+
messages: {
|
|
9
|
+
tag: "Use Effect.catchTag or Effect.catchTags instead of manually discriminating a tagged error in a broad Effect catch handler.",
|
|
10
|
+
reason: "Use Effect.catchReason or Effect.catchReasons instead of manually discriminating a tagged `reason` in a broad Effect catch handler."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
BinaryExpression(node) {
|
|
16
|
+
const tagMember = tagMemberFromComparison(node);
|
|
17
|
+
if (tagMember === void 0 || !isInsideBroadEffectHandler(node)) return;
|
|
18
|
+
context.report({
|
|
19
|
+
node,
|
|
20
|
+
messageId: isReasonTagMember(tagMember) ? "reason" : "tag"
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
SwitchStatement(node) {
|
|
24
|
+
if (!isTagMember(node.discriminant) || !isInsideBroadEffectHandler(node)) return;
|
|
25
|
+
context.report({
|
|
26
|
+
node,
|
|
27
|
+
messageId: isReasonTagMember(node.discriminant) ? "reason" : "tag"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export { noManualEffectErrorTagRule };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isInsideBroadEffectHandler, isTagMember, tagMemberFromComparison } from "../shared/tagged-values.mjs";
|
|
2
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
3
|
+
// src/lint/anti-slop/effect/rules/no-manual-tag-comparison.ts
|
|
4
|
+
const noManualTagComparisonRule = defineRule({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "problem",
|
|
7
|
+
docs: { description: "Use Effect Match or Predicate helpers instead of manually branching on `_tag`." },
|
|
8
|
+
messages: {
|
|
9
|
+
manualComparison: "Use Match.tag/Match.tags for tagged-value branching, or Predicate.isTagged for a simple reusable predicate.",
|
|
10
|
+
manualSwitch: "Use Match.value(value).pipe(Match.tag/Match.tags/Match.tagsExhaustive) or the tagged enum `$match` helper instead of switching on `_tag`."
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
createOnce(context) {
|
|
14
|
+
return {
|
|
15
|
+
BinaryExpression(node) {
|
|
16
|
+
if (tagMemberFromComparison(node) === void 0 || isInsideBroadEffectHandler(node)) return;
|
|
17
|
+
context.report({
|
|
18
|
+
node,
|
|
19
|
+
messageId: "manualComparison"
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
SwitchStatement(node) {
|
|
23
|
+
if (!isTagMember(node.discriminant) || isInsideBroadEffectHandler(node)) return;
|
|
24
|
+
context.report({
|
|
25
|
+
node,
|
|
26
|
+
messageId: "manualSwitch"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export { noManualTagComparisonRule };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isStringLiteral } from "../../shared/string-literal.mjs";
|
|
2
|
+
import { isMatchPatternObject, propertyName } from "../shared/tagged-values.mjs";
|
|
3
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
4
|
+
// src/lint/anti-slop/effect/rules/no-manual-tagged-construction.ts
|
|
5
|
+
const noManualTaggedConstructionRule = defineRule({
|
|
6
|
+
meta: {
|
|
7
|
+
type: "problem",
|
|
8
|
+
docs: { description: "Construct tagged values with their existing Effect constructor instead of writing `_tag` manually." },
|
|
9
|
+
messages: { manualConstruction: "Use the existing Schema tagged `.make`, tagged class/error constructor, or Data.taggedEnum variant constructor instead of writing a literal `_tag` object." }
|
|
10
|
+
},
|
|
11
|
+
createOnce(context) {
|
|
12
|
+
return { ObjectExpression(node) {
|
|
13
|
+
if (isMatchPatternObject(node)) return;
|
|
14
|
+
const tag = node.properties.find((property) => property.type === "Property" && propertyName(property) === "_tag" && isStringLiteral(property.value));
|
|
15
|
+
if (tag !== void 0) context.report({
|
|
16
|
+
node: tag,
|
|
17
|
+
messageId: "manualConstruction"
|
|
18
|
+
});
|
|
19
|
+
} };
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export { noManualTaggedConstructionRule };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/effect/rules/no-service-constructor-imports.ts
|
|
3
|
+
const SERVICE_CONSTRUCTOR_NAME = /^make[A-Z]/u;
|
|
4
|
+
const TEST_FILE = /\.(?:test|spec)\.[cm]?[jt]sx?$/u;
|
|
5
|
+
function isProjectLocalImport(source) {
|
|
6
|
+
return source.startsWith("./") || source.startsWith("../");
|
|
7
|
+
}
|
|
8
|
+
function getImportedName(specifier) {
|
|
9
|
+
if (specifier.imported.type === "Identifier") return specifier.imported.name;
|
|
10
|
+
return specifier.imported.value;
|
|
11
|
+
}
|
|
12
|
+
/** Keep dependency-bearing Effect service constructors local to their owning capability modules. */
|
|
13
|
+
const noServiceConstructorImportsRule = defineRule({
|
|
14
|
+
meta: {
|
|
15
|
+
type: "problem",
|
|
16
|
+
docs: { description: "Disallow project-local make<CapabilityName> imports outside test and spec files." },
|
|
17
|
+
messages: { serviceConstructorImport: "Do not import Effect service constructor \"{{name}}\" into runtime code. Import the owning Layer, yield the contextual service, and allow its requirements to propagate to the composition root." }
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
const isTestFile = TEST_FILE.test(context.filename.replaceAll("\\", "/"));
|
|
21
|
+
return { ImportDeclaration(node) {
|
|
22
|
+
if (isTestFile || !isProjectLocalImport(node.source.value)) return;
|
|
23
|
+
for (const specifier of node.specifiers) {
|
|
24
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
25
|
+
const importedName = getImportedName(specifier);
|
|
26
|
+
if (!SERVICE_CONSTRUCTOR_NAME.test(importedName)) continue;
|
|
27
|
+
context.report({
|
|
28
|
+
node: specifier,
|
|
29
|
+
messageId: "serviceConstructorImport",
|
|
30
|
+
data: { name: importedName }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} };
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
export { noServiceConstructorImportsRule };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
// src/lint/anti-slop/effect/rules/prefer-effect-match.ts
|
|
3
|
+
const equalityOperators = /* @__PURE__ */ new Set([
|
|
4
|
+
"==",
|
|
5
|
+
"===",
|
|
6
|
+
"!=",
|
|
7
|
+
"!=="
|
|
8
|
+
]);
|
|
9
|
+
const preferEffectMatchRule = defineRule({
|
|
10
|
+
meta: {
|
|
11
|
+
type: "problem",
|
|
12
|
+
docs: { description: "Use Match from Effect for chained literal ternaries over the same value." },
|
|
13
|
+
messages: { preferMatch: "Use Match from Effect instead of a chained literal ternary." }
|
|
14
|
+
},
|
|
15
|
+
createOnce(context) {
|
|
16
|
+
const isLiteral = (node) => node.type === "Literal" || node.type === "TemplateLiteral" && node.expressions.length === 0;
|
|
17
|
+
const comparedValue = (node) => {
|
|
18
|
+
if (node.type !== "BinaryExpression" || !equalityOperators.has(node.operator)) return;
|
|
19
|
+
if (isLiteral(node.left)) return context.sourceCode.getText(node.right);
|
|
20
|
+
if (isLiteral(node.right)) return context.sourceCode.getText(node.left);
|
|
21
|
+
};
|
|
22
|
+
return { ConditionalExpression(node) {
|
|
23
|
+
if (node.parent?.type === "ConditionalExpression") return;
|
|
24
|
+
const value = comparedValue(node.test);
|
|
25
|
+
if (value === void 0) return;
|
|
26
|
+
let alternate = node.alternate;
|
|
27
|
+
let literalChecks = 1;
|
|
28
|
+
while (alternate.type === "ConditionalExpression") {
|
|
29
|
+
if (comparedValue(alternate.test) !== value) return;
|
|
30
|
+
literalChecks += 1;
|
|
31
|
+
alternate = alternate.alternate;
|
|
32
|
+
}
|
|
33
|
+
if (literalChecks > 1) context.report({
|
|
34
|
+
node,
|
|
35
|
+
messageId: "preferMatch"
|
|
36
|
+
});
|
|
37
|
+
} };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
export { preferEffectMatchRule };
|