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

scalastyleSources does not include all source directories #47

Closed
fthomas opened this issue Dec 23, 2015 · 13 comments
Closed

scalastyleSources does not include all source directories #47

fthomas opened this issue Dec 23, 2015 · 13 comments

Comments

@fthomas
Copy link

fthomas commented Dec 23, 2015

In one of my projects Scalastyle 0.8.0 does not inspect all source files. The project is a JVM/JS cross project and has its sources in different directories (shared/src/main/scala, jvm/src/main/scala-2.10, jvm/src/main/scala-2.11, etc.). and it seems that Scalastyle only inspect files in jvm/src/main/scala because scalastyleSources only contains this directory:

> coreJVM/scalastyleSources
[info] List(/home/frank/data/code/refined/core/jvm/src/main/scala)

I suspect scalastyleSources should by default instead contain the same directories as sourceDirectories (or unmanagedSourceDirectories):

> coreJVM/sourceDirectories
[info] List(
  /home/frank/data/code/refined/core/jvm/src/main/scala-2.11,
  /home/frank/data/code/refined/core/jvm/src/main/scala,
  /home/frank/data/code/refined/core/jvm/src/main/java,
  /home/frank/data/code/refined/core/shared/src/main/scala,
  /home/frank/data/code/refined/core/jvm/target/scala-2.11/src_managed/main)

Btw, the same problem exists in Cats and circe.

@fthomas
Copy link
Author

fthomas commented Dec 31, 2015

Pinging @adrian-wang since this is related to #41.

Note that scalastyleSources can be overriden for the Compile configuration like this:

(scalastyleSources in Compile) <++= unmanagedSourceDirectories in Compile

But doing the same for the Test configuration has no effect.

@adrian-wang
Copy link
Contributor

Hi @fthomas , did you use

(scalastyleSources in Test) <++= unmanagedSourceDirectories in Compile

or

(scalastyleSources in Test) <++= unmanagedSourceDirectories in Test

?

@fthomas
Copy link
Author

fthomas commented Jan 4, 2016

I tried all of

(scalastyleSources in Test) <++= unmanagedSourceDirectories in Compile,
(scalastyleSources in Test) <++= unmanagedSourceDirectories in Test,
(scalastyleSources in Test) <++= unmanagedSourceDirectories in (Test, compile),
(scalastyleSources in (Test, compile)) <++= unmanagedSourceDirectories in Compile,
(scalastyleSources in (Test, compile)) <++= unmanagedSourceDirectories in Test,
(scalastyleSources in (Test, compile)) <++= unmanagedSourceDirectories in (Test, compile),
(scalastyleSources in (Test, scalastyle)) <++= unmanagedSourceDirectories in Compile,
(scalastyleSources in (Test, scalastyle)) <++= unmanagedSourceDirectories in Test,
(scalastyleSources in (Test, scalastyle)) <++= unmanagedSourceDirectories in (Test, compile),

but none of those had the desired effect.

In the sbt console test:unmanagedSourceDirectories outputs the directories that should be added to test:scalastyleSources.

@adrian-wang
Copy link
Contributor

This is unreasonable...

@fthomas
Copy link
Author

fthomas commented Jan 4, 2016

Indeed. Is there anything I could do to "debug" this?

fthomas added a commit to fthomas/refined that referenced this issue Jan 6, 2016
This contains a workaround for
scalastyle/scalastyle-sbt-plugin#47
@pjrt
Copy link

pjrt commented Sep 8, 2016

One way we worked around this:

      scalastyleSources in Compile <++= unmanagedSourceDirectories in Test,

This means that running sbt scalastyle (no test:) will also run scalastyle on the test folder.

@matthewfarwell
Copy link
Member

Scalastyle is now an AutoPlugin, which may have changed behaviour slightly. Could you recheck this and see if there is still a problem, using 0.9.0-SNAPSHOT please?

@fthomas
Copy link
Author

fthomas commented Apr 22, 2017

@matthewfarwell I tried 0.9.0-SNAPSHOT but scalastyleSources still contains only one directory:

[info] * /home/frank/data/code/refined/modules/core/jvm/src/main/scala

@matthewfarwell
Copy link
Member

matthewfarwell commented Apr 23, 2017

I don't understand the problem. I can do the following (using 0.9.0-SNAPSHOT, but as far as I'm aware this behaviour hasn't changed).

Add two directories and single file to scalastyleSources:

build.sbt:

name := "single"

version := "0.1.0"

scalastyleSources in Compile := Seq(
                                baseDirectory.value / "extra" / "foo",
                                baseDirectory.value / "extra" / "bar",
                                baseDirectory.value / "extra" / "Top.scala")

Use master scalastyle:

project/plugins.sbt:

resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "0.9.0-SNAPSHOT")

Make sure the files exist:

$ mkdir extra extra/foo extra/bar
$ touch extra/Top.scala extra/foo/Foo.scala extra/bar/Bar.scala

And scalastyle processes in the output:

$ sbt scalastyle
[info] Loading project definition from /home/mfarwell/code/scalastyle/test/single/project
[info] Set current project to single (in build file:/home/mfarwell/code/scalastyle/test/single/)
[info] scalastyle using config /home/mfarwell/code/scalastyle/test/single/scalastyle-config.xml
[info] scalastyle Processed 3 file(s) <-------- **** PROCESSED THREE FILES ***
[info] scalastyle Found 0 errors
[info] scalastyle Found 0 warnings
[info] scalastyle Found 0 infos
[info] scalastyle Finished in 4 ms
[success] created output: /home/mfarwell/code/scalastyle/test/single/target
[success] Total time: 0 s, completed Apr 23, 2017 8:35:52 AM

@matthewfarwell
Copy link
Member

@fthomas @adrian-wang Could you see if the behaviour has changed between 0.8.0 and 0.9.0, and if not, please tell me what the problem is, if indeed there is one. Thanks.

@fthomas
Copy link
Author

fthomas commented Aug 13, 2017

@matthewfarwell The problem still exists in 0.9.0. scalastyleSources still contains only one source directory

> coreJVM/scalastyleSources
[info] * /home/frank/data/code/refined/modules/core/jvm/src/main/scala

instead of all relevant source directories for this project:

> coreJVM/unmanagedSourceDirectories
[info] * /home/frank/data/code/refined/modules/core/jvm/src/main/scala-2.12
[info] * /home/frank/data/code/refined/modules/core/jvm/src/main/scala
[info] * /home/frank/data/code/refined/modules/core/jvm/src/main/java
[info] * /home/frank/data/code/refined/modules/core/shared/src/main/scala-2.12
[info] * /home/frank/data/code/refined/modules/core/shared/src/main/scala

Since all my sources are in /home/frank/data/code/refined/modules/core/shared/src/main/scala, scalastyle doesn't check any files.

The problem is not that I cannot change scalastyleSources to contain the same directories as unmanagedSourceDirectories (because we've done this at least in cats, circe, and refined) but that scalastyleSources should contain the same directories as unmanagedSourceDirectories by default. In a typical JVM / JS cross project it shouldn't be required to change scalastyleSources.

BTW, I had similar issues with other plugins:

@matthewfarwell
Copy link
Member

Can you try this with the snapshot and see if it works please?

@fthomas
Copy link
Author

fthomas commented Aug 15, 2017

Just tried 0.10.0-SNAPSHOT and it picks up all my source directories. Thanks @matthewfarwell!

fthomas added a commit to fthomas/cats that referenced this issue Aug 21, 2017
This version is compatible with sbt 1.0.0 and allows to get rid of
a workaround for scalastyle/scalastyle-sbt-plugin#47.

It also complained about new issues which I've ignored for now. The same
issues already have been silenced in other places of the library.
sjrd added a commit to sjrd/scala-js that referenced this issue Aug 28, 2017
This the latest version, and the first one supporting sbt 1.0.

Moreover, it now takes "shared" source directories into account by
default, i.e., all `unmanagedSourceDirectories`. See the issue
scalastyle/scalastyle-sbt-plugin#47.
Therefore, we remove the workaround we had for that issue.
sjrd added a commit to sjrd/scala-js that referenced this issue Aug 28, 2017
This the latest version, and the first one supporting sbt 1.0.

Moreover, it now takes "shared" source directories into account by
default, i.e., all `unmanagedSourceDirectories`. See the issue
scalastyle/scalastyle-sbt-plugin#47.
Therefore, we remove the workaround we had for that issue.
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

No branches or pull requests

4 participants