codeveto 0.1.0__py3-none-any.whl
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.
- codeveto/__init__.py +3 -0
- codeveto/__main__.py +8 -0
- codeveto/ai/__init__.py +19 -0
- codeveto/ai/harness.py +303 -0
- codeveto/ai/packets.py +855 -0
- codeveto/ai/policy.py +222 -0
- codeveto/ai/prompt.py +101 -0
- codeveto/ai/providers/__init__.py +178 -0
- codeveto/ai/providers/claude.py +247 -0
- codeveto/ai/providers/openai_compat.py +246 -0
- codeveto/ai/runner.py +293 -0
- codeveto/ai/verify.py +324 -0
- codeveto/anchor.py +211 -0
- codeveto/cli.py +247 -0
- codeveto/cli_explain.py +49 -0
- codeveto/cli_hook.py +31 -0
- codeveto/cli_init.py +254 -0
- codeveto/cli_mcp.py +29 -0
- codeveto/cli_packets.py +35 -0
- codeveto/cli_publish.py +29 -0
- codeveto/cli_review.py +362 -0
- codeveto/cli_rules.py +78 -0
- codeveto/cli_verify.py +47 -0
- codeveto/config.py +1229 -0
- codeveto/data/README.md +16 -0
- codeveto/data/ai-wire.schema.json +53 -0
- codeveto/data/prompts/system.md +57 -0
- codeveto/data/report-v1.schema.json +268 -0
- codeveto/data/templates/forgejo-codeveto.yml +104 -0
- codeveto/data/templates/github-codeveto.yml +18 -0
- codeveto/embedded.py +311 -0
- codeveto/engine.py +1570 -0
- codeveto/git.py +1549 -0
- codeveto/globs.py +348 -0
- codeveto/integrations/__init__.py +1 -0
- codeveto/integrations/hooks.py +327 -0
- codeveto/integrations/mcp.py +770 -0
- codeveto/integrations/mcp_ai.py +77 -0
- codeveto/integrations/prepush.py +222 -0
- codeveto/jsonsafe.py +60 -0
- codeveto/languages.py +539 -0
- codeveto/lexers.py +2560 -0
- codeveto/model.py +372 -0
- codeveto/publish/__init__.py +28 -0
- codeveto/publish/action.py +330 -0
- codeveto/publish/common.py +84 -0
- codeveto/publish/diff.py +208 -0
- codeveto/publish/event.py +241 -0
- codeveto/publish/forgejo.py +184 -0
- codeveto/publish/github.py +380 -0
- codeveto/publish/http.py +263 -0
- codeveto/publish/pull.py +218 -0
- codeveto/publish/untrusted.py +110 -0
- codeveto/py.typed +0 -0
- codeveto/redact.py +113 -0
- codeveto/render/__init__.py +64 -0
- codeveto/render/agent.py +43 -0
- codeveto/render/github.py +101 -0
- codeveto/render/json.py +23 -0
- codeveto/render/markdown.py +208 -0
- codeveto/render/safe.py +249 -0
- codeveto/render/sarif.py +217 -0
- codeveto/render/text.py +210 -0
- codeveto/report.py +252 -0
- codeveto/rules/__init__.py +84 -0
- codeveto/rules/agent.py +2972 -0
- codeveto/rules/base.py +1026 -0
- codeveto/rules/ci.py +1708 -0
- codeveto/rules/config.py +493 -0
- codeveto/rules/deps.py +1693 -0
- codeveto/rules/docker.py +479 -0
- codeveto/rules/examples/__init__.py +148 -0
- codeveto/rules/examples/agent.py +839 -0
- codeveto/rules/examples/ci.py +1046 -0
- codeveto/rules/examples/config.py +191 -0
- codeveto/rules/examples/deps.py +369 -0
- codeveto/rules/examples/docker.py +157 -0
- codeveto/rules/examples/go.py +241 -0
- codeveto/rules/examples/hygiene.py +466 -0
- codeveto/rules/examples/js.py +462 -0
- codeveto/rules/examples/python.py +595 -0
- codeveto/rules/examples/rust.py +268 -0
- codeveto/rules/examples/secrets.py +561 -0
- codeveto/rules/examples/security.py +608 -0
- codeveto/rules/examples/shell.py +174 -0
- codeveto/rules/examples/sql.py +194 -0
- codeveto/rules/examples/tests.py +497 -0
- codeveto/rules/go.py +328 -0
- codeveto/rules/hygiene.py +1094 -0
- codeveto/rules/js.py +768 -0
- codeveto/rules/python.py +1642 -0
- codeveto/rules/rust.py +209 -0
- codeveto/rules/secrets.py +1335 -0
- codeveto/rules/security.py +3680 -0
- codeveto/rules/shell.py +867 -0
- codeveto/rules/sql.py +629 -0
- codeveto/rules/tests.py +1404 -0
- codeveto/schema.py +384 -0
- codeveto/statements.py +607 -0
- codeveto/worktree.py +1176 -0
- codeveto/yamlish.py +1179 -0
- codeveto-0.1.0.dist-info/METADATA +253 -0
- codeveto-0.1.0.dist-info/RECORD +106 -0
- codeveto-0.1.0.dist-info/WHEEL +4 -0
- codeveto-0.1.0.dist-info/entry_points.txt +2 -0
- codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"""Examples for the js pack."""
|
|
2
|
+
|
|
3
|
+
from codeveto.rules.base import bad, good
|
|
4
|
+
|
|
5
|
+
EXAMPLES = {
|
|
6
|
+
"js/debugger": [
|
|
7
|
+
bad(
|
|
8
|
+
"src/cart/total.js",
|
|
9
|
+
"export function total(items) {\n"
|
|
10
|
+
" debugger; // expect\n"
|
|
11
|
+
" return items.reduce((sum, item) => sum + item.price, 0);\n"
|
|
12
|
+
"}\n",
|
|
13
|
+
old="export function total(items) {\n"
|
|
14
|
+
" return items.reduce((sum, item) => sum + item.price, 0);\n"
|
|
15
|
+
"}\n",
|
|
16
|
+
note="A leftover breakpoint in application code.",
|
|
17
|
+
),
|
|
18
|
+
bad(
|
|
19
|
+
"src/components/Checkout.tsx",
|
|
20
|
+
"export function Checkout({ order }: { order: Order }) {\n"
|
|
21
|
+
" if (!order.total) debugger // expect\n"
|
|
22
|
+
" return <p>{order.total}</p>;\n"
|
|
23
|
+
"}\n",
|
|
24
|
+
note="After an if header and without a semicolon.",
|
|
25
|
+
),
|
|
26
|
+
bad(
|
|
27
|
+
"src/components/Counter.vue",
|
|
28
|
+
"<template>\n"
|
|
29
|
+
' <button @click="count++">{{ count }}</button>\n'
|
|
30
|
+
"</template>\n"
|
|
31
|
+
'<script setup lang="ts">\n'
|
|
32
|
+
"import { ref, watch } from 'vue';\n"
|
|
33
|
+
"const count = ref(0);\n"
|
|
34
|
+
"watch(count, () => { debugger; }); // expect\n"
|
|
35
|
+
"</script>\n",
|
|
36
|
+
note="Inside the script block of a Vue single-file component.",
|
|
37
|
+
),
|
|
38
|
+
good(
|
|
39
|
+
"src/devtools/options.js",
|
|
40
|
+
"// Set debugger: true to pause on load.\n"
|
|
41
|
+
"export const options = { debugger: false, label: 'debugger' };\n"
|
|
42
|
+
"export const enabled = options.debugger;\n"
|
|
43
|
+
"export const pattern = /debugger;/;\n",
|
|
44
|
+
note="An object key, a property, a string, a regex literal and a comment.",
|
|
45
|
+
),
|
|
46
|
+
good(
|
|
47
|
+
"src/components/Help.jsx",
|
|
48
|
+
"export function Help() {\n"
|
|
49
|
+
" return (\n"
|
|
50
|
+
" <p>\n"
|
|
51
|
+
" Open the browser debugger to step through the code.\n"
|
|
52
|
+
" </p>\n"
|
|
53
|
+
" );\n"
|
|
54
|
+
"}\n",
|
|
55
|
+
note="The word in JSX text.",
|
|
56
|
+
),
|
|
57
|
+
good(
|
|
58
|
+
"src/cart/total.test.js",
|
|
59
|
+
"test('total', () => {\n debugger;\n expect(total([])).toBe(0);\n});\n",
|
|
60
|
+
note="Test files are exempt.",
|
|
61
|
+
),
|
|
62
|
+
],
|
|
63
|
+
"js/public-env-secret": [
|
|
64
|
+
bad(
|
|
65
|
+
"src/lib/stripe.ts",
|
|
66
|
+
"import Stripe from 'stripe';\n"
|
|
67
|
+
"const key = process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY!; // expect\n"
|
|
68
|
+
"export const stripe = new Stripe(key);\n",
|
|
69
|
+
note="Next.js inlines every NEXT_PUBLIC_ variable into the client bundle.",
|
|
70
|
+
),
|
|
71
|
+
bad(
|
|
72
|
+
"src/lib/supabase.js",
|
|
73
|
+
"import { createClient } from '@supabase/supabase-js';\n"
|
|
74
|
+
"export const admin = createClient(\n"
|
|
75
|
+
" import.meta.env.VITE_SUPABASE_URL,\n"
|
|
76
|
+
" import.meta.env.VITE_SUPABASE_SERVICE_ROLE_KEY, // expect\n"
|
|
77
|
+
");\n",
|
|
78
|
+
note="The service-role key bypasses row-level security; the URL is fine.",
|
|
79
|
+
),
|
|
80
|
+
bad(
|
|
81
|
+
".env.local",
|
|
82
|
+
"NEXT_PUBLIC_SITE_URL=http://localhost:3000\n"
|
|
83
|
+
"NEXT_PUBLIC_DATABASE_PASSWORD= # expect\n",
|
|
84
|
+
note="Defined in a .env file with a browser-exposed prefix.",
|
|
85
|
+
),
|
|
86
|
+
bad(
|
|
87
|
+
"vite.config.ts",
|
|
88
|
+
"import { defineConfig } from 'vite';\n"
|
|
89
|
+
"export default defineConfig({\n"
|
|
90
|
+
" define: {\n"
|
|
91
|
+
" 'import.meta.env.VITE_JWT_SECRET': JSON.stringify(jwtSecret), // expect\n"
|
|
92
|
+
" },\n"
|
|
93
|
+
"});\n",
|
|
94
|
+
note="A define key in a framework config.",
|
|
95
|
+
),
|
|
96
|
+
bad(
|
|
97
|
+
"src/lib/maps.ts",
|
|
98
|
+
"export const mapsKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY; // expect\n"
|
|
99
|
+
"export const apiUrl = import.meta.env.VITE_API_URL;\n",
|
|
100
|
+
note="Warning tier: named like a credential; restrict the key or proxy it.",
|
|
101
|
+
),
|
|
102
|
+
bad(
|
|
103
|
+
"apps/web/.env",
|
|
104
|
+
"REACT_APP_API_URL=http://localhost:8080\nREACT_APP_GITHUB_TOKEN= # expect\n",
|
|
105
|
+
note="Warning tier in a .env file: a token without a secret's name.",
|
|
106
|
+
),
|
|
107
|
+
good(
|
|
108
|
+
"src/lib/supabase.ts",
|
|
109
|
+
"import { createClient } from '@supabase/supabase-js';\n"
|
|
110
|
+
"export const supabase = createClient(\n"
|
|
111
|
+
" process.env.NEXT_PUBLIC_SUPABASE_URL!,\n"
|
|
112
|
+
" process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,\n"
|
|
113
|
+
");\n"
|
|
114
|
+
"export const stripeKey = import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY;\n"
|
|
115
|
+
"export const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN;\n",
|
|
116
|
+
note="Anon, publishable keys and DSNs are designed to be public.",
|
|
117
|
+
),
|
|
118
|
+
good(
|
|
119
|
+
"src/server/env.ts",
|
|
120
|
+
"// Never name a secret NEXT_PUBLIC_STRIPE_SECRET_KEY.\n"
|
|
121
|
+
"const FORBIDDEN = ['NEXT_PUBLIC_STRIPE_SECRET_KEY'];\n"
|
|
122
|
+
"export const secret = process.env.STRIPE_SECRET_KEY;\n"
|
|
123
|
+
"export const resetUrl = process.env.NEXT_PUBLIC_PASSWORD_RESET_URL;\n"
|
|
124
|
+
"export const beta = import.meta.env.VITE_PRIVATE_BETA_ENABLED;\n",
|
|
125
|
+
note="Mentions in comments and lists, a server-only secret, names holding no secret.",
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
"js/empty-catch": [
|
|
129
|
+
bad(
|
|
130
|
+
"src/storage.js",
|
|
131
|
+
"export function load(key) {\n"
|
|
132
|
+
" try {\n"
|
|
133
|
+
" return JSON.parse(localStorage.getItem(key));\n"
|
|
134
|
+
" } catch (err) {} // expect\n"
|
|
135
|
+
"}\n",
|
|
136
|
+
),
|
|
137
|
+
bad(
|
|
138
|
+
"src/storage.ts",
|
|
139
|
+
"export function save(key: string, value: unknown): void {\n"
|
|
140
|
+
" try {\n"
|
|
141
|
+
" localStorage.setItem(key, JSON.stringify(value));\n"
|
|
142
|
+
" } catch { // expect\n"
|
|
143
|
+
" }\n"
|
|
144
|
+
"}\n",
|
|
145
|
+
note="Optional catch binding, the block spread over two lines.",
|
|
146
|
+
),
|
|
147
|
+
good(
|
|
148
|
+
"src/storage.js",
|
|
149
|
+
"export function load(key) {\n"
|
|
150
|
+
" try {\n"
|
|
151
|
+
" return JSON.parse(localStorage.getItem(key));\n"
|
|
152
|
+
" } catch {\n"
|
|
153
|
+
" // Private mode: storage is unavailable, fall back to defaults.\n"
|
|
154
|
+
" return null;\n"
|
|
155
|
+
" }\n"
|
|
156
|
+
"}\n",
|
|
157
|
+
),
|
|
158
|
+
good(
|
|
159
|
+
"src/prefetch.js",
|
|
160
|
+
"export function prefetch(url) {\n"
|
|
161
|
+
" fetch(url).catch(() => {});\n"
|
|
162
|
+
" try { warm(url); } catch { /* best effort */ }\n"
|
|
163
|
+
"}\n",
|
|
164
|
+
note="A promise .catch and a block that documents the ignore.",
|
|
165
|
+
),
|
|
166
|
+
],
|
|
167
|
+
"js/console-log": [
|
|
168
|
+
bad(
|
|
169
|
+
"src/api/orders.ts",
|
|
170
|
+
"export async function createOrder(input: OrderInput) {\n"
|
|
171
|
+
" console.log('creating order', input); // expect\n"
|
|
172
|
+
" return db.orders.insert(input);\n"
|
|
173
|
+
"}\n",
|
|
174
|
+
),
|
|
175
|
+
bad(
|
|
176
|
+
"src/components/Cart.jsx",
|
|
177
|
+
"export function Cart({ items }) {\n"
|
|
178
|
+
" window.console.debug(items); // expect\n"
|
|
179
|
+
" return <ul>{items.length}</ul>;\n"
|
|
180
|
+
"}\n",
|
|
181
|
+
),
|
|
182
|
+
good(
|
|
183
|
+
"src/api/orders.ts",
|
|
184
|
+
"export async function createOrder(input: OrderInput) {\n"
|
|
185
|
+
" try {\n"
|
|
186
|
+
" return await db.orders.insert(input);\n"
|
|
187
|
+
" } catch (err) {\n"
|
|
188
|
+
" console.error('order failed', err);\n"
|
|
189
|
+
" throw err;\n"
|
|
190
|
+
" }\n"
|
|
191
|
+
"}\n"
|
|
192
|
+
"// console.log('debug');\n",
|
|
193
|
+
note="console.error is deliberate output; a commented-out call is not code.",
|
|
194
|
+
),
|
|
195
|
+
good(
|
|
196
|
+
"scripts/seed.js",
|
|
197
|
+
"import { seed } from '../src/db.js';\n"
|
|
198
|
+
"const count = await seed();\n"
|
|
199
|
+
"console.log(`seeded ${count} rows`);\n",
|
|
200
|
+
note="Scripts print by design.",
|
|
201
|
+
),
|
|
202
|
+
good(
|
|
203
|
+
"packages/cli/main.js",
|
|
204
|
+
"#!/usr/bin/env node\nconsole.log('usage: shop <command>');\n",
|
|
205
|
+
note="A node shebang marks a CLI entry point.",
|
|
206
|
+
),
|
|
207
|
+
],
|
|
208
|
+
"js/ts-ignore": [
|
|
209
|
+
bad(
|
|
210
|
+
"src/legacy/adapter.ts",
|
|
211
|
+
"export function adapt(input: Legacy) {\n"
|
|
212
|
+
" // @ts-ignore // expect\n"
|
|
213
|
+
" return input.payload.items;\n"
|
|
214
|
+
"}\n",
|
|
215
|
+
),
|
|
216
|
+
bad(
|
|
217
|
+
"src/legacy/widget.tsx",
|
|
218
|
+
"// @ts-nocheck // expect\nexport const Widget = () => <div />;\n",
|
|
219
|
+
note="Turns checking off for the whole file.",
|
|
220
|
+
),
|
|
221
|
+
bad(
|
|
222
|
+
"src/legacy/parse.ts",
|
|
223
|
+
"// @ts-expect-error // expect\nexport const value: number = parse('1');\n",
|
|
224
|
+
note="An expect-error directive without a description.",
|
|
225
|
+
),
|
|
226
|
+
good(
|
|
227
|
+
"src/legacy/adapter.ts",
|
|
228
|
+
"export function adapt(input: Legacy) {\n"
|
|
229
|
+
" // @ts-expect-error -- the legacy SDK types omit payload\n"
|
|
230
|
+
" return input.payload.items;\n"
|
|
231
|
+
"}\n",
|
|
232
|
+
),
|
|
233
|
+
good(
|
|
234
|
+
"src/lint.ts",
|
|
235
|
+
"// Do not use @ts-ignore here; see CONTRIBUTING.\n"
|
|
236
|
+
"export const banned = '@ts-ignore';\n",
|
|
237
|
+
note="Prose about the directive and a string.",
|
|
238
|
+
),
|
|
239
|
+
],
|
|
240
|
+
"js/loose-equality": [
|
|
241
|
+
bad(
|
|
242
|
+
"src/cart.js",
|
|
243
|
+
"export function isEmpty(cart) {\n return cart.count == 0; // expect\n}\n",
|
|
244
|
+
),
|
|
245
|
+
bad(
|
|
246
|
+
"src/status.ts",
|
|
247
|
+
"export const changed = (a: string, b: string) => a != b; // expect\n",
|
|
248
|
+
),
|
|
249
|
+
good(
|
|
250
|
+
"src/cart.js",
|
|
251
|
+
"export function hasItems(cart) {\n"
|
|
252
|
+
" if (cart == null) return false;\n"
|
|
253
|
+
" if (typeof cart.count == 'number') return cart.count !== 0;\n"
|
|
254
|
+
" return cart.items.length === 0 ? false : true;\n"
|
|
255
|
+
"}\n",
|
|
256
|
+
note="== null and typeof comparisons are the accepted idioms.",
|
|
257
|
+
),
|
|
258
|
+
good(
|
|
259
|
+
"src/format.js",
|
|
260
|
+
"// a == b is wrong here\n"
|
|
261
|
+
"export const op = '==';\n"
|
|
262
|
+
"export const re = /a==b/;\n"
|
|
263
|
+
"export const ok = (a, b) => a === b || a <= b || a >= b;\n",
|
|
264
|
+
),
|
|
265
|
+
],
|
|
266
|
+
"js/async-foreach": [
|
|
267
|
+
bad(
|
|
268
|
+
"src/jobs/sync.ts",
|
|
269
|
+
"export async function syncAll(users: User[]) {\n"
|
|
270
|
+
" users.forEach(async (user) => { // expect\n"
|
|
271
|
+
" await sync(user);\n"
|
|
272
|
+
" });\n"
|
|
273
|
+
"}\n",
|
|
274
|
+
),
|
|
275
|
+
bad(
|
|
276
|
+
"src/jobs/notify.js",
|
|
277
|
+
"export function notifyAll(users) {\n"
|
|
278
|
+
" users\n"
|
|
279
|
+
" .forEach(async function (user) { // expect\n"
|
|
280
|
+
" await notify(user);\n"
|
|
281
|
+
" });\n"
|
|
282
|
+
"}\n",
|
|
283
|
+
note="A chained call on its own line.",
|
|
284
|
+
),
|
|
285
|
+
good(
|
|
286
|
+
"src/jobs/sync.ts",
|
|
287
|
+
"export async function syncAll(users: User[]) {\n"
|
|
288
|
+
" for (const user of users) {\n"
|
|
289
|
+
" await sync(user);\n"
|
|
290
|
+
" }\n"
|
|
291
|
+
" await Promise.all(users.map(async (user) => notify(user)));\n"
|
|
292
|
+
" users.forEach((user) => log(user));\n"
|
|
293
|
+
"}\n",
|
|
294
|
+
),
|
|
295
|
+
good(
|
|
296
|
+
"src/jobs/docs.js",
|
|
297
|
+
"// Never write users.forEach(async (u) => ...).\n"
|
|
298
|
+
"export const tip = 'use for...of instead of .forEach(async';\n",
|
|
299
|
+
),
|
|
300
|
+
],
|
|
301
|
+
"js/react-index-key": [
|
|
302
|
+
bad(
|
|
303
|
+
"src/components/List.jsx",
|
|
304
|
+
"export function List({ items }) {\n"
|
|
305
|
+
" return (\n"
|
|
306
|
+
" <ul>\n"
|
|
307
|
+
" {items.map((item, index) => (\n"
|
|
308
|
+
" <li key={index}>{item.name}</li> // expect\n"
|
|
309
|
+
" ))}\n"
|
|
310
|
+
" </ul>\n"
|
|
311
|
+
" );\n"
|
|
312
|
+
"}\n",
|
|
313
|
+
),
|
|
314
|
+
bad(
|
|
315
|
+
"src/components/Rows.tsx",
|
|
316
|
+
"export function Rows({ rows }: { rows: Row[] }) {\n"
|
|
317
|
+
" return rows.map((row: Row, i: number) => {\n"
|
|
318
|
+
" const label = row.title;\n"
|
|
319
|
+
" return <RowView key={`row-${i}`} label={label} />; // expect\n"
|
|
320
|
+
" });\n"
|
|
321
|
+
"}\n",
|
|
322
|
+
note="A template key built only from the index, in a block-bodied callback.",
|
|
323
|
+
),
|
|
324
|
+
good(
|
|
325
|
+
"src/components/List.jsx",
|
|
326
|
+
"export function List({ items }) {\n"
|
|
327
|
+
" return (\n"
|
|
328
|
+
" <ul>\n"
|
|
329
|
+
" {items.map((item, index) => (\n"
|
|
330
|
+
" <li key={item.id} data-position={index}>{item.name}</li>\n"
|
|
331
|
+
" ))}\n"
|
|
332
|
+
" </ul>\n"
|
|
333
|
+
" );\n"
|
|
334
|
+
"}\n",
|
|
335
|
+
note="Keyed by a stable ID; the index is used for something else.",
|
|
336
|
+
),
|
|
337
|
+
good(
|
|
338
|
+
"src/components/Grid.tsx",
|
|
339
|
+
"export function Grid({ cells, i }: { cells: Cell[]; i: number }) {\n"
|
|
340
|
+
" return cells.map((cell) => <CellView key={cell.id} row={i} />);\n"
|
|
341
|
+
"}\n",
|
|
342
|
+
note="No index parameter in the callback.",
|
|
343
|
+
),
|
|
344
|
+
],
|
|
345
|
+
"js/async-use-effect": [
|
|
346
|
+
bad(
|
|
347
|
+
"src/components/Profile.tsx",
|
|
348
|
+
"export function Profile({ id }: { id: string }) {\n"
|
|
349
|
+
" useEffect(async () => { // expect\n"
|
|
350
|
+
" setUser(await fetchUser(id));\n"
|
|
351
|
+
" }, [id]);\n"
|
|
352
|
+
" return null;\n"
|
|
353
|
+
"}\n",
|
|
354
|
+
),
|
|
355
|
+
bad(
|
|
356
|
+
"src/components/Feed.jsx",
|
|
357
|
+
"export function Feed() {\n"
|
|
358
|
+
" React.useEffect( // expect\n"
|
|
359
|
+
" async function load() {\n"
|
|
360
|
+
" setItems(await fetchFeed());\n"
|
|
361
|
+
" },\n"
|
|
362
|
+
" [],\n"
|
|
363
|
+
" );\n"
|
|
364
|
+
" return null;\n"
|
|
365
|
+
"}\n",
|
|
366
|
+
note="The callback on the next line.",
|
|
367
|
+
),
|
|
368
|
+
good(
|
|
369
|
+
"src/components/Profile.tsx",
|
|
370
|
+
"export function Profile({ id }: { id: string }) {\n"
|
|
371
|
+
" useEffect(() => {\n"
|
|
372
|
+
" let cancelled = false;\n"
|
|
373
|
+
" (async () => {\n"
|
|
374
|
+
" const user = await fetchUser(id);\n"
|
|
375
|
+
" if (!cancelled) setUser(user);\n"
|
|
376
|
+
" })();\n"
|
|
377
|
+
" return () => {\n"
|
|
378
|
+
" cancelled = true;\n"
|
|
379
|
+
" };\n"
|
|
380
|
+
" }, [id]);\n"
|
|
381
|
+
" return null;\n"
|
|
382
|
+
"}\n",
|
|
383
|
+
),
|
|
384
|
+
good(
|
|
385
|
+
"src/hooks/useData.js",
|
|
386
|
+
"export function useData(load) {\n"
|
|
387
|
+
" useEffect(() => {\n"
|
|
388
|
+
" load().then(setData);\n"
|
|
389
|
+
" }, [load]);\n"
|
|
390
|
+
" return useCallback(async () => setData(await load()), [load]);\n"
|
|
391
|
+
"}\n",
|
|
392
|
+
),
|
|
393
|
+
],
|
|
394
|
+
"js/explicit-any": [
|
|
395
|
+
bad(
|
|
396
|
+
"src/api/client.ts",
|
|
397
|
+
"export async function get(url: string): Promise<any> { // expect\n"
|
|
398
|
+
" const res = await fetch(url);\n"
|
|
399
|
+
" return res.json();\n"
|
|
400
|
+
"}\n",
|
|
401
|
+
),
|
|
402
|
+
bad(
|
|
403
|
+
"src/api/cache.ts",
|
|
404
|
+
"export const cache: Record<string, any> = {}; // expect\n"
|
|
405
|
+
"export const raw = load() as any; // expect\n"
|
|
406
|
+
"export function first(xs: any[]) { // expect\n"
|
|
407
|
+
" return xs[0];\n"
|
|
408
|
+
"}\n",
|
|
409
|
+
),
|
|
410
|
+
good(
|
|
411
|
+
"src/api/client.ts",
|
|
412
|
+
"export async function get<T>(url: string): Promise<T> {\n"
|
|
413
|
+
" const res = await fetch(url);\n"
|
|
414
|
+
" return (await res.json()) as T;\n"
|
|
415
|
+
"}\n"
|
|
416
|
+
"export const hasAny = (xs: unknown[]) => xs.some(Boolean);\n",
|
|
417
|
+
),
|
|
418
|
+
good(
|
|
419
|
+
"src/rules.js",
|
|
420
|
+
"// Accept any value here.\n"
|
|
421
|
+
"export const any = (preds) => (x) => preds.some((p) => p(x));\n"
|
|
422
|
+
"export const label = 'type: any';\n",
|
|
423
|
+
note="JavaScript, a function named any, a comment and a string.",
|
|
424
|
+
),
|
|
425
|
+
good(
|
|
426
|
+
"types/legacy-widget.d.ts",
|
|
427
|
+
"declare module 'legacy-widget' {\n"
|
|
428
|
+
" export function render(el: HTMLElement, options?: any): any;\n"
|
|
429
|
+
"}\n",
|
|
430
|
+
note="A declaration file describing untyped JavaScript.",
|
|
431
|
+
),
|
|
432
|
+
],
|
|
433
|
+
"js/var-declaration": [
|
|
434
|
+
bad(
|
|
435
|
+
"src/legacy/counter.js",
|
|
436
|
+
"var count = 0; // expect\nexport function next() {\n return ++count;\n}\n",
|
|
437
|
+
),
|
|
438
|
+
bad(
|
|
439
|
+
"src/legacy/loop.ts",
|
|
440
|
+
"export function sum(xs: number[]) {\n"
|
|
441
|
+
" for (var i = 0, total = 0; i < xs.length; i++) total += xs[i]; // expect\n"
|
|
442
|
+
" return total;\n"
|
|
443
|
+
"}\n",
|
|
444
|
+
),
|
|
445
|
+
good(
|
|
446
|
+
"src/db.ts",
|
|
447
|
+
"import { PrismaClient } from '@prisma/client';\n"
|
|
448
|
+
"declare global {\n"
|
|
449
|
+
" var prisma: PrismaClient | undefined;\n"
|
|
450
|
+
"}\n"
|
|
451
|
+
"declare var __APP_VERSION__: string;\n"
|
|
452
|
+
"export const db = globalThis.prisma ?? new PrismaClient();\n",
|
|
453
|
+
note="Ambient global declarations need var.",
|
|
454
|
+
),
|
|
455
|
+
good(
|
|
456
|
+
"src/config.js",
|
|
457
|
+
"// var is function-scoped\n"
|
|
458
|
+
"export const variant = 'var x = 1';\n"
|
|
459
|
+
"export const vars = { var: 1 };\n",
|
|
460
|
+
),
|
|
461
|
+
],
|
|
462
|
+
}
|