Skip to content

Commit

Permalink
[Fix #6274] Don't cache corrected status
Browse files Browse the repository at this point in the history
Caching auto-correct runs was introduced in #5857. This PR fixes an
issue when someone runs auto-correct on a file, but later reverts the
corrected offenses.
Auto-correct run caches the offenses with status :corrected, and now if
someone inspects the reverted file again, the offenses are pulled from
the cache with the wrong status. Because of this the offenses get now
printed with `[Corrected]`, even though auto-correct was not used.
  • Loading branch information
Laura Paakkinen authored and bbatsov committed Oct 8, 2018
1 parent da8c541 commit d48304e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [#6334](https://github.com/rubocop-hq/rubocop/pull/6334): Fix a false negative for `Style/RedundantFreeze` when assigning a range object to a constant. ([@koic][])
* [#5538](https://github.com/rubocop-hq/rubocop/issues/5538): Fix false negatives in modifier cops when line length cop is disabled. ([@drenmi][])
* [#6340](https://github.com/rubocop-hq/rubocop/pull/6340): Fix an error for `Rails/ReversibleMigration` when block argument is empty. ([@koic][])
* [#6274](https://github.com/rubocop-hq/rubocop/issues/6274): Fix "[Corrected]" message being displayed even when nothing has been corrected. ([@jekuta][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cached_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def serialize_offense(offense)
},
message: message(offense),
cop_name: offense.cop_name,
status: offense.status
status: :uncorrected
}
end

Expand Down
23 changes: 23 additions & 0 deletions spec/rubocop/result_cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ def abs(path)
end
end

# Fixes https://github.com/rubocop-hq/rubocop/issues/6274
context 'when offenses are saved by autocorrect run' do
let(:corrected_offense) do
RuboCop::Cop::Offense.new(
:warning, location, 'unused var', 'Lint/UselessAssignment', :corrected
)
end
let(:uncorrected_offense) do
RuboCop::Cop::Offense.new(
corrected_offense.severity.name,
corrected_offense.location,
corrected_offense.message,
corrected_offense.cop_name,
:uncorrected
)
end

it 'serializes them with :uncorrected status' do
cache.save([corrected_offense])
expect(cache.load).to match_array([uncorrected_offense])
end
end

context 'when no option is given' do
let(:options2) { {} }

Expand Down

0 comments on commit d48304e

Please sign in to comment.