skryukov / rubocop-gradual Goto Github PK
View Code? Open in Web Editor NEWGradually improve your code with RuboCop
License: MIT License
Gradually improve your code with RuboCop
License: MIT License
I'm thinking of including exe/standard-gradual
into the gem to support standard
proxying.
Probably this will lead to rewriting of the glue code, that connects rubocop and rubocop-gradual.
Or... maybe it is doing something extra at the end of the task, but only sometimes?
Using the rubocop
shim hack (with autocorrect):
❯ bundle exec rubocop -a
Inspecting 109 file(s) for autocorrection...
.............................................................................................................
Fixed 0 file(s).
...........................................................................................................................................................................................................................................................
Found 142 files with 6203 issue(s).
Processing results...
RuboCop Gradual got 1 issue(s) fixed, 6203 left. Keep going!
bundle exec rubocop -a 48.45s user 6.64s system 200% cpu 27.541 total
Using the rake check task locally the process appears to run as expected:
❯ bundle exec rake rubocop_gradual:check
Running RuboCop Gradual...
...........................................................................................................................................................................................................................................................
Found 142 files with 6203 issue(s).
Processing results...
RuboCop Gradual got no changes.
bundle exec rake rubocop_gradual:check 45.73s user 6.49s system 172% cpu 30.274 total
However, in CI we get a different results from the same rake check task, running against the same code, same git SHA:
+ bundle exec rake rubocop_gradual:check
Program Name: /opt/atlassian/pipelines/agent/build/vendor/bundle/ruby/2.7.0/bin/rake
Not using any observers because program name isn't rails, passenger, or rspec
Running RuboCop Gradual...
...........................................................................................................................................................................................................................................................
Found 142 files with 6203 issue(s).
Processing results...
RuboCop Gradual got 1 issue(s) fixed, 6203 left. Keep going!
RuboCop Gradual failed!
Unexpected Changes!
RuboCop Gradual lock file is outdated, to fix this message:
- Run `rubocop-gradual` locally and commit the results, or
- EVEN BETTER: before doing the above, try to fix the remaining issues in those files!
`.rubocop_gradual.lock` diff:
+ "config/environments/development.rb:4085136686": [
+ [13, 5, 42, "Rails/Blank: Use `ENV[\"TOPICS\"].blank?` instead of `ENV[\"TOPICS\"].nil? || ENV[\"TOPICS\"].empty?`.", 75732059]
+ ],
I'm at a loss for how this is possible.
I have a large config, with many RuboCop plugins (see rubocop-lts
meta gem), and when I run with NO_GRADUAL=1
different cops run that when I run rubocop-gradual
normally. I'm not sure of much else yet, but I will update here as I figure things out.
My CI failed with a RuboCop violation. So locally I ran:
❯ bundle exec rake rubocop_gradual:autocorrect
Running RuboCop Gradual...
Inspecting 181 file(s) for autocorrection...
.....................................................................................................................................................................................
Fixed 0 file(s).
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................
Found 258 files with 5513 issue(s).
Processing results...
RuboCop Gradual got no changes.
noglob bundle exec rake rubocop_gradual:autocorrect 53.01s user 8.48s system 228% cpu 26.863 total
This is a surprising and invalid result, since I saw the result of running rubocop on CI (which runs check
).
Instead of saying it "got no changes" it should have reported the new failures we are about to see below...
So I ran force_update
:
❯ bundle exec rake rubocop_gradual:force_update
Running RuboCop Gradual...
.......................................................................................................................................................................................................................................................................................................................................................................................................................................................
Found 258 files with 5515 issue(s).
Processing results...
Uh oh, RuboCop Gradual got worse:
-> spec/channels/modified_relays_channel_spec.rb (1 new issues)
(line 7) "Betterment/UnscopedFind: Records are being retrieved directly using user input.
Please query for the associated record in a way that enforces authorization (e.g. "trust-root chaining").
INSTEAD OF THIS:
Post.find(params[:post_id])
DO THIS:
current_user.posts.find(params[:post_id])
See here for more information on this error:
https://github.com/Betterment/betterlint/blob/main/README.md#bettermentunscopedfind
(https://github.com/Betterment/betterlint#bettermentunscopedfind)"
-> spec/channels/sensor_streams_channel_spec.rb (1 new issues)
(line 7) "Betterment/UnscopedFind: Records are being retrieved directly using user input.
Please query for the associated record in a way that enforces authorization (e.g. "trust-root chaining").
INSTEAD OF THIS:
Post.find(params[:post_id])
DO THIS:
current_user.posts.find(params[:post_id])
See here for more information on this error:
https://github.com/Betterment/betterlint/blob/main/README.md#bettermentunscopedfind
(https://github.com/Betterment/betterlint#bettermentunscopedfind)"
Force updating lock file...
noglob bundle exec rake rubocop_gradual:force_update 20.56s user 4.62s system 226% cpu 11.099 total
The force_update
caught the change somehow, when the autocorrect
did not.
Following the lengthy brainstorming and discussion in #1, I suggest renaming the --update
option, and possibly removing (or changing?) its short name.
Rationale:
rubocop-gradual
already updates the lock file in the normal development workflow. The README even suggests using that command without options in git hooks to update the lock file. So having a separate --update
command that does something else is confusing.--update
command should be named in a way that conveys its specificity (e.g. what type of update it does or when it does it).I suggest using --force-update
, because it disregards the "error" case of introducing new issues in the lock file.
It might also be useful to delete the -u
short option (if you don't want to incentivize using it too much), or maybe change it to something else? Possible values for a short command:
-f
(of rm -f
fame)-U
with an upercase U only (uppercase is sometimes used to convey that you're asking for the "more powerful" version of a command)-uu
(used by ripgrep for instance)-fu
(which reads like… hmm maybe that joke is too colorful)The --ci
option is ambiguous:
If the functionality is "check code against the lock file and error out if there is any new linting output", maybe a name like --check
might be a better fit?
Edit: other brainstormed names: --test
, --strict
.
I am using the rubocop-gradual shim, so it runs instead of the standard rubocop command normally.
When I run:
NO_GRADUAL=1 bundle exec rubocop -a --list
it only prints the list of files that would be processed.
If I instead run:
bundle exec rubocop -a --list
It runs rubocop gradual ignoring the --list
option entirely.
Is this intentional?
I'm using the shim, so rubocop_gradual runs instead of rubocop normally.
When I run:
bundle exec rubocop -a Gemfile
the entire project is scanned as if I had not specified a file.
When I run:
NO_GRADUAL=1 bundle exec rubocop -a Gemfile
It lints the Gemfile only.
Is this a known limitation of rubocop-gradual?
Is it intentional?
Firstly, I need to say: I love this gem - the idea is brilliant, and I'd love to help however I can!
I hacked the gem source to see what was going on:
59: str.each_byte.inject(5381) do |hash, b|
60: ((hash << 5) + hash) ^ b
61: end & 0xFFFFFFFF
62: rescue NoMethodError => error
63: byebug
64: end
Before hitting my byebug
, I got this output:
❯ bundle exec rake rubocop_gradual
Running RuboCop Gradual...
................................
Found 13 files with 233 issue(s).
Processing results...
Return value is: nil
I am not familiar with that last line, having run rubocop_gradual many times now.
Here's some introspection after hitting my byebug
:
(byebug) str
nil
(byebug) error.class
NoMethodError
(byebug) error.message
"undefined method `each_byte' for nil:NilClass"
(byebug) puts error.backtrace
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:59:in `djb2a'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:38:in `issue_hash'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `block in prepare_issues'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `map'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:32:in `prepare_issues'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results/file.rb:15:in `initialize'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results.rb:14:in `new'
/Users/pboling/.asdf/installs/ruby/2.7.8/lib/ruby/gems/2.7.0/gems/rubocop-gradual-0.3.1/lib/rubocop/gradual/results.rb:14:in `block in initialize'
I am not sure which file it is dying on... because str
is nil
... 😆
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.