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 #8506] Add AllowedParentClasses config to Lint/MissingSuper. #11940
[Fix #8506] Add AllowedParentClasses config to Lint/MissingSuper. #11940
Conversation
313e068
to
c940c51
Compare
Change looks good, but perhaps we can generalize the setting name to divorce it from one particular reason for ignoring a node. E.g. |
Agreed - the name should be more generic. Also this settings needs to be documented and some example usages should be added to the docs. |
That makes sense,
I wasn't sure about this, I'll add something. Thanks for pointing it out |
c940c51
to
77a425b
Compare
77a425b
to
91d5809
Compare
classes from this cop, for example in the case of an abstract class that is | ||
not meant to be called with `super`. In those cases, you can use the | ||
`ExcludedParentClasses` option to specify which classes should be excluced | ||
*in addition to* `Object` and `BasicObject`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This document and examples are auto-generated based on the source code. Please update lib/rubocop/cop/lint/missing_super.rb directly.
There's no need to update the docs/modules/ROOT/pages/cops_lint.adoc doc as it will be generated at the time of release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @koic, I've amended the commit to keep the history clean.
I hope I did it right 😄
91d5809
to
84f2c69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
@@ -60,6 +67,22 @@ module Lint | |||
# end | |||
# end | |||
# | |||
# @example ExcludedParentClasses: [MyAbstractClass] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be named AllowedParentClasses
to be in-line with how we typically name stuff. /cc @koic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the new suggested name :-)
@@ -14,6 +14,13 @@ module Lint | |||
# Autocorrection is not supported because the position of `super` cannot be | |||
# determined automatically. | |||
# | |||
# `Object` and `BasicObject` are excluded from this cop because of their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excluded from -> allowed by
Other than my remark about the naming the changes look good as well. I'll merge the PR once the name is updated. |
84f2c69
to
c6c842d
Compare
Thank you @bbatsov, the new suggested name makes sense. |
# # there's no need to specify Object or BasicObject | ||
# # in the AllowedParentClasses option. | ||
# end | ||
# end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example ClassWithNoParent
class is irrelevant to the AllowedParentClasses
configuration and is always allowed, so it looks better to put it in the # good
case of @example
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I can move it there, but I wanted to make it absolutely clear that no matter what the value of AllowedParentClasses
is, Object
and BasicObject
will always be allowed, so this example is just to remark that one more time in case the reader misses it from the description above. Although it can technically go in both places, I feel like it's more useful here. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I understand the intention. But @example ConfigurationName
is typically used to describe unique behaviors of ConfigurationName
. For the sake of consistent documentation structure, it would be better to move this to @example
I think :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't really argue with that, I understand the value of consistency 🙂
I'll move this up as suggested 👍
The default value of %w[BasicObject Object] is kept for backwards compatibility, but users can now add to that list using the AllowedParentClasses config value.
c6c842d
to
09d0ff5
Compare
I've got a "rubocop server is not running" error while running specs on 2.7, but that might just be a flaky? |
Yeah, I have rerun the CI matrix contains flaky spec. Thank you. |
Add
AllowedParentClasses
config toLint/MissingSuper
.The default value of
%w[BasicObject Object]
is kept for backwards compatibility, but users can now add to that list using theAllowedParentClasses
config value.It's important to note that the value of
AllowedParentClasses
will be ADDED to the default value.This is because I don't foresee scenarios where users would want to remove
BasicObject
orObject
from this list, and removes the requirement for always specifying them.I'm open to feedback on this assumption and happy to change it into a full replacement, I simply went with the most logical approach in my opinion.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.