Skip to content

Don't flag a local variable named fixture_path - #26

Merged
aslam merged 1 commit into
aslam:mainfrom
cheesepaulo:fixture-path-local-variable
Oct 14, 2026
Merged

aslam merged 1 commit into
aslam:mainfrom
cheesepaulo:fixture-path-local-variable

Conversation

@cheesepaulo

Copy link
Copy Markdown
Contributor

Ran 0.1.2 against a private app going from Rails 7.1 to 7.2. fixture_path_assignment matched 7 lines in its spec helpers, all a local variable:

fixture_path = build_fixture_path(route, mock_data_file)

Ruby reads a bare name = x as a local variable, never a call to the setter, so the removed fixture_path= always has a receiver. The pattern goes from \bfixture_path\s*= to \.fixture_path\s*=(?!=):

Line Before After
self.fixture_path = x hit hit
config.fixture_path = "spec/fixtures" hit hit
ActiveSupport::TestCase.fixture_path = x hit hit
fixture_path = build(route) hit —
@fixture_path = x hit —
self.fixture_path == x hit —
config.fixture_paths = [x] — —

Two lines go into NEAR_MISSES (the local and the instance variable). With the old pattern, test_replacement_apis_are_not_flagged fails on both; with the new one the suite passes (97 runs, 0 failures). On the app, the 7 hits go to 0 and nothing else in the report changes (blockers 3 → 2).

🤖 Generated with Claude Code

Ruby reads a bare `fixture_path = x` as a local variable assignment, never
as a call to the removed setter, so the rule now needs a receiver
(`self.`, `config.`, `ActiveSupport::TestCase.`). It also stops matching
an instance variable (`@fixture_path = x`) and a comparison (`==`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslam

aslam commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Thanks, this is right. A bare fixture_path = x can only ever be a local variable, so making the pattern require a receiver drops the false positives and loses no real hits. I ran the suite on this branch and it passes.

One small optional change: obj.fixture_path => 1 and obj.fixture_path =~ /a/ still match. Changing the lookahead to (?![=~>]) excludes both:

pattern: "\\.fixture_path\\s*=(?![=~>])"

Neither is likely in real code, though.

@aslam
aslam merged commit 6597222 into aslam:main Oct 14, 2026
7 checks passed
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