feat(no-thenable): add no-thenable rule - #1531
Conversation
|
Verdict: needs changes — the computed-key resolution is scope-blind and can false-positive. Otherwise a thorough, correct port. Not merging (new rule + this issue). The literal/string/template/ Correctness — scope-blindness (false positive) const then = "then"; // collected: "then" -> range
function f(then: string) { // parameter shadows the outer const
return { [then]: 1 }; // `then` here is the PARAM (unknown), but is flagged
}oxc avoids this because it resolves the computed-key identifier to its declaration via the semantic model. Here the name-based map conflates distinct bindings. Fix: key Secondary (same root cause): Otherwise correct
Perf: an initial full-AST Housekeeping: Blocker: switch the computed-key map from name-keyed to |
Ports the oxlint
unicorn/no-thenablerule to deno_lint as a native Rustrule. It flags declaring an object or class member named
then, which makesthe value accidentally "thenable" and can break when the value is used in an
awaitexpression.The rule detects the following cases:
thenproperty — shorthand, key/value, method,getter, or setter, whether the key is the identifier
then, the string"then", a`then`template, or a computed key that is an identifierresolving to a
const/let/varinitialized to"then".thenmember — method, property, getter, setter, and theirstaticvariants (private#thenmembers are intentionally not flagged).Object.defineProperty(foo, "then", ...)andReflect.defineProperty(foo, "then", ...).Object.fromEntries([["then", ...]]).thenmember, e.g.foo.then = 1,foo["then"] += 1.then, both via declarations (export const then = 1,export function then() {},export class then {}, and destructuringpatterns) and via specifiers (
export { then },export { x as then }).The diagnostic message and help text, as well as the complete pass/fail
fixture arrays, are ported from the oxc reference:
https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/unicorn/no_thenable.rs
Tagged RECOMMENDED (on by default) — flagging for maintainer sign-off.