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

Rubocop fixes and configuration update #19218

Merged
merged 10 commits into from
Nov 1, 2023
Merged

Rubocop fixes and configuration update #19218

merged 10 commits into from
Nov 1, 2023

Conversation

iangmaia
Copy link
Contributor

@iangmaia iangmaia commented Sep 19, 2023

This PR builds on top of #19149 and configures Rubocop in the project, fixing most of the reported offences.

Some of the offences could be a bit riskier to quickly fix and didn't seem very critical, so I generated a .rubocop_todo.yml to silence them for now.

@iangmaia iangmaia added the Do Not Merge In PRs with this label, our automation will fail a require check, preventing accidental merging label Sep 19, 2023
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 19, 2023

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr19218-cc10f9d
Commitcc10f9d
Direct Downloadjetpack-prototype-build-pr19218-cc10f9d.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 19, 2023

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr19218-cc10f9d
Commitcc10f9d
Direct Downloadwordpress-prototype-build-pr19218-cc10f9d.apk
Note: Google Login is not supported on these builds.

@iangmaia iangmaia changed the title Configure Rubocop Rubocop fixes and configuration improvements Sep 20, 2023
@iangmaia iangmaia changed the title Rubocop fixes and configuration improvements Rubocop fixes and configuration update Sep 21, 2023
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Oct 5, 2023

Warnings
⚠️ PR is not assigned to a milestone.
⚠️ PR has more than 300 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@iangmaia iangmaia force-pushed the fix/rubocop branch 2 times, most recently from a10a127 to 946ab0b Compare October 23, 2023 16:45
@iangmaia iangmaia force-pushed the fix/rubocop branch 2 times, most recently from 1675bc3 to 2ba7613 Compare October 25, 2023 17:38
@iangmaia iangmaia mentioned this pull request Oct 26, 2023
@iangmaia iangmaia added Tooling and removed Do Not Merge In PRs with this label, our automation will fail a require check, preventing accidental merging labels Oct 26, 2023
@iangmaia iangmaia marked this pull request as ready for review October 26, 2023 17:42
@iangmaia iangmaia requested review from mokagio and removed request for mokagio October 30, 2023 10:06
Copy link
Contributor

@mokagio mokagio left a comment

Choose a reason for hiding this comment

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

Thank you for tackling RuboCop @iangmaia !

Before moving forward with this, I suggest syncing with @spencertransier . He's been working on removing outdated settings, like GHHELPER_REPO, from other projects. I wouldn't be surprised if this one was next in the list. It'd be a shame if you worked in parallel and generated merge conflicts

### Gems needed only for generating Promo Screenshots
group :screenshots, optional: true do
gem 'rmagick', '~> 4.1'
gem 'rmagick', '~> 4.1'
end
Copy link
Contributor

Choose a reason for hiding this comment

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

@iangmaia 😄 🤖 win!

image

@@ -160,7 +162,7 @@ import 'lanes/release_management_in_ci.rb'

default_platform(:android)

before_all do |lane|
before_all do |_lane|
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe RuboCop prefixed this with _ because it's unused. But if that's the case, we might as well remove it, no?

Suggested change
before_all do |_lane|
before_all do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was auto-fixed by RuboCop.
In principle I agree, but at the same time, the signature does help to document that this is a special Fastlane thing 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

My two cents are that it's up to us devs to look into the documentation to discover what optional parameters the method we use have. I prefer the code to be leaner, every unused parameter begs the question "why is this here?"

But, not something I feel so strongly about to delay this PR for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, the _ RuboCop requests brings in a bit more obscurity to the fact parameter is there. Decided to go with your suggestion: cc10f9d

@@ -48,8 +50,8 @@ fastlane_require 'dotenv'
USER_ENV_FILE_PATH = File.join(Dir.home, '.wpandroid-env.default')
Dotenv.load(USER_ENV_FILE_PATH)

ENV[GHHELPER_REPO = 'wordpress-mobile/WordPress-Android']
ENV['PROJECT_ROOT_FOLDER'] = File.dirname(File.expand_path(__dir__)) + '/'
ENV.fetch(GHHELPER_REPO = 'wordpress-mobile/WordPress-Android', nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this change.

I think what the code did (or tried to do) before was setting the GHHELPER_REPO value in the environment. Now it's only reading it, I think. 🤔

By the way, do we even need it in the environment? I thought we removed it a while back. See wordpress-mobile/WordPress-iOS#20072

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This went away with the latest rebase, so I believe @spencertransier already worked on some refactoring here.

It seems that the old code and the RuboCop updated code weren't doing much 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe @spencertransier already worked on some refactoring here.

I thought that, too, but couldn't find the PR. I've seen many of those recently because Spencer has been busy across all our apps and assumed I just got confused.

unless options[:skip_confirm]
UI.user_error!('Aborted by user request') unless UI.confirm('Do you want to continue?')
end
UI.user_error!('Aborted by user request') if !options[:skip_confirm] && !UI.confirm('Do you want to continue?')
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of using positive logic here and in the other instances?

Suggested change
UI.user_error!('Aborted by user request') if !options[:skip_confirm] && !UI.confirm('Do you want to continue?')
UI.user_error!('Aborted by user request') unless options[:skip_confirm] || UI.confirm('Do you want to continue?')

Copy link
Contributor Author

@iangmaia iangmaia Oct 31, 2023

Choose a reason for hiding this comment

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

Ah, nice one. RuboCop changed it to avoid nesting, I believe, but the unless with a positive condition is more readable. Updated here: 407518f

Base automatically changed from add/dangermattic-setup to trunk October 31, 2023 10:24
@iangmaia
Copy link
Contributor Author

Thank you for tackling RuboCop @iangmaia !

Before moving forward with this, I suggest syncing with @spencertransier . He's been working on removing outdated settings, like GHHELPER_REPO, from other projects. I wouldn't be surprised if this one was next in the list. It'd be a shame if you worked in parallel and generated merge conflicts

Good point -- in fact, I already had quite some conflicts on several (including this one) of the open PRs in the apps, for both Dangermattic and RuboCop config. Hopefully we'll merge the PRs soon and it will be easier when all branches are aligned on RuboCop and Ruby 3 setup.

Copy link
Contributor

@mokagio mokagio left a comment

Choose a reason for hiding this comment

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

Approved with non blocking syntax sugar suggestions

@@ -160,7 +162,7 @@ import 'lanes/release_management_in_ci.rb'

default_platform(:android)

before_all do |lane|
before_all do |_lane|
Copy link
Contributor

Choose a reason for hiding this comment

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

My two cents are that it's up to us devs to look into the documentation to discover what optional parameters the method we use have. I prefer the code to be leaner, every unused parameter begs the question "why is this here?"

But, not something I feel so strongly about to delay this PR for it.

@@ -158,7 +154,7 @@
rescue FastlaneCore::Interface::FastlaneError => e
# Sometimes the upload fails randomly with a "Google Api Error: Invalid request - This Edit has been deleted.".
# It seems one reason might be a race condition when we do multiple edits at the exact same time (WP beta, JP beta). Retrying usually fixes it
if e.message.start_with?('Google Api Error') && (retry_count -= 1) > 0
if e.message.start_with?('Google Api Error') && (retry_count -= 1).positive?
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL. Nice!

end rescue puts "Cannot delete file #{file}"
File.delete(file) if Integer(File.basename(file, '.*')) < Integer(options[:build])
rescue StandardError
puts "Cannot delete file #{file}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope, but what do you think of relying on Fastlane's UI management?

Suggested change
puts "Cannot delete file #{file}"
UI. error("Could not delete file #{file}.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Done here: cc10f9d

fastlane/lanes/release_management_in_ci.rb Outdated Show resolved Hide resolved
iangmaia and others added 2 commits November 1, 2023 15:44
`editorial_branch` should already be a `String`

Co-authored-by: Gio Lodi <gio.lodi@automattic.com>
@wpmobilebot
Copy link
Contributor

3 Warnings
⚠️ Gemfile was changed without updating its corresponding Gemfile.lock. Please run bundle install or bundle update <updated_gem>.
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@iangmaia iangmaia merged commit b26a9a4 into trunk Nov 1, 2023
20 checks passed
@iangmaia iangmaia deleted the fix/rubocop branch November 1, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants