-
Notifications
You must be signed in to change notification settings - Fork 11
New rule: simplify-named-let-initialization #745
Copy link
Copy link
Open
Labels
autopilot-candidateThe Copilot Agent should attempt this during a scheduled Autopilot runThe Copilot Agent should attempt this during a scheduled Autopilot runnew lintIssues suggesting new lints or pull requests implementing new lintsIssues suggesting new lints or pull requests implementing new lints
Metadata
Metadata
Assignees
Labels
autopilot-candidateThe Copilot Agent should attempt this during a scheduled Autopilot runThe Copilot Agent should attempt this during a scheduled Autopilot runnew lintIssues suggesting new lints or pull requests implementing new lintsIssues suggesting new lints or pull requests implementing new lints
Rule summary
Old scheme code that doesn't use internal definitions sometimes uses complex named
letloops with very large expressions used as the initial values for the namedlet's arguments. Since all of a namedlet's initial arguments are evaluated before anything in the namedletis, it's more readable to extract complex initial value expressions into definitions preceding the namedlet.This should only be done for named
letargument initialization expressions that take up multiple lines, and it's only safe when the other initialization expressions are pure. It's also only possible in a definition context. The variable name chosen for the initial value should be the corresponding namedletargument variable name prefixed withinit-.This rule should not be included alongside the
let-replacementrules, since it isn't actually replacing aletbinding with adefine: it's introducing a newdefinebinding to make an existingletbinding easier to read.Test case
No-change test case
Additional context
Saw this in racket/scribble#535, specifically this commit.