Fewer false positives: JSON.stringify, Number(), || defaults decided by declared types; no-redos, bounded-concurrency, URL and RegExp #67
Loading…
Reference in a new issue
No description provided.
Delete branch "evobug/fb3-false-positives"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Feedback round 3, area false positives (the "Rules" section; #4 of the top ten).
What changed, per item
JSON.stringifyof plain data — done. Newshape.rsrecords, from syntax, what a value is: a binding's declared type, a member of another value, what it was destructured from, the item a callback orfor…ofgets, a built-in method's result (slice,map.get,map.size,Object.fromEntries,Object.entries),Object.freeze(...), a function's or method's declared return type, and values aftertypeof x === "string"orif (isErr(r)) return. The whole-program pass evaluates it with the validator generator's type model (json_value.rs): aliases, interfaces, imports and re-exports,Record, mapped and conditional types,Option, andT["key"]looked up without resolving the rest ofT. Every case in the entry passes now, including the destructuring cases that disagreed (now consistent, by type).bigint,unknown,JsonValue("can hold a cycle"), a type that refers to itself, atoJSONfield.this.xuses its declared type (it runs beforeJSON.stringifydoes).const xs = [](TypeScript lets its type grow with whatever is pushed).page.evaluate(...)-style inferred types. SAFE-TS has no type inference for return values without a declared type.number-parse-nan— done.Number(...)of booleans (!!x, comparisons,in, a field declaredboolean, also in another file's type), of numbers, and of capture groups of a matched regex that are only digits ((\d+),[0-9]{2},-?\d+; top-level groups only, fromexec, non-gmatch,matchAll).parseInt(true)isNaN, so booleans are exempt forNumberonly; this fixes an old exemption that coveredparseInttoo.prefer-nullish-default— done, by declared return type. Decision:f(x) || 1withfdeclared(…): numberis not reported. Anumbercan't beundefined, so??would never apply and the quick fix would silently drop the default. Replacing0is the point here, which is the rule's existing exemption forMath.hypot(...) || 1. This is the opposite of the brief's first reading; the feedback entry (0 means "no run") supports it. DeclaredOption<number>, it is still reported. Works across files.no-redos— done. Negated classes are real sets now, no longer "any character".(?:[^<>"]|"[^"]*")*and the attribute tag regex pass; the tag regex is polynomial at worst, and only exponential cases are reported. Existing fixtures plus([^a]+)+b,(?:[^x]|y)+$stay reported.bounded-concurrency— done.Object.entries/keys/valuesof anObject.freeze({…})or{…} as consttable without spreads (or of an inline literal) has a fixed length, so it isn't reported. ARecord<string, …>table still is.new URL/fileURLToPath— done.new URL("src", import.meta.url)(any path-like literal orconst: no scheme, no//host, no whitespace or\) is accepted. So arefileURLToPath(new URL(<such a path>, import.meta.url))andfileURLToPath(import.meta.url). Encoded%2F/%5Care refused, sincefileURLToPaththrows on them. The docs giveimport.meta.dirname/import.meta.filenameas the alternative for helpers that take a parameter.new RegExpinconsistency — explained and fixed. Cause: inside a test callback nothing is reported (the runner catches the throw), so the "similar template in reproduction.test.ts" was quiet. In a helper, any template was reported, even number-only ones. Now a template made of escaped text (escapeRegExp), constant text and numbers (also numbers typed in other files) is accepted. Each pattern is parsed with worst-case stand-ins, so`x{${n}}`withuis still reported. Unescaped text is reported with the reason.RTSS (
evobug/adopt-safe-ts-architecture), before → afterunsafe(() => JSON.stringify(…)): 37 sites. With the wrapper removed, all 37 were reported before. After: 24. So 13 wrappers become unnecessary. Of the 24: 16unknown, 1JsonValue, 2 replacers (all with the reason in the message), and 5 untyped values (data: object,path.join(…)results, callback results, a spread of loop items). Items named in the feedback that are fixed:Object.fromEntriesof an aliasedMap(control-groups, vite-plugins), the cheat action spread,this.options…member reads in fake-server,DeepPartial<ServerConfig>overrides (draft.ts),Recordaliases.fileURLToPath(new URL(…, import.meta.url)): the 3 helpers (here×2,besideThis) take a parameter and still needunsafe. Their 7 call sites written inline (fileURLToPath(new URL('src', import.meta.url))): before, each was reported; after, 0 are.new RegExp: the one non-test site (assetTag) interpolates unescaped parameters and is still reported, rightly. Test-body ones were never reported.bounded-concurrency(SAMPLE_URLS, anObject.freezetable),no-redos(R3 regexes),number-parse-nan(Number(!!a.job),Number(a > 0),Number(b.shows),Number(m[1])): the RTSS code was already rewritten. The same shapes in the newtyped_valuesfixture are reported before and pass after.typed_values: 59 reports with main's checker → 18 now. Each of the 18 is expected.Docs changed
docs/rules/unhandled-failure.md(JSON.stringifyby type, why it is still reported,new RegExptemplates, module URLs,fileURLToPath,import.meta.dirname),docs/rules/number-parse-nan.md,docs/rules/prefer-nullish-default.md,docs/rules/no-redos.md,docs/rules/bounded-concurrency.md,docs/guide/libraries.md(built-ins that can't fail),docs/guide/json.md(jsonNullwithJSON.stringify),CHANGELOG.md(Unreleased → Fixed).Verification
All pass:
npm run build,cargo nextest run --workspace(212/212, including docs examples and the newtyped_valuesfixture),cargo clippy -q --workspace --all-targets(no warnings),npm run test:std(285),npm run typecheck,npm run typecheck:emit,node scripts/docs-typecheck.mjsandnpm run test:docs(386 examples),npm run test:vite,npm run bench:check,node scripts/verify-packages.mjs. New unit tests inredos.rs(negated classes, digit groups).🤖 Generated with Claude Code