Git Product home page Git Product logo

rubocop-gradual's Issues

Add `standard` support out of the box

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.

Config loads differently based on something

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.

Odd encoding churn

Running rubocop-gradual is resulting in many iterations of churn between encoded strings and unencoded strings across the entire lockfile. Some pics of one of the recent ones:

First we went one way:
Screenshot 2023-10-23 at 23 06 15
Screenshot 2023-10-23 at 23 06 05
Screenshot 2023-10-23 at 23 05 40
Screenshot 2023-10-23 at 23 05 32

And then later the same day:
Screenshot 2023-10-23 at 23 01 55
Screenshot 2023-10-23 at 23 01 47
Screenshot 2023-10-23 at 23 01 19
Screenshot 2023-10-23 at 23 01 04

Bug: Discrepancy between lint failures in `autocorrect` and `force_update`?

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.

Suggestion: rename the `--update` option to `--force-update`

Following the lengthy brainstorming and discussion in #1, I suggest renaming the --update option, and possibly removing (or changing?) its short name.

Rationale:

  1. Without any options, 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.
  2. Given that first point, the --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)

Suggestion: rename --ci option to a context-neutral name

The --ci option is ambiguous:

  • Continuous integration covers a wide range of practices.
  • It suggests that this command should only be ran on CI servers, but it might be useful to run it on developer workstations as well.
  • It doesn't actually describe what the option does.

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.

Unable to use CLI --list option

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?

Unable to lint a single file?

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?

Crash during rake rubocop_gradual

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... 😆

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.