Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce new RuboCop cops for all Ruby files #566

Merged
merged 56 commits into from
Dec 19, 2023
Merged

Conversation

Splines
Copy link
Member

@Splines Splines commented Nov 25, 2023

Rubocop version information:

rubocop 1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.1.4) [x86_64-linux]

Commands used:

bundle exec rubocop --autocorrect --disable-uncorrectable
bundle exec rubocop --autocorrect-all --disable-uncorrectable # used later

Notable manual changes

  • Use Time.current instead of Time.now. Ref
  • Use update instead of update_all. Ref

Notable manual changes (explicit) / Questions from my side

Current status (2023-12-03 15:30):

  • 30 rubocop:todo Rails/ cops left
  • 1 rubocop:todo Naming/ cop left -> easily fixable
  • 3 rubocop:todo Lint/ cops left
  • 2 rubocop:todo Metrics/ cops left -> probably won't fix in this PR (will stay as todo note)

Some open points or commits to take especially care of (please mark as checked):

  • registrations_controller.rb -> check_registration_limit
  • Disabled line length in multiple occurrences in user_cleaner.rb for long regex statements.
  • Deleted some lines in Devise.setup (see Basecamp)
  • shrine.rb -> added submission_path
  • quizzes_controller.rb -> init_values (quiz_round_params[:save_probe])
  • Duplicate methods in medium.rb´ (one still has to be fixed is_restricted?`)
  • submissions.rb: are the methods at the bottom really supposed to be private class methods?
  • db.rake -> ensure_format
  • Why do we rescue the StandardError in registrations_controller as well as in log_fail? Please provide a comment there
  • Why do we have a has_documents? method in assignments_helper if we have the same method in assignment.rb (over there: renamed to documents?
  • user.rb -> The method has_tutorials was never used (I've made a search for that word), so I deleted it
  • 12 Rails/HasManyOrHasOneDependent todos -> won't fix on my own.
  • I fixed the Rails/InverseOf cops but am not 100% sure that this is the way it should work. I followed the examples from here but have a feeling summarized well by this comment.
  • 12 Rails/UniqueValidationWithoutIndex -> won't fix on my own and probably not in this PR as it may require changing db columns, i.e. add new migrations, right?
  • In course.rb -> question_ids_for_quiz, there is an unused variable. Should we return it?
  • submission.rb -> filename_for_bulk_download
  • Security fixes in this commit

Notable unsafe corrections (incomplete list!)

Note that autocorrects running on old migrations were not committed.

  • video_uploader.rb -> pp changed to Rails.logger.debug
  • ...

Before merging

  • Search for unwanted rubocop:enable that don't have matching rubocop:todo or rubocop:enable block beforehand (rubocop can search for that, it is a cop on its own)
  • bundle exec rubocop -A should not show any warning/error any more (see also CI/CD pipeline)

Todo

Only safe autocorrections used. Command:
bundle exec rubocop --autocorrect --disable-uncorrectable

version: 1.57.2 (using Parser 3.2.2.4,
rubocop-ast 1.30.0, running on ruby 3.1.4) [x86_64-linux]
See the docs: https://docs.rubocop.org/rubocop/usage/auto_correct.html

704 files inspected, 8138 offenses detected, 7399 offenses corrected,
720 more offenses can be corrected with `rubocop -A`.

Note there occurred one error for the file "db/seeds.rb", which will
be fixed manually in subsequent commits.
@Splines Splines self-assigned this Nov 25, 2023
@Splines Splines changed the base branch from main to mampf-next November 25, 2023 17:09
@Splines Splines marked this pull request as ready for review November 28, 2023 15:59
@Splines Splines marked this pull request as draft November 28, 2023 15:59
704 files inspected, 3912 offenses detected, 3912 offenses corrected
704 files inspected, 3171 offenses detected, 2432 offenses corrected,
720 more offenses can be corrected with `rubocop -A`

Command:
bundle exec rubocop --autocorrect --disable-uncorrectable
This is since we only use the instance variable to provide a *default*
value for some params, so the helper methods can still be reused.
The respective comments were added manually, not automatically.
Replaced `update_all` by `update`
and `Time.now` by `Time.current`
This is to avoid Rails/UnknownEnv error
Command used:
bundle exec rubocop --autocorrect-all --disable-uncorrectable

704 files inspected, 911 offenses detected,
909 offenses corrected

2 errors occurred:
An error occurred while Style/StringConcatenation cop was inspecting
mampf/app/models/medium.rb:871:30.
An error occurred while Layout/LineLength cop was inspecting
mampf/db/seeds.rb.

I manually fixed the error in medium.rb.
 I checked the seeds.rb and dit not find any error there.
Command used: bundle exec rubocop --autocorrect --disable-uncorrectable

704 files inspected, 371 offenses detected, 350 offenses corrected,
13 more offenses can be corrected with `rubocop -A`
app/models/course.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@fosterfarrell9 fosterfarrell9 left a comment

Choose a reason for hiding this comment

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

I adressed the points you mentioned, for some I don't know what do myself. I still have to look at all changes in more detail in order to make sure I did not overlook anything. But maybe the current state is okay for a first feedback.

app/models/talk.rb Outdated Show resolved Hide resolved
@Splines Splines merged commit e87caf4 into mampf-next Dec 19, 2023
1 check passed
@Splines Splines deleted the feature/rubocop-all branch December 19, 2023 09:52
@Splines Splines mentioned this pull request Dec 19, 2023
1 task
Splines added a commit that referenced this pull request Jan 6, 2024
* Let RuboCop autocorrect all Ruby files (safe)

Only safe autocorrections used. Command:
bundle exec rubocop --autocorrect --disable-uncorrectable

version: 1.57.2 (using Parser 3.2.2.4,
rubocop-ast 1.30.0, running on ruby 3.1.4) [x86_64-linux]
See the docs: https://docs.rubocop.org/rubocop/usage/auto_correct.html

704 files inspected, 8138 offenses detected, 7399 offenses corrected,
720 more offenses can be corrected with `rubocop -A`.

Note there occurred one error for the file "db/seeds.rb", which will
be fixed manually in subsequent commits.

* Revert "Let RuboCop autocorrect all Ruby files (safe)"

This reverts commit b067b2f.

* Force use of explicit hash literal value (HashSyntax)

* Only correct string literals to double quotes (safe)

704 files inspected, 3912 offenses detected, 3912 offenses corrected

* Allow use of method ".touch"

* Autocorrect all other specified cops (safe)

704 files inspected, 3171 offenses detected, 2432 offenses corrected,
720 more offenses can be corrected with `rubocop -A`

Command:
bundle exec rubocop --autocorrect --disable-uncorrectable

* Fix Layout/IndentationConsistency (manual)

* Fix (or disable) Layout/LineLength

* Fix all Style/ cops

* Fix Lint/ cops (3 still left open)

* Rename `get_votes_count` to `votes_count`

* Fix other Naming/ cops (1 still left open)

* Disable `Rails/HelperInstanceVariable` in `quizzes_helper.rb`

This is since we only use the instance variable to provide a *default*
value for some params, so the helper methods can still be reused.

* Fix all Rails/InverseOf cops

* Disable Rails/ cops in existing db migrations

The respective comments were added manually, not automatically.

* Fix Rails/SkipsModelValidations (1 left open)

Replaced `update_all` by `update`
and `Time.now` by `Time.current`

* Disable Rails/OutputSafety for one line

* Fix Rails/I18n related cops

* Add custom env variable to rubocop

This is to avoid Rails/UnknownEnv error

* Disable Performance/CollectionLiteralInLoop in some tests

* Merge two duplicates groups in Gemfile together

* Automatically autocorrect cops (unsafe)

Command used:
bundle exec rubocop --autocorrect-all --disable-uncorrectable

704 files inspected, 911 offenses detected,
909 offenses corrected

2 errors occurred:
An error occurred while Style/StringConcatenation cop was inspecting
mampf/app/models/medium.rb:871:30.
An error occurred while Layout/LineLength cop was inspecting
mampf/db/seeds.rb.

I manually fixed the error in medium.rb.
 I checked the seeds.rb and dit not find any error there.

* Fix missing `Time.zone.now`

* Add Style/MethodCallWithArgsParentheses and autofix (safe)

Command used: bundle exec rubocop --autocorrect --disable-uncorrectable

704 files inspected, 371 offenses detected, 350 offenses corrected,
13 more offenses can be corrected with `rubocop -A`

* Fix Layout/ cops

* Fix or disable Style/ cops

* Delete weird random character

* Fix Security/ cops

* Fix Performance/ cops

* Fix wrong namespace for a cop

* Manually ignore more db/ cop violations

* Delete empty test files

* Fix line to long

* Temporarily disable Rails/LexicallyScopedActionFilter

* Fix <= logical bug (registration threshold)

* remove duplicated restricted? method

* change private methods to non-private methods

* remove duplicate method

* fix typo

* change inverse_of relation

* fix existing inverse_of associations

* rename duplicate announcements method

* undo premature change

* add namespace to constant

* remove unnecessary logging

* remove non existing action from before filter

* Rewrite new registrations query with timeframe

* Allow touch_all method and replace problematic update calls

See this comment:
#566 (comment)

* Disable Rails/HasManyOrHasOneDependent rule

This is because we think it's cleaner not to have to write
"dependent: nil".

Also removed the respective rubocop:todo comments

* Fix unwanted "," character

* Get rid of weird "foo" check

* remove unused restricted? methods

* Replace problematic touch_all by touch

* Fix wrong manual Style/ correction of 5081aaa

* Fix Rails/OutputSafety

* Remove duplicate dates before save

see #566 (comment)

---------

Co-authored-by: fosterfarrell9 <[email protected]>
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