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

[Fix #9962] Update Style/WordArray to register an offense in percent style if any values contain spaces #9981

Merged
merged 1 commit into from Aug 12, 2021

Conversation

dvandersluis
Copy link
Member

Updates Style/WordArray to mark %w() arrays as offenses if they contain any values with spaces.

Fixes #9962.


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.

Comment on lines 76 to 79
def invalid_percent_array_contents?(node)
# Disallow %w() arrays that contain invalid encoding or spaces
complex_content?(node.values, word_regex: false)
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Originally this used the same complex_content? check, taking the WordRegex configuration into account, however, this caused 206 offenses on rubocop itself, disallowing a lot of %w() arrays that are probably good to keep (ie. they contained non word characters). For instance:

%w(1 2.0 [1] {} :sym :"#{a}").each do |lit|

As a result, I made the check only look for space issues. If desired we could add in another configuration to specify a regex for this check?

… `percent` style if any values contain spaces.
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 12, 2021

Good work!

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.

WordArray should enforce bracket style for strings that don't match WordRegex
2 participants