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

[SDQ-2009] lint missing super #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/rubocop-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Lint/ErbNewArguments:
Description: Emulates warnings in Ruby 2.6
Enabled: true

Lint/MissingSuper:
Description: Checks for the presence of constructors and lifecycle callbacks without calls to ‘super`.
Enabled: true
Exclude:
- app/services/**/*

Comment on lines +19 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use AllowedParentClasses (if possible) instead of excluding full directories
https://docs.rubocop.org/rubocop/1.54/cops_lint.html#lintmissingsuper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would include:
ApplicationService
ValidateGiftCsvRow
BaseHandler
AbstractHandler
Sends:TrackerServices:Base

Do we anticipate other Rails microservices to implement these parent classes?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed with Marc. Unless a good reason, super should be used.
Its already linked, sharing for posterity:

rubocop/ruby-style-guide#809 (comment)

The problem is that you don't know this is the case if the superclass is part of another library or maintained by someone else. The base class may add some initialization logic in the future that would not get run by your subclass.

It is worth pointing out that the Java language has required all constructors to call a superconstructor since the beginning for exactly this reason: not calling the superclass constructor breaks the guarantee that it will run when instances of that class or its subclasses are instantiated. Java code requires that the subclass invoke a superclass constructor directly, or else a call to the superclass's default (no-args) constructor will be inserted for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like we should keep this for full enforcement then, with no exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(it also sounds like I should instead go ahead and start full rubocop enforcement per #14, so that it is no longer possible to bypass this)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds like we should keep this for full enforcement then, with no exceptions?

Ok with creating exceptions for the classes listed above (I'll double check these and share here)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess, what I'm trying to articulate is that list of classes doesn't feel like the appropriate solution outside of the monolith. If we share this repo/gem among other classes, it should only contain contents that are relevant to all rails repos (like whitelisting a widely shared pattern like app/services). If we're including ApplicationService with something like CookieCutter, than it feels more appropriate to whitelist here. However the others should be whitelisted in the monolith, not in this repo.

Relatedly, if we have this sort of complicated set of rules, that points to a need to go ahead and start enforcing more strictness with our rules (which is an underlying sentiment I'm seeing here based on visible patterns + these comments)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree – we could just override this in the application Rubocop config instead of in the gem then

Lint/RedundantStringCoercion:
Description: Checks for Object#to_s usage in string interpolation.
Enabled: true
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/sendoso/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Rubocop
module Sendoso
VERSION = '0.1.6'
VERSION = '0.1.7'
end
end