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

Conversation

rhunterharris
Copy link
Contributor

Remove enforcement of Lint/MissingSuper for app/services directory and subdirectories, matching overrides in monolith.

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

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

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.

Lint/MissingSuper
5 participants