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

~~Consider disabling~~ Re-enable Lint/MissingSuper #195

Open
will opened this issue Aug 26, 2020 · 19 comments
Open

~~Consider disabling~~ Re-enable Lint/MissingSuper #195

will opened this issue Aug 26, 2020 · 19 comments
Assignees
Labels
approved 👍 rule change 👩‍⚖️ Suggest a style guide rule change

Comments

@will
Copy link
Contributor

will commented Aug 26, 2020

Hi, I just updated and noticed this linter was turned on in 0.5.0.

It has a ton of problems for me since I use abstract! from sorbet. It generates an initialize method in the abstract parent class to raise an exception if anyone accidentally tries to instantiate it. All of the child classes have their own initialize methods and are correctly not calling super, but the linter thinks they should be calling it.

I'm going to disable it for myself in the yaml file, but wanted to open the issue here in case others have the same problem.

@searls
Copy link
Contributor

searls commented Aug 26, 2020

Thanks for calling this out! Enough people use sorbet that I think this alone is worth rolling back. Even as I added it I could imagine a couple corner cases where not calling super was the right thing to do

@searls searls self-assigned this Aug 26, 2020
@searls searls added approved 👍 rule change 👩‍⚖️ Suggest a style guide rule change labels Aug 26, 2020
@searls searls closed this as completed in aba3fa4 Aug 26, 2020
@searls
Copy link
Contributor

searls commented Aug 26, 2020

Landed in 0.5.2

@will
Copy link
Contributor Author

will commented Aug 26, 2020

Thanks!

Also, rubocop may have disabled Style/MethodMissingSuper when they put in Lint/MissingSuper rubocop/rubocop#8376

I do remember it yelling at me about the method missing one, but I cant remember if it was useful or not.

@searls
Copy link
Contributor

searls commented Aug 26, 2020

IIRC the MissingSuper is a recent replacement for the other one

@will
Copy link
Contributor Author

will commented Aug 26, 2020

That's my understanding, but if the new MissingSuper is disabled here, you might want to turn back on MethodMissingSuper manually?

@searls
Copy link
Contributor

searls commented Aug 26, 2020

My understanding is MethodMissingSuper was removed in favor of MissingSuper and there is unfortunately no apparent way to configure it to only cover method missing 😦

https://docs.rubocop.org/rubocop/0.89/cops_lint.html

@marcandre
Copy link

marcandre commented Aug 26, 2020

It has a ton of problems for me since I use abstract! from sorbet. It generates an initialize method in the abstract parent class to raise an exception if anyone accidentally tries to instantiate it.

Interesting. I couldn't read this in the reference given, do you know of another source?

Unless I'm missing something, it seems completely mistaken from sorbet. They should instead override MyAbstractClass.new instead of MyAbstractClass#initialize. An abstract class could have very valid reason to do initializations, and a concrete class shouldn't have to create an empty initialize if it doesn't require initialization parameters.

Edit: I opened sorbet/sorbet#3388

@searls searls reopened this Aug 31, 2020
@searls
Copy link
Contributor

searls commented Aug 31, 2020

Will reopen and see if this is a sorbet-specific thing and they're open to changing it. If so and nobody else raises issues I'll turn it back on

@searls searls added question 🤔 Further information is requested and removed approved 👍 labels Aug 31, 2020
@ttilberg
Copy link
Contributor

ttilberg commented Nov 18, 2020

@searls For what it's worth, I ran into this and was surprised outside of Sorbet a few months back: https://www.reddit.com/r/ruby/comments/hw8t6a/how_to_please_standardrbrubocop/. It also references another user in Rubocops tracker with a similar issue: rubocop/rubocop#3760 (comment).

Do you feel that super should get called in instances like this? (I don't feel like that's the case)

@marcandre
Copy link

@ttilberg I agree, the rule doesn't quit work for method_missing and for repond_to_missing?; it sometimes makes sense to unconditionally return from those without calling super. I'll fix that later today 👍

@searls
Copy link
Contributor

searls commented Nov 20, 2020

@ttilberg if you look at @marcandre's PR, the feedback received was to document why this hook should be an exception. Since you've written about this before and care a lot about it, could you provide a documentation update for inclusion in that PR so that it can be merged upstream?

@marcandre
Copy link

marcandre commented Nov 20, 2020 via email

@jmkoni
Copy link
Contributor

jmkoni commented Jan 22, 2021

@will We are looking at turning this on because it's good for the average Rubyist. Has Sorbet changed? Or would this still be an issue?

@will
Copy link
Contributor Author

will commented Jan 22, 2021

@jmkoni do you know of a way that I can test turning it back on in a single project, to see what happens? Something in that yaml file maybe?

@jmkoni
Copy link
Contributor

jmkoni commented Jan 22, 2021

@will yeah! You should be able to do something like this, but instead enable Lint/MissingSuper. I'm guessing you already have a yaml file that looks very similar. #158 (comment)

@will
Copy link
Contributor Author

will commented Jan 22, 2021

with a .standard.yml file of

parallel: true
ignore:
  - 'sorbet/**/*'
  - '**/*':
    - Lint/ConstantDefinitionInBlock # sorbet enums

Lint/MissingSuper:
  Enabled: true

standardrb 0.11.0 doesn't report any problems, however I would have expected these two classes

# typed: strict
# frozen_string_literal: true

class Factory
  extend T::Sig
  extend T::Helpers
  abstract!

  # sorbet workaround, ref: https://github.com/sorbet/sorbet/issues/2374
  alias_method :initialize_abstract, :initialize

  sig { params(params: T::Hash[Symbol, T.untyped]).void }
  def initialize(params = {})
    initialize_abstract
  end
end

class ClusterFactory < Factory
  extend T::Sig

  sig { params(params: T::Hash[Symbol, T.untyped]).void }
  def initialize(params = {})
    # no super
  end
end

to have generated an error with this on? Unless that alias trick is also solving that problem, but it seems like it wouldn't.

@will
Copy link
Contributor Author

will commented Jan 22, 2021

Oh I see it was supposed to be in .rubocop.yml not standard, and I was supposed to run rubocop directly and not standard.

This still breaks for me in that case above. Also in another area I'm on purpose not calling super in subclasses, but this is not related to anything sorbet.

Either way I'm okay with whatever you all decide as long as I can still opt out of this check with an ignore, which I think would work like I'm doing for Lint/ConstantDefinitionInBlock

@searls
Copy link
Contributor

searls commented Jan 23, 2021

TIL (well, re-learned) that we allowed rule-specific ignores in Standard. That being the case I think we should turn this back on and hope Sorbet users who need this will find this issue.

@searls searls changed the title Consider disabling Lint/MissingSuper ~~Consider disabling~~ Re-enable Lint/MissingSuper Jan 23, 2021
@searls searls added approved 👍 and removed question 🤔 Further information is requested labels Jan 23, 2021
@marcandre
Copy link

hope Sorbet users who need this will find this issue

and upvote / comment on the issue I opened on Sorbet...

@jasonkarns jasonkarns added this to Backlog in Test Double Trouble Oct 1, 2021
@searls searls removed this from Backlog in Test Double Trouble Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved 👍 rule change 👩‍⚖️ Suggest a style guide rule change
Projects
None yet
Development

No branches or pull requests

5 participants