Giter Site home page Giter Site logo

Comments (14)

leifwickland avatar leifwickland commented on May 21, 2024

+1

from scalastyle.

coltfred avatar coltfred commented on May 21, 2024

Agreed! +1

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

I took a stab at trying to fix this. I got far enough to realize that the Scalariform parser doesn't seem to designate function definitions as being nested. It was easy enough to modify traverse() to know if the function it was looking at was declared inside of another function, but that's insufficient because Scala allows a function to declare a type which contains functions which should not be considered nested. I didn't see an obvious way to detect in the stream of Scalariform tokens that a new anonymous type was being defined. Does Scalastyle contain code to do that already?

from scalastyle.

lhohan avatar lhohan commented on May 21, 2024

+1

from scalastyle.

rklaehn avatar rklaehn commented on May 21, 2024

+1

I am not sure if this can be done in the same turn, but I would also like the following to be ignored:

trait Bla {
  def foo: Int
}

object Bla {
  ...
  private class Impl extends Bla {
    def foo = 3 // this is effectively private, so it should not be flagged!
  }
}

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

@rklaehn

Does the ignoreOverride property satisfy the requirement for the second half of your request?

from scalastyle.

rklaehn avatar rklaehn commented on May 21, 2024

I did not know about this. It mostly satisfies the requirement, but not entirely.

I like to write in a style where I define sealed traits or sealed abstract classes, and then implement the logic in a private class in the companion object of the trait. That way you don't have to put private in front of every little helper method, and it is much more difficult to accidentally make something public. So I would like to have scalastyle ignore everything in a private implementation class, not just overridden methods.

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

@rklaehn

That was supposed to be:

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

@rklaehn Yeah, that makes sense. No, I don't know of a way to configure Scalastyle to do that. It seems like it ought to be possible to detect that situation.

from scalastyle.

matthewfarwell avatar matthewfarwell commented on May 21, 2024

I think I've fixed this.

Could one of you try it out and see if it fulfils your needs please? You can use the batch mode of scalastyle. Thanks.

As for the private class, I don't think there is anything I can do about this. You say that it is effectively private, but it isn't really. I can't make it private because it implements a trait. If it didn't implement the trait, then I could (should?) make it private.

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

@matthewfarwell, thank you for your work on this.

Your change almost entirely fixes the issue. The one case it doesn't handle could be considered a separate issue.

Specifically if a val receives its value from an anonymous block and a defis defined inside that block then scalastyle still treats it as a public method.

For example in the following, adtToName is detected as violating PublicMethodsHaveTypeChecker:

private val namesToAdt: Map[String, SomeAdt] = {
  def adtToName(a: SomeAdt) = a match {
    case Adt1 | Adt2 | Adt3 => a.name
  }
  AllAdtMembers.map(a => adtToName(a) -> a).toMap
}

If you feel like that should be treated as a separate issue, please let me know. I'd be happy to write it up.

Thanks again for your hard work fixing this issue.

from scalastyle.

matthewfarwell avatar matthewfarwell commented on May 21, 2024

Yes, this should be raised as a separate issue. It is a relatively easy
fix, which I'll do when I get a minute.

Have fun,

Matthew Farwell.

2014-12-29 21:01 GMT+01:00 Leif Wickland [email protected]:

@matthewfarwell https://github.com/matthewfarwell, thank you for your
work on this.

Your change almost entirely fixes the issue. The one case it doesn't
handle could be considered a separate issue.

Specifically if a val receives its value from an anonymous block and a defis
defined inside that block then scalastyle still treats it as a public
method.

For example in the following, adtToName is detected as violating
PublicMethodsHaveTypeChecker:

private val namesToAdt: Map[String, SomeAdt] = {
def adtToName(a: SomeAdt) = a match {
case Adt1 | Adt2 | Adt3 => a.name
}
AllAdtMembers.map(a => adtToName(a) -> a).toMap
}

If you feel like that should be treated as a separate issue, please let me
know and I'll write up up.

Thanks again for your hard work fixing this issue.


Reply to this email directly or view it on GitHub
#48 (comment)
.

from scalastyle.

matthewfarwell avatar matthewfarwell commented on May 21, 2024

#129 has now been fixed, Could someone test it and see if it really does fix their issues please?

Thanks.

from scalastyle.

leifwickland avatar leifwickland commented on May 21, 2024

@matthewfarwell, Yes #129 is fixed for me. Thanks for your work.

from scalastyle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.