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
Add new Lint/MissingSuper
cop
#8376
Conversation
@@ -137,6 +137,7 @@ def external_dependency_checksum | |||
end | |||
|
|||
def self.inherited(subclass) | |||
super |
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.
😊
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.
@fatkodima Marc-André is smiling for a reason.
There's no super
for a class with no parent.
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.
Actually I still like adding it, and I was surprise I didn't in the first place.
Great cop & PR ❤️ |
Thanks 😊 |
|
Looks like a |
That sounds reasonable.
Lint. I'm surprised we've put the other two cops until Style, but I guess that's historical - in the very beginning Style was the only department. :-)
E.g. this should probably go under Lint. |
I'm wondering if we should expose the ability to add more stateless classes and callbacks, but probably that's an overkill at that point. Good work! |
e20c4fd
to
ee8499d
Compare
Implemented this.
Agreed. |
ee8499d
to
1f8765b
Compare
end | ||
|
||
def contains_super?(node) | ||
node.each_descendant(:super, :zsuper).any? |
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.
any
is not the same thing as !.empty?
. It will work the same way in most cases, however this will fail if the array contains nil
.
[1] pry(main)> [nil].any?
=> false
[2] pry(main)> ![nil].empty?
=> true
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.
Correct, but each_descendant(:super, :zsuper)
won't return array with nils - either empty or with Node
instances.
1f8765b
to
06d4871
Compare
Hi @fatkodima && @marcandre.
I don't see any reason for me to add a Full code:
The result from rubocop:
|
Upon reflection, I have to agree that the case of Same idea for Unless there's objection, I'd remove them. |
I'd also add missing |
@fatkodima oh, good catch. Want to take care of this? You seem to write up PRs faster than I can review them 😅 |
😄 |
Sure thing: #8480 |
Would it be possible to make the list of stateless classes configurable? We have a lot of offenses for children of a couple of base classes where we know it's unnecessary to call |
This commit fixes the following error: > Error: The `Style/MethodMissingSuper` cop has been removed since > it has been superseded by `Lint/MissingSuper`. Please use > `Lint/MissingSuper` instead. cf. rubocop/rubocop#8376
I have a similar problem like @haines my service classes inherit but don't need to call super rubocop/ruby-style-guide#809 (comment) I would like to exclude those classes or any that inherit from ApplicationService. EDIT: fortunately all my services objects are inside app/services so I added this to rubocop.yml Lint/MissingSuper:
Exclude:
- 'app/services/**/*' |
This is required to make the latest version of standard happy See rubocop/ruby-style-guide#809 and rubocop/rubocop#8376 for context
* Show less months in the dropdown * A bit less top padding for charts * tests for to_s * Adjust month formatting to Mon-Year * Update standard, apply fixes that can auto apply * Ensure we call super so parent classes can initialize This is required to make the latest version of standard happy See rubocop/ruby-style-guide#809 and rubocop/rubocop#8376 for context * More linting fixes * Bump cache versions Just incase the date formatting change happens to mess w/ our cache keys * Fix the keys to match the new period formatting * Updated overview card chart spacing Co-authored-by: claudiovallejo <hola@claudiovallejo.mx>
@@ -137,6 +137,7 @@ def external_dependency_checksum | |||
end | |||
|
|||
def self.inherited(subclass) | |||
super |
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.
@fatkodima Marc-André is smiling for a reason.
There's no super
for a class with no parent.
expect_no_offenses(<<~RUBY) | ||
class Foo | ||
def method_missing(*args) | ||
super |
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.
Is this calling method_missing
on Object
?
expect_offense(<<~RUBY) | ||
class Foo | ||
def self.inherited(base) | ||
^^^^^^^^^^^^^^^^^^^^^^^^ Call `super` to invoke callback defined in the parent class. |
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.
What would super
refer to? Foo
has Object
as an implicit parent.
Why super
is needed in this case?
For context - rubocop/ruby-style-guide#809
Lint
orStyle
department.Style/MethodMissingSuper
cop, checking onlymethod_missing
callback. Should that cop be deprecated in favor of this new cop?