Scalastyle examines your Scala code and indicates potential problems with it.
Full documentation is currently available on the Scalastyle website
scalastyle-sbt-plugin
License: Apache License 2.0
Scalastyle examines your Scala code and indicates potential problems with it.
Full documentation is currently available on the Scalastyle website
I have a play project with multiple modules. Each module is configured to run scalastyle.
It works well when NullChecker is set to warning level.
<check level="warning" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
If it is set to error level:
<check level="error" class="org.scalastyle.scalariform.NullChecker" enabled="true"></check>
I receive an error on checking with this stacktrace:
java.lang.RuntimeException: exists error
at scala.sys.package$.error(package.scala:27)
at scala.Predef$.error(Predef.scala:142)
at org.scalastyle.sbt.Tasks$.onHasErrors$1(Plugin.scala:99)
at org.scalastyle.sbt.Tasks$.doScalastyle(Plugin.scala:106)
at org.scalastyle.sbt.ScalastylePlugin$$anonfun$4$$anonfun$apply$1.apply(Plugin.scala:63)
at org.scalastyle.sbt.ScalastylePlugin$$anonfun$4$$anonfun$apply$1.apply(Plugin.scala:63)
at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (common/*:scalastyle) exists error
Our environment:
Oracle JDK 1.7 or 1.8
SBT 0.13.0
Scala 2.10.3 or 2.10.4
Scalastyle sbt plugin 0.4.0
The example given in http://www.scalastyle.org/sbt.html
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
no longer works because all the keys are now in the autoImport
object. Is there a reason for the change? Even though there is import autoImport._
, this only makes the key accessible inside ScalastylePlugin
itself; you can no longer write ScalastylePlugin.scalastyle
directly.
We have to do
import org.scalastyle.sbt.ScalastylePlugin.autoImport._
to get it working.
In theory, files could be excluded using following construct:
scalastyleSources := scalastyleSources in dao.value .map(PathFinder.apply _) .reduceLeft[PathFinder]((a, b) => a +++ b) .**("*") .filter( ! _.getAbsolutePath.contains("src/main/scala/my/generated/metadata")).get
but - scalastyle seems to take entire parent directory instead of single file passed in.
updated from 0.4 to 0.5. Since then, no scalastyle-result.xml-file or any other similar file is written when calling sbt scalastyle.
Add support for auto plugins in sbt 0.13.5
I run sbt scalastyle
command end everything looks fine, while exit code of this task is 1 that fails our CI server.
pozharko@pozharko-desktop ~/Code/ergo/ergo $ sbt scalastyle
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /home/pozharko/Code/ergo/ergo/project
[info] Loading settings from build.sbt,lock.sbt ...
[info] Set current project to ergo (in build file:/home/pozharko/Code/ergo/ergo/)
[info] lock.sbt is up to date.
[info] scalastyle using config /home/pozharko/Code/ergo/ergo/scalastyle-config.xml
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:294:12: Avoid using return
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:311:12: Avoid using return
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:286:37: Avoid using null
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:286:51: Avoid using null
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:126:6: Cyclomatic complexity of 14 exceeds max of 10
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:126:6: Method is longer than 50 lines
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/crypto/Equihash.scala:268:6: Method is longer than 50 lines
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/ErgoApp.scala:74:6: Public method must have explicit type
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/FakePowScheme.scala:20:15: The number of parameters should not exceed 8
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinsEmission.scala:37:4: If block needs braces
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinsEmission.scala:38:9: If block needs braces
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:43: File line length exceeds 160 characters
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:25:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:26:4: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:27:4: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:28:4: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:29:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:30:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:31:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:32:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:33:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:34:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:35:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:37:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:38:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/emission/CoinEmissionPrinter.scala:43:58: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/PoWScheme.scala:24:6: The number of parameters should not exceed 8
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/PoWScheme.scala:35:6: The number of parameters should not exceed 8
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/PoWScheme.scala:107:15: The number of parameters should not exceed 8
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/mining/difficulty/RequiredDifficulty.scala:88:27: Avoid using return
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/settings/StateTypeReaders.scala: File must end with newline character
[error] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/ErgoReadersHolder.scala: expected start of definition, but was Token(VAL,val,596,val)
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala:95:14: Method is longer than 50 lines
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistory.scala:223:6: Method is longer than 50 lines
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/ErgoHistoryReader.scala:103:15: Cyclomatic complexity of 12 exceeds max of 10
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala:161:16: Cyclomatic complexity of 15 exceeds max of 10
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/HeadersProcessor.scala:189:11: If block needs braces
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala:38:16: Cyclomatic complexity of 13 exceeds max of 10
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala:108:23: If block needs braces
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/nodeView/history/storage/modifierprocessors/FullBlockProcessor.scala:38:16: Method is longer than 50 lines
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/local/ErgoMiner.scala: File must end with newline character
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/local/ErgoMiningThread.scala: File must end with newline character
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/local/TransactionGenerator.scala: File must end with newline character
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/org/ergoplatform/local/ErgoStatsCollector.scala: File must end with newline character
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/Test.scala:27:2: Regular expression matched 'println'
[warn] /home/pozharko/Code/ergo/ergo/src/main/scala/Test.scala:28:2: Regular expression matched 'println'
[info] scalastyle Processed 81 file(s)
[info] scalastyle Found 1 errors
[info] scalastyle Found 45 warnings
[info] scalastyle Found 0 infos
[info] scalastyle Finished in 13 ms
[success] created output: /home/pozharko/Code/ergo/ergo/target
[error] Total time: 2 s, completed Mar 14, 2018, 10:44:40 AM
pozharko@pozharko-desktop ~/Code/ergo/ergo $ $?
1: command not found
perhaps with the ability to toggle specific style checks on a per-class basis.
this would enable teams with CI to automatically enforce standards in pull requests.
This is not a big issue, but it seems file is now generated N times, when you have sub-modules in your project:
> scalastyleGenerateConfig
[success] created: C:\Users\Jerzy\Documents\GitHub\unicorn\scalastyle-config.xml
[success] created: C:\Users\Jerzy\Documents\GitHub\unicorn\scalastyle-config.xml
[success] created: C:\Users\Jerzy\Documents\GitHub\unicorn\scalastyle-config.xml
[success] Total time: 0 s, completed 2015-02-08 12:23:57
especially now that the 0.13.0 release seems imminent
Hi,
Is it possible to exclude some sources from scalastyle analysis? I can not find any setting for that.
Thanks in advance!
i would like to generate html report so that i could see it in CI tools.
To get Scalastyle SBT to work with scalastyle IntelliJ idea plugin, the file needs to be in ./idea
or ./project
folders and the config file needs to be called scalastyle_config.xml
(not scalastyle-config.xml
).
This is really silly as you would think everything would be consistent. When trying to set sbt to use the scalastyle_config.xml
in the project folder in a multi module project it doesnt work!
scalastyleConfig := file("project/scalastyle_config.xml")
in sbt;
> show scalastyleConfig
[info] reports/*:scalastyleConfig
[info] scalastyle-config.xml
[info] report-api-common/*:scalastyleConfig
[info] scalastyle-config.xml
[info] report-sparkjobs/*:scalastyleConfig
[info] scalastyle-config.xml
[info] etl/*:scalastyleConfig
[info] scalastyle-config.xml
[info] common/*:scalastyleConfig
[info] scalastyle-config.xml
[info] root-project/*:scalastyleConfig
[info] project/scalastyle_config.xml
This is beyond frustrating.
how to wrote new scalaStyle code for my project to avoid instantiate from other classes{ Avoid new keyword }, i am new to this. how to deploy that rule to my project using maven? @[email protected]
There are quiet
and silent
args (for instance see this PR: #46 ) but it is difficult to see how to configure them anywhere. Please advise and maybe add to plugin documentation.
Ideally I'd like to add to build.sbt
I am follow the manual at http://www.scalastyle.org/sbt.html try to make the style check part of test flow.
after I add below to projects/plugins.sbt
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")
resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"
// Create a default Scala style task to run with tests
lazy val testScalaStyle = taskKeyUnit
testScalaStyle := {
org.scalastyle.sbt.PluginKeys.scalastyle.toTask("").value
}
(test in Test) <<= (test in Test) dependsOn testScalaStyle
error: object scalastyle is not a member of package org
org.scalastyle.sbt.PluginKeys.scalastyle.toTask("").value
^
ScalaStyle plugin uses the legacy sbt.Plugin
class which is not compatible with the newer AutoPlugin
mechanism.
In particular, I'm writing an AutoPlugin
that modifies the scalastyle
task to add automatic "fail on warnings" by applying the "w" argument using partialInput
. That works well if the override to scalastyle
task is specified in a project's build.sbt
file, but if it's specified in an AutoPlugin
then the override order is not respected: the task definition present in your plugin overrides anything I specify in my AutoPlugin
It would be good to migrate your code to use sbt.AutoPlugin
instead
Not sure if I just don't understand how to transfer that setting down through sbt (like q or w) but I couldn't get it to work; had to resort to modifying the sbt launcher to make java open everything open in UTF-8.
I created a multi-project SBT build project,
http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project
and after running sbt scalastyle, I got
Processed 0 file(s)
Found 0 errors
Found 0 warnings
Finished in 3 ms
In SBT shell, scala-source showed all the soruce code folder correctly. PS, it works for single project setup.
scala-source
[info] core/compile:scala-source
[info] /Users/dbtsai/dev/alpineml/core/src/main/scala
[info] datasets/compile:scala-source
[info] /Users/dbtsai/dev/alpineml/datasets/src/main/scala
[info] root/compile:scala-source
[info] /Users/dbtsai/dev/alpineml/src/main/scala
Thanks.
The config file should also allow a URL.
Is it possible to make this plugin run as part of the sbt test
run, and if there are any warnings then to make the tests fail?
This would be really useful for managing shared repo's and using a CI to enforce coding style. (Such as travis)
This could use the same configuration file, or even optionally a different one.
I would like to have an option to fail the build on warning. Problem with bumping all warning to error on scalastyle_config.xml is that it makes Idea IntelliJ Scala plugin display all violations as straight error red. Normally, I would like to see it as warning inside IntelliJ.
I'm sorry if that has already been solved, but my google foo didn't reveal anything and I didn't get any response on the scala IRC channel either.
I copied the description from this issue: #18 which describes exactly what I would like. I couldn't find if 'ngbinh' ever opened an issue as he said.
When I use the latest version of the plugin (0.3.1) and the latest version of sbt (0.12.3), scalastyle reports a parse error on code which uses string interpolation. You know, the one that looks like:
message=Expected token RPAREN but got Token(STRING_LITERAL,"Getting the mutex failed with ${ex.getMessage}")
It looks like sbt is downloading version 0.1.2 of scalariform. My impression was that 0.1.4 was the first version of scalariform with the fix for 2.10, allowing string interpolation.
I think sbt is downloading that version because sbt 0.12.3 is built on scala 2.9 and the scalastyle.pom has a scala-2.9 profile which says to use 0.1.2 of scalariform.
Is there reason that the 2.9 profile couldn't use the 0.1.4 version of scalariform? Would that fix the problem here?
Hi,
After adding to my project/plugins.sbt file the lines:
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.2.0-SNAPSHOT")
resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
and after adding to my build.sbt the line:
org.scalastyle.sbt.ScalastylePlugin.Settings
i get:
error sbt.ResolveException: unresolved dependency: org.scalastyle#scalastyle_2.9.2;0.2.0-SNAPSHOT: not found
Any clue what might wrong?
Thanks,
Lacramioara
No issue with scalastyle-sbt-plugin 0.4.0, but when updating to scalastyle-sbt-plugin 0.5.0 I've got the following errors.
error: value enablePlugins is not a member of sbt.Project
lazy val root = (project in file(".")).enablePlugins(PlayScala)
^
sbt.compiler.EvalException: Type error in expression
at sbt.compiler.Eval.checkError(Eval.scala:384)
at sbt.compiler.Eval.compileAndLoad(Eval.scala:183)
at sbt.compiler.Eval.evalCommon(Eval.scala:152)
at sbt.compiler.Eval.evalDefinitions(Eval.scala:122)
at sbt.EvaluateConfigurations$.evaluateDefinitions(EvaluateConfigurations.scala:254)
at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:109)
at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:710)
at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:715)
at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:714)
at scala.Option.getOrElse(Option.scala:120)
at sbt.Load$.sbt$Load$$memoLoadSettingsFile$1(Load.scala:714)
at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:721)
at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:721)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
1 // Comment to get more information during initialization
at sbt.Load$.loadFiles$1(Load.scala:721)
at sbt.Load$.discoverProjects(Load.scala:732)
at sbt.Load$.discover$1(Load.scala:545)
at sbt.Load$.loadTransitive(Load.scala:574)
at sbt.Load$.loadProjects$1(Load.scala:442)
at sbt.Load$.loadUnit(Load.scala:446)
at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:281)
at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:281)
at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:91)
at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:90)
at sbt.BuildLoader.apply(BuildLoader.scala:140)
at sbt.Load$.loadAll(Load.scala:334)
at sbt.Load$.loadURI(Load.scala:289)
at sbt.Load$.load(Load.scala:285)
at sbt.Load$.load(Load.scala:276)
at sbt.Load$.apply(Load.scala:130)
at sbt.Load$.defaultLoad(Load.scala:36)
at sbt.BuiltinCommands$.doLoadProject(Main.scala:481)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$.process(Command.scala:92)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.State$$anon$1.process(State.scala:184)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.MainLoop$.next(MainLoop.scala:98)
at sbt.MainLoop$.run(MainLoop.scala:91)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:70)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:65)
at sbt.Using.apply(Using.scala:24)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:65)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:48)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:32)
at sbt.MainLoop$.runLogged(MainLoop.scala:24)
at sbt.StandardMain$.runManaged(Main.scala:53)
at sbt.xMain.run(Main.scala:28)
at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
at xsbt.boot.Launch$.withContextLoader(Launch.scala:129)
at xsbt.boot.Launch$.run(Launch.scala:109)
at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:36)
at xsbt.boot.Launch$.launch(Launch.scala:117)
at xsbt.boot.Launch$.apply(Launch.scala:19)
at xsbt.boot.Boot$.runImpl(Boot.scala:44)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore
This happens when I'm running just activator clean
or sbt clean
. Reverting to scalastyle-sbt-plugin 0.4.0 and everything works correctly. I have tried on Playframework 2.3.4 and 2.3.5 using sbt 0.13.6 with a scala version 2.11.2.
scalastyle-sbt-plugin currently prints message in multiple lines, like this:
[info] scalastyle Processed 9 file(s)
[info] scalastyle Found 0 errors
[info] scalastyle Found 0 warnings
[info] scalastyle Found 0 infos
[info] scalastyle Finished in 0 ms
These lines will appears again and again when there were several sub-projects in this build, sometimes even more than one screen.
Do you consider fold these lines into one line is a good idea?
For example:
[info] scalastyle Processed 1 file(s). Found 2 error(s) / 3 warning(s) / 4 info(s). Finished in 5ms
If so, would you mind me create a PR for this change?
It would be nice if the plugin would work with both scala versions. Need to wait for sbt on 2.11.
http://stackoverflow.com/questions/23282469/does-sbt-builds-againts-scala-2-11
This is my configuration
<check level="error" class="org.scalastyle.scalariform.ImportOrderChecker" enabled="true">
<parameters>
<parameter name="groups">java,scala,others,mycompany</parameter>
<parameter name="group.java">javax?\..+</parameter>
<parameter name="group.scala">scala\..+</parameter>
<parameter name="group.mycompany">com.mycompany\..+</parameter>
<parameter name="group.others">.+</parameter>
</parameters>
</check>
and the following import is being flagged as invalid by scalastyle, reporting There should be no empty line separating imports in the same group.
com.rabbitmq.this
com.mycompany.that
However if I change the order to java,scala,mycompany,others
then there is no error reported.
Hello,
I am following the instructions in Scalastyle in order to add the plugin into my Scala project. I have added "addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")" into a new plugins.sbt file.
However, when I refresh my project in IntelliJ IDEA, I get the following error:
Error:Error while importing SBT project:
...
[info] Resolving org.scala-lang.modules#scala-xml_2.11;1.0.4 ...
[info] Resolving jline#jline;2.12.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scalastyle#scalastyle-sbt-plugin;0.8.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[...]
error sbt.ResolveException: unresolved dependency: org.scalastyle#scalastyle-sbt-plugin;0.8.0: not found
error sbt.ResolveException: unresolved dependency: org.scalastyle#scalastyle-sbt-plugin;0.8.0: not found
[error] Total time: 1 s, completed 12-jun-2016 14:46:45What am I doing wrong? The project is using Scala 2.11.7 and SBT 0.13.9
The final version of sbt 1.0 is already released.
the current dependencies are pulling in loads of older scala/sbt binaries that aren't being evicted by sbt for some reason :-(
Thanks for the recent 0.6.0 update! I'm now trying to run scalastyle on my test sources, which need maintenance too. I'd like a slightly different configuration for it, so I tried overriding scalastyleConfig in Test
. This works for the root project, but doesn't seem to take for sub projects. Running show test:scalastyleConfig
shows that the sub projects are using the default config.
The example is here: https://github.com/gshakhn/private-wiki/tree/test-scalastyle
Let me know if I can provide more detail.
To sync all our config files for various setups for our devs we use services that require some form of authentication.
For example:
We sometime use private github repos to get a file hosted on a "config" repo. We can get those files with
curl -u <some_oauth_token>:x-basic-oauth https://raw.githubusercontent/[user/org]/[reponame]/[branch]/[path_tyo_file]
It would be nice to have something that allows for more complex requests by setting headers. Or defining our own process.
The user guide suggests that to run scalastyle as part of another task you need to add:
lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
// scalastyle >= 0.9.0
compileScalastyle := scalastyle.in(Compile).toTask("").value
// scalastyle <= 0.8.0
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
(compile in Compile) := ((compile in Compile) dependsOn compileScalastyle).value
But note that this makes the compile task dependent on the scalastyle task - the scalastyle task executes first. This can cause problems because if the code doesn’t compile, you’ll get the scalastyle errors messages, not the scalac ones. Great though scalastyle is, it can’t match the error messages produced by the compiler. :-)
There is actually another way which doesn't loose the compiler errors:
compile := compileScalastlyeTask(Compile / compile, Compile / scalastyle).value
def compileScalastlyeTask(compileTask: TaskKey[CompileAnalysis],
scalastyleTask: InputKey[Unit]): Def.Initialize[Task[CompileAnalysis]] = Def.task {
val analysis = compileTask.value
val args: Seq[String] = Seq.empty
val scalastyleSourcesV = scalastyleSources.value
val configV = scalastyleConfig.value
val configUrlV = scalastyleConfigUrl.value
val streamsV = streams.value
val failOnErrorV = scalastyleFailOnError.value
val failOnWarningV = scalastyleFailOnWarning.value
val scalastyleTargetV = scalastyleTarget.value
val configRefreshHoursV = scalastyleConfigRefreshHours.value
val targetV = target.value
val configCacheFileV = scalastyleConfigUrlCacheFile.value
org.scalastyle.sbt.Tasks.doScalastyle(args,
configV,
configUrlV,
failOnErrorV,
failOnWarningV,
scalastyleSourcesV,
scalastyleTargetV,
streamsV,
configRefreshHoursV,
targetV,
configCacheFileV)
analysis
}
The idea here is really simple which is to first call the compile task, then the scalastlye task and finally return the result of the compile task. This is quite verbose and not future proof since it is essentially reimplementing the scalastyle
input task.
It would be far simpler if there was a normal task (not an input task) provided by the plugin.
I'm trying to extract shared plugins and settings into a common set of AutoPlugins. Here's the plugin for Scalastyle:
package com.jawshooah.sbt
import sbt._
import sbt.Keys._
import sbt.plugins.JvmPlugin
import org.scalastyle.sbt.ScalastylePlugin
import org.scalastyle.sbt.ScalastylePlugin._
object ScalastylePluginSettings extends AutoPlugin {
override def requires = JvmPlugin
override def trigger = allRequirements
/* ScalastylePlugin is not an AutoPlugin, so we manually add its settings here */
override def projectSettings =
ScalastylePlugin.projectSettings ++
baseSettings ++
Project.inConfig(Compile)(baseSettings) ++
Project.inConfig(Test)(baseSettings)
lazy val baseSettings = Seq(
(scalastyleConfig in Compile) := sbtCommonDir.value / "scalastyle-config.xml",
(scalastyleConfig in Test) := sbtCommonDir.value / "scalastyle-test-config.xml"
)
lazy val sbtCommonDir = baseDirectory { _ / "project" / "sbt-common" }
}
scalastyleConfig
appears to be set correctly in Compile
:
> inspect compile:scalastyleConfig
[info] Setting: java.io.File = /Users/joshuahagins/dev/sandbox/sbt-common-test/project/sbt-common/scalastyle-config.xml
[info] Description:
[info] Scalastyle configuration file
[info] Provided by:
[info] {file:/Users/joshuahagins/dev/sandbox/sbt-common-test/}root/compile:scalastyleConfig
[info] Defined at:
[info] (com.jawshooah.sbt.ScalastylePluginSettings) ScalastylePluginSettings.scala:22
[info] Dependencies:
[info] compile:baseDirectory
[info] Reverse dependencies:
[info] compile:scalastyleGenerateConfig
[info] compile:scalastyle
[info] Delegates:
[info] compile:scalastyleConfig
[info] *:scalastyleConfig
[info] {.}/compile:scalastyleConfig
[info] {.}/*:scalastyleConfig
[info] */compile:scalastyleConfig
[info] */*:scalastyleConfig
[info] Related:
[info] *:scalastyle::scalastyleConfig
[info] test:scalastyle::scalastyleConfig
[info] test:scalastyleConfig
[info] compile:scalastyle::scalastyleConfig
[info] *:scalastyleConfig
...but not in Test
:
> inspect test:scalastyleConfig
[info] Setting: java.io.File = scalastyle-config.xml
[info] Description:
[info] Scalastyle configuration file
[info] Provided by:
[info] {file:/Users/joshuahagins/dev/sandbox/sbt-common-test/}root/test:scalastyleConfig
[info] Defined at:
[info] (org.scalastyle.sbt.ScalastylePlugin) Plugin.scala:100
[info] Dependencies:
[info] *:scalastyle::scalastyleConfig
[info] Reverse dependencies:
[info] test:scalastyleGenerateConfig
[info] test:scalastyle
[info] Delegates:
[info] test:scalastyleConfig
[info] runtime:scalastyleConfig
[info] compile:scalastyleConfig
[info] *:scalastyleConfig
[info] {.}/test:scalastyleConfig
[info] {.}/runtime:scalastyleConfig
[info] {.}/compile:scalastyleConfig
[info] {.}/*:scalastyleConfig
[info] */test:scalastyleConfig
[info] */runtime:scalastyleConfig
[info] */compile:scalastyleConfig
[info] */*:scalastyleConfig
[info] Related:
[info] compile:scalastyleConfig
[info] *:scalastyleConfig
If I add the line:
(scalastyleConfig in scalastyle) := sbtCommonDir.value / "scalastyle-test-config.xml"
...it works. I assume this is related to the way scalastyleConfig in Test
is initially set, but this is very counterintuitive, and I'm not sure if it has any other repercussions.
How can I generate scalastyle-reports.html from scalastyle-reports.xml file to show it on web page,So that I can see the warnings.
Sorry this is more of a question. How do I modify my build file so that I can get scalastyle on run on every compile? I tried this, but it doesn't work:
compile in Compile <<= (compile in Compile) dependsOn(
org.scalastyle.sbt.Tasks.scalastyle)
It throws this:
<console>:65: error: type mismatch;
found : sbt.Project.Initialize[sbt.InputTask[Unit]]
required: sbt.Scoped.AnyInitTask
compile in Compile <<= (compile in Compile) dependsOn(Tasks.scalastyle)
I tried to get around this by casting scalastyle task to sbt.Scoped.AnyInitTask
but this fails with a CastException.
Any other ideas?
Hi,
The magic number rule, in my opinion, incorrectly flags a collection of numbers assigned to a variable, eg. val numbers = Array(5,10,20,25,30)
The intention behind the array is explicitly defined by the variable name.
Thanks,
Meghana.
I would like to exclude some folders/files from being checked, how do I do that?
The command-line version of scalastyle takes the source directory to use, but I can't figure out how to do that with scalastyle-sbt.
Trailing commas lead to very confusing errors. Trailing commas were added in SIP-27 (Scala 2.12.2). I don't actually use them intentionally but it can take a very long time to find it since scalac passes but scalastyle fails without any line information and usually on an unrelated token.
For example:
[error] MySpec.scala: illegal start of simple expression: Token(RPAREN,),295,))
import org.scalatest.FlatSpec
import org.scalatest.prop.GeneratorDrivenPropertyChecks
class MySpec extends FlatSpec with GeneratorDrivenPropertyChecks {
case class Foo(a: String, b: Int)
Foo(
"hello",
123,
)
}
I want to invoke scalastyle before the testing actually begins. I started with this
def styleCheck = streams.map(s => Tasks.doScalastyle())
(test in Test) <<= (test in Test) dependsOn styleCheck
I am not sure what to fill in for the parameters of Tasks.doScalastyle
The integration tests in our project are in the /src/it
folder and the unit tests in src/test
.
Although sbt test:scalastyle
works fine and checks all the files in src/test
, the command sbt it:scalastyle
checks the source files in src/main
.
Is there a way to configure the sbt scalastyle plugin to check the files in /src/it
folder?
I'm trying to use scrooge-sbt-plugin (3.12.3, still not released) and scalastyle-sbt-plugin (0.4.0) in same project. As soon as scalastyle-sbt-plugin is just added to plugins.sbt, build starts crashing, scrooge-sbt-plugin execution fails with:
Caused by: java.lang.ClassNotFoundException: scopt.mutable.OptionParser
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.twitter.scrooge.ScroogeSBT$.compile(ScroogeSBT.scala:24)
at com.twitter.scrooge.ScroogeSBT$$anonfun$16.apply(ScroogeSBT.scala:204)
at com.twitter.scrooge.ScroogeSBT$$anonfun$16.apply(ScroogeSBT.scala:200)
at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:35)
at scala.Function7$$anonfun$tupled$1.apply(Function7.scala:34)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[error] (bar/compile:scroogeGen) java.lang.NoClassDefFoundError: scopt/mutable/OptionParser
No releases since 2015, and at least one merged fix since then that I could use. Any idea when the next release will be?
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.