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 #9771] Fix a false positive for Style/TrivialAccessors #9772

Merged

Conversation

koic
Copy link
Member

@koic koic commented May 5, 2021

Fixes #9771.

This PR fixes a false positive for Style/TrivialAccessors when defining a method that is not a writer.


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.

@bbatsov
Copy link
Collaborator

bbatsov commented May 5, 2021

I have the vague memory that this was by design, so people would uncover "accidental" accessors, regardless of the name. I also thought we had some configuration about the exactness of the name match, but I don't see it. I wonder if I'm thinking of some similar cop. :-)

@bbatsov
Copy link
Collaborator

bbatsov commented May 5, 2021

Ah, actually it seems we didn't include examples of the config options in the docs, which is why I didn't see them at first. I was thinking of ExactNameMatch.

Fixes rubocop#9771.

This PR changes `AllowDSLWriters` to true by default because
it's still a trivial accessor and most people are unlikely to be
creating DSLs.

By this will prevent a false positive for `Style/TrivialAccessors`
when defining a method that is not a DSL writer.
@koic koic force-pushed the fix_false_positive_for_style_trivial_accessors branch from 5b0edda to d236803 Compare May 10, 2021 04:09
@koic
Copy link
Member Author

koic commented May 10, 2021

Actually the issue was because the default value of AllowDSLWriters option.
I referred to #963 and it looks like the default value was maybe set in opposite.

I've updated PR by changing the default value from false to true for AllowDSLWriters option adding missing examples.

@bbatsov bbatsov merged commit 8ed41bb into rubocop:master May 10, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented May 10, 2021

Great work with the examples! I had forgotten how many options this cop had, but now they will be a lot easier to comprehend/discover.

@koic koic deleted the fix_false_positive_for_style_trivial_accessors branch May 10, 2021 07:26
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.

Style/TrivialAccessors make unwanted changes
2 participants