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

[#8827] Change Style/FormatStringToken style to template #10723

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pirj
Copy link
Member

@pirj pirj commented Jun 18, 2022

fixes #8827

template seems to be by far the most accepted style, at least in the real-world-rspec repositories.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch from 63151e3 to 02a7856 Compare June 18, 2022 01:18
@pirj pirj changed the title [#8227] Change Style/FormatStringToken style to template [#8827] Change Style/FormatStringToken style to template Jun 18, 2022
@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch 2 times, most recently from 0c1c281 to 9bb0f07 Compare June 18, 2022 01:33
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 18, 2022

While I don't mind changing this for RuboCop itself (unless someone from @rubocop/rubocop-core objects), that's a breaking configuration change we can't do before 2.0.

@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch from 9bb0f07 to 765bca1 Compare June 18, 2022 19:15
@pirj
Copy link
Member Author

pirj commented Jun 18, 2022

that's a breaking configuration change we can't do before 2.0

Fair enough.
I don't even think that even the introduction of EnableNewCopsUpTo would allow making enforced style changes between major versions.

The only way to push such changes through quicker is to release major versions more often. And this is precisely what I'm trying to do by squashing the remaining tickets for the 2.0 milestone.

My primary concern is that it's been more than 1.5 years since RuboCop 1.0 release. Presently, there are 60 cops in Enabled: pending status, and except for those with the NewCops: enable "brave early adopter" setting, this would put a major burden during upgrade to RuboCop 2.0.

If my understanding that it's better to release 2.0 soon is correct, I intend to continue with the few remaining 2.0 issues.

@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch from 765bca1 to ea90ff3 Compare June 18, 2022 19:42
@@ -146,7 +146,7 @@ def highlighted_area
# @api private
# This is just for debugging purpose.
def to_s
format('%<severity>s:%3<line>d:%3<column>d: %<message>s',
Copy link
Member Author

Choose a reason for hiding this comment

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

The following change leads to a build failure on JRuby:

-        format('%<severity>s:%3<line>d:%3<column>d: %<message>s',
+        format('%{severity}:%3{line}:%3{column}: %{message}',
       expected: "C:  1:  1: message % test"
            got: "C:1:1: message % test"

Works fine on MRI. Even though it probably makes sense to file a JRuby ticket, I'd say that we have to keep this as is to support correct behaviour on older JRuby versions.

cc @headius

@@ -46,7 +46,7 @@ def report_file(file, offenses)

offenses.each do |o|
output.printf(
"%<severity>s:%3<line>d:%3<column>d: %<message>s\n",
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as in offense.rb.

CONTRIBUTOR = '[@%<user>s]: https://github.com/%<user>s'
SIGNATURE = Regexp.new(format(Regexp.escape('[@%<user>s][]'), user: '([\w-]+)'))
CONTRIBUTOR = '[@%{user}]: https://github.com/%{user}'
SIGNATURE = Regexp.new(format(Regexp.escape('[@%<user>s][]'), user: '([\w-]+)')) # rubocop:disable Style/FormatStringToken
Copy link
Member Author

Choose a reason for hiding this comment

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

Appreciate any clever solution that wouldn't offend the cop and would allow for Regexp nesting with escaping. I cracked my teeth here.

MSG = 'Assignment Branch Condition size for %<method>s is too high. ' \
'[%<abc_vector>s %<complexity>.4g/%<max>.4g]'
MSG = 'Assignment Branch Condition size for %{method} is too high. ' \
'[%{abc_vector} %<complexity>0.4g/%<max>0.4g]' # rubocop:disable Style/FormatStringToken
Copy link
Member Author

Choose a reason for hiding this comment

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

It feels that the cop needs to consider this as an exception:

format('%<complexity>.4g', complexity: 12.3456) # => "12.35"
format('%{complexity}.4g', complexity: 12.3456) # => "12.3456.4g"

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 18, 2022

If my understanding that it's better to release 2.0 soon is correct, I intend to continue with the few remaining 2.0 issues.

I'm not opposed to doing major releases more often in general. We should probably start some discussion about our goals for 2.0 soon.

@pirj
Copy link
Member Author

pirj commented Jun 19, 2022

Does it make sense to make a 2-0-breaking-changes branch, and create a PR from it to master? We could accumulate breaking changes there that can't make their way to master? Candidates are:

@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch from ea90ff3 to fbf9518 Compare June 19, 2022 14:59
@pirj pirj force-pushed the 8227-change-enforced-stye-of-format-string-token-cop branch from fbf9518 to ddb695b Compare June 19, 2022 15:04
@bbatsov
Copy link
Collaborator

bbatsov commented Jun 20, 2022

We can just create a branch named rubocop-2.0. :-) My only concern with this is who's going to be keeping it in sync with master - I assume there are often going to be conflicts here and there. That's the main reason this branch doesn't exist already.

@koic
Copy link
Member

koic commented Jun 21, 2022

We can just create a branch named rubocop-2.0. :-) My only concern with this is who's going to be keeping it in sync with master - I assume there are often going to be conflicts here and there. That's the main reason this branch doesn't exist already.

I think it's better NOT to make rubocop-2.0 branch. For example, I've heard that RubyGems / Bundler suffered from the branching strategy in the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default for Style/FormatStringToken
3 participants