feat(lint): find a closure that only passes its parameters on #173
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/9-lint-redundant-closure"
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?
Closes #9
What
The lint rule
redundant-closure: a closure whose body is one call of a declared function with the closure's own parameters, each once and in order ({ f(_) },{ f(_, _2) },{ x => f(x) },{ f _ }), is reported and its fix passes the function by its name:items.map { stripMargin(_) }becomesitems.map(stripMargin). A closure that trails the call moves into the argument list, with its parameter's label where a labeled argument comes before it or its position would fill another parameter.Why it is certain
The rule reads the checker's tables, as
labeled-literaldoes: the resolution of the inner call (aDirectcall of aSymbolKind.Functionwith a ready, non-generic signature that has a body and does not takeself), the adaptations at the inner call, at its arguments and at the closure (onlyImplicitParameter(i)in order, andTrailingClosure), its type arguments, and the function type the closure was given (sameTypefor every parameter and the result, modes only by value orvaron both sides, no default). No new checker table was needed; the existingresolutions,adaptations,typeArguments,argumentTargetsandexpressionTypesanswer every question. No seed impact.A closure that adapts the function (default left out,
lazy, variadic, conversion or wrap of an argument or the result, generic ornativecallee, a method, a binding or field that holds a closure) gets no finding at all: the rule has no setting and no suppression, so it reports only what it can fix.The case-shorthand rule split out to #168 is untouched; torb-lint.md still names it under "What is not decided".
Changes
compiler/src/lint/redundant-closure.trb: the rule; wired intofinding.trb,command.trband the language server (view.trb).TargetandparametersOfoflabeled-literal.trbbecame public for the label of a moved trailing closure.compiler/tests/lint.test.trb: groupredundant-closure- every position (trailing, parenthesized, labeled, command, no parentheses), a local and a static function, a generic outer function, labels for a moved trailing closure, and the cases that are kept (a default,lazy, an adaptation, a generic callee, a stored closure, arguments out of order, used twice, labeled or not the parameters); every fixed text type checks.torb lint --fix --rule redundant-closure std compiler/srcthentorb format(22 closures in 11 files). Afterwards the rule finds nothing in std and compiler/src.docs/tooling/torb-lint.md(synopsis, rule section with atrb checkexample, the not-built list),the-torb-command.md,verifying-your-work.md,ROADMAP.md,compiler/CONTRIBUTING.md; skills regenerated.Test
Locally (quick checks only):
torb check compiler stdclean,torb format --checkon every touched file,torb docs skill docs skills --check, andtorb test compiler/tests/lint.test.trb --filter redundant-closure(5 passed). Gates run in CI.43f19e2af94f2d56480f4f2d56480f59512e08c159512e08c10b21250801Approved. Checklist for head
0b21250:redundant-closurecovers every position, local/static functions, labels for a moved trailing closure, and the kept cases (default,lazy, generic, wrapped result, stored closure, order, reuse, labels); every fixed text is re-checked. CI green (combined status success).Non-blocking: none.