Skip to content

Add Token.isLiteralIdentifier - #2662

Merged
calda merged 1 commit into
nicklockwood:developfrom
jparise:literal-identifier-helper
Aug 20, 2026
Merged

Add Token.isLiteralIdentifier#2662
calda merged 1 commit into
nicklockwood:developfrom
jparise:literal-identifier-helper

Conversation

@jparise

@jparise jparise commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Small readability change: names the fact that true, false, and nil are tokenized as identifiers rather than keywords, so rules don't each have to remember it.

Reasoning

Any rule that treats an identifier as a name referring to something has to exclude these three, and that check was written out by hand in a handful of places — including inside ParsingHelpers itself:

if prevToken.isIdentifier, !["true", "false", "nil"].contains(prevToken.string) {

This is easy to miss, which is the motivation: while writing preferLazyMap I did miss it, and the rule initially rejected any closure body containing a boolean literal. Putting the predicate next to isNumber and the other token checks makes it discoverable instead of rediscovered.

Adopted at the two sites where it's a drop-in replacement. The other sites match these literals as switch patterns (case .identifier("true"), .identifier("false"), ...), where spelling them out reads at least as clearly as a where clause would, so I left them alone. redundantType keeps its own true/false-only check on purpose — nil has no inferable type and shouldn't be folded in.

Full test suite passes.

The tokenizer represents `true`, `false`, and `nil` as identifiers rather than
keywords, so any rule that treats an identifier as a name referring to something
has to remember to exclude them. That check was spelled out by hand in several
places, including inside ParsingHelpers itself.

Names the fact once, next to `isNumber` and the other token predicates, so it is
discoverable rather than rediscovered — the `preferLazyMap` rule initially missed
it and rejected every closure body containing a boolean literal.

Adopted at the two sites where it is a drop-in. The remaining sites match these
literals as `switch` patterns (`case .identifier("true"), ...`), where spelling
them out reads at least as clearly as a `where` clause would, so they are left
alone. `redundantType` deliberately keeps its own `true`/`false`-only check,
since `nil` has no inferable type and must not be folded in.

@calda calda left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.46%. Comparing base (adad8ac) to head (bd95b2b).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2662      +/-   ##
===========================================
- Coverage    95.47%   95.46%   -0.01%     
===========================================
  Files          178      178              
  Lines        27186    27189       +3     
===========================================
+ Hits         25955    25956       +1     
- Misses        1231     1233       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@calda
calda merged commit ccd7977 into nicklockwood:develop Aug 20, 2026
15 of 16 checks passed
@jparise
jparise deleted the literal-identifier-helper branch August 20, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants