Giter Site home page Giter Site logo

scalastyle's Introduction

Scalastyle - Scala style checker

Scalastyle examines your Scala code and indicates potential problems with it.

Full documentation is currently available on the Scalastyle website

Build Status codecov.io

scalastyle's People

Contributors

ahirreddy avatar asaitov avatar axelgschaider avatar balmungsan avatar evis avatar facsimiler avatar fatlazycat avatar janm399 avatar joshrosen avatar kciesielski avatar kiritsuku avatar latkin avatar marconilanna avatar matthewfarwell avatar maximenajim avatar mjeffryes avatar namin avatar rehevkor5 avatar richardbradley avatar rigoford avatar rxin avatar scrapcodes avatar sethtisue avatar shanielh avatar shiti avatar tanishiking avatar tim-zh avatar timgreen avatar tkawachi avatar vshchukin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scalastyle's Issues

SpacesAfterPlusChecker

Does not handle

val someText = "blah ... a long line " +
" some more text"

I assume our ide strips trailing blank spaces and hence it cant find a space after the plus. But I would expect this to pass.

Matching headers with multi-byte encodings...

If you have a UTF-8 (without byte-order-mark) Scala source file (Main.scala) with the following contents:

// Copyright © 2012, Some Big Company.  All rights reserved.
object Main extends App {
  println ("Hello, world!")
}

and a Scalastyle UTF-8 encoded (also without BOM) config file with the following contents:

<?xml version="1.0" encoding="UTF-8" ?>
<scalastyle>
  <name>Header match test file</name>
  <check class="org.scalastyle.file.HeaderMatchesChecker" enabled="true" level="error">
    <parameters>
      <parameter name="header"><![CDATA[// Copyright © 2012, Some Big Company.  All rights reserved.]]></parameter>
    </parameters>
  </check>
</scalastyle>

then you get the following output when run with scalastyle (I'm running using the scalastyle-maven-plugin):

...
Starting scalastyle
start file C:\ScalaStyleTest\src\main\scala\Main.scala
error file=C:\ScalaStyleTest\src\main\scala\Main.scala message=Header does not match expected text line=1
end file C:\ScalaStyleTest\src\main\scala\Main.scala
Processed 1 file(s)
Found 1 errors
Found 0 warnings

The problem is the copyright '©' symbol, which requires two bytes to encode it in UTF-8. This can be verified by removing it from both files and re-running scalastyle:

Starting scalastyle
start file C:\ScalaStyleTest\src\main\scala\Main.scala
end file C:\ScalaStyleTest\src\main\scala\Main.scala
Processed 1 file(s)
Found 0 errors
Found 0 warnings

SimplifyBooleanExpressionChecker triggered by named boolean parameter

"Another more serious problem with SimplifyBooleanExpressionChecker:

if (boolVal && method(boolParam = true)) {
// ...
}

The expression above is reported as a problem, but it should not."


"Gosh. I hadn't seen this one.

The reason is you're using a = true. The SimplifyBooleanExpressionChecker has a bug where it ignores some of the parse tree below the infix operator that it is checking. It also sometimes skips the checks altogether. This doesn't produce an error, but should:

var b = true

if (b && {println("foobar"); b && false }) {
}

Could you raise an issue please, and I'll look at it.

Thanks.

Matthew Farwell."

ignore configuration property for MethodNamesChecker

It would be nice to have an ignore regex for the MethodNamesChecker, e.g. some symbolic methods are fairly common, like +, -, ++ or -- for collections or numeric types.

I suggest an ignore property on purpose because I know that one should avoid symbolic method names since they can be confusing. With an ignore property one can signal intent that certain symbolic method names are part of an API / DSL, like ! for actors are, but that they are NOT part of the proper way to name methods.

MethodNamesChecker: don't complain when overriding methods

MethodNamesChecker complains if one overrides methods, e.g. when implementing new collections like scala.collection.mutable.Buffer, because methods named += or +=:, which are by default not allowed.

It would be nice to be able to (have at least an option to) ignore overridden methods. This way the MethodNamesChecker wouldn't pollute the output with warnings one can't do anything about.

I guess, disabling checking overridden methods by default makes sense.

Add "ignore lines" option to HeaderMatchesChecker

Would be nice to ignore selected lines in the header. Checkstyle does this by ingesting a list of integers corresponding to the lines to ignore.

Most headers contain licenses with a dated copyright line which should be evolvable in long-running projects. Such a line should be ignored by scalastyle.

E.g.
// Copyright (C) 2011-2012 the original author or authors.

Implement EqualsHashCode

EqualsHashCode

Checks that classes that override equals() also override hashCode().
Rationale: The contract of equals() and hashCode() requires that equal objects have the same hashCode.
Hence, whenever you override equals() you must override hashCode() to ensure that your class can be used in collections that are hash based.

MagicNumberCheck issues warning for 0L

The MagicNumberChecker ignores values of 0 and 1 for Integers but raises a warning when using Long values:

val ticks = 0L // This will raise a Magic Number warning
val ticks: Long = 0 // This works fine

I'm not sure if one style is preferred over the other in Scala but I don't believe that 0L should count as a magic number in this case.

Allow custom rule ID

Currently, comment filters can turn off a rule for a particular part of a file.

A problem rises when one wants to disable a rule that can occur multiple times with different parameters.

For instance:

  1. Project has many files, including some command line tools
  2. A custom regex rule is made to check for any println statments
  3. Another custom regex rule is made to ensure a space between if and the condition
  4. Suppose the developer wants to check for the presence of println statements in files that aren't command line tools -- now the only option is to annotate // scalastyle:off regex as that is the id of the custom regex rule. However, this turns off the second regex rule as well.

It would be useful to be able to specify a custom ID for the regex rule (i.e. regex.println) in order to reference it specifically when ignoring it in certain files.

Add Scala 2.10 support

Not sure if Scalastyle currently supports 2.10. When I tried using it on a project that uses 2.10 and makes use of string interpolation, running scalastyle sbt command results in

> scalastyle error file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/api/Api.scala message=Expected token SEMI but got Token(STRING_LITERAL,"$baseApiUrl/stream/$apiVersion/posts/stream/global",2716,"$baseApiUrl/stream/$apiVersion/posts/stream/global") warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/client/AppDotNet.scala message=Header does not match expected text line=1 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/client/AppDotNet.scala message=File line length exceeds 160 characters line=35 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/client/AppDotNet.scala message=Avoid using null line=10 column=32 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Header does not match expected text line=1 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=12 column=16 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=13 column=16 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=14 column=16 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=15 column=16 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=19 column=12 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=25 column=4 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=26 column=4 warning file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/Main.scala message=Regular expression matched 'println' line=27 column=6 error file=/Users/levinotik/Dev/scala/projects/adn4s/src/main/scala/model/Models.scala message=Expected token RPAREN but got Token(STRING_LITERAL," userName: $userName, id: $id, description: $description",6688," userName: $userName, id: $id, description: $description") Processed 4 file(s) Found 2 errors Found 12 warnings Finished in 3 ms

HeaderMatchesChecker appends blank line to expected header

I've noticed an issue with the HeaderMatchesChecker in which it appears to append a blank line to the defined header. Then, if there is not a blank line following the header in a file, it will fail - and the line number provided is one higher than the number of lines in the defined header.

(There's also a stack trace, so it seems that more than just a test has failed. Is that normal?)

If there is a blank line, then the header matches just fine.

I was hoping to attach a zip file with a sample, but GitHub doesn't allow that, alas. :-( So you'll have to follow the longer-winded version below:

To reproduce, create a simple SBT project with the following files and their contents:

./build.sbt

org.scalastyle.sbt.ScalastylePlugin.Settings

./scalastyle-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<scalastyle>
 <name>Some test Scalastyle config</name>
  <check class="org.scalastyle.file.HeaderMatchesChecker" enabled="true"
  level="error">
    <parameters>
      <parameter name="header"><![CDATA[/*
This is some standard boilerplate that our boring lawyers force us to add to
every file whether we like it or not. Unfortunately, Scalastyle doesn't seem to
treat the header "as is" and appends a blank line to it, so that it fails the
header check. Any ideas?]]>
      </parameter>
    </parameters>
  </check>
</scalastyle>

./project/build.properties

sbt.version=0.13.1

./project/plugins.sbt

addSbtPlugin ("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.4.0")

./src/main/scala/Test.scala

/*
This is some standard boilerplate that our boring lawyers force us to add to
every file whether we like it or not. Unfortunately, Scalastyle doesn't seem to
treat the header "as is" and appends a blank line to it, so that it fails the
header check. Any ideas?
OK. This is NOT part of the boilerplate. If there was a blank line in front of
this line, then the above would pass the header check OK. But without that
blank line, it fails. This is a problem, because there is no blank line in the
definition of the header.
*/

object Test
extends App {
  println ("Hello, world!")
}

Having done all that, if you now run:

sbt scalastyle

you should see something like this:

[info] Loading project definition from C:\Users\SomeDumbUser\Documents\src\bug\ScalastyleHeaderIssue\project
[info] Set current project to scalastyleheaderissue (in build file:/C:/Users/SomeDumbUser/Documents/src/bug/ScalastyleHeaderIssue/)
error file=C:\Users\SomeDumbUser\Documents\src\bug\ScalastyleHeaderIssue\src\main\scala\Test.scala message=Header does not match expected text line=6
Processed 1 file(s)
Found 1 errors
Found 0 warnings
Found 0 infos
Finished in 11 ms
[success] created: sbt.SettingKey$$anon$4@51a188f0
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:744)
[error] (*:scalastyle) exists error
[error] Total time: 0 s, completed Feb 13, 2014 4:21:26 AM

Note that the checker reports that the header does not match at line 6 - even though there are only 5 lines in the header. If you edit the source file and put a blank line in between the header than the rest of the initial comment, then the header check passes OK.

I'll try to have a look into this when I get a moment, and maybe see if I can create a pull request for you. However, I'd appreciate it if you could have a quick look to see if there's anything obviously wrong with the header parser.

Thanks!

Mike

Scala 2.10 format strings?

I noticed that in files that have Scala 2.10 format strings, I get scalastyle errors like this:

message=Expected token SEMI but got Token(STRING_LITERAL,"""abc $someValue""", 318, """abc $someValue""")

The message doesn't give an apparent line number, and it pops up for both single and triple quoted format strings.

Any ideas what's going on?

scalastyle in global sbt?

Sorry if this is already addressed somewhere. Can you configure scalastyle in your global config in ~/.sbt? If so, can the instructions be updated? Currently they only tell you how to set it up for a specific project.

Error when checking empty file

Scalastyle is unable to check files that are completely empty:

[INFO] --- scalastyle-maven-plugin:0.3.1:check (default-cli) @ org.scala-ide.build ---
error file=/home/antoras/dev/Scala/scala-ide/org.scala-ide.sdt.core.tests/test-workspace/javamapper/src/pack/Target.scala message=String index out of range: -1

MethodNamesChecker warns at "def foo_=" mutators

Is there a reason, why the default does not include an optional suffix for the "_=" mutators, e.g. the following yields a warning:

class Foo {
  def foo: Int
  def foo_=(foo: Int) { } 
}

I'd assumed the default would be something like: "^[a-z][A-Za-z0-9]*(_=)?$".

Cyclomatic complexity not correct

Hi,

I noted that some function would be spotted as having a too high cyclomatic complexity if local functions are used. Putting the local functions outside (as non local) solves the issue. In my opinion, this is erroneous. Locally defined functions should not be counted in cyclomatic complexity of the enclosing function.

Pierre-Yves

Magic Number

I can see it's only partially implemented but how would currently comply ?

I'd expect

object Something {
val someVal = 50
}

to pass

Enhance HeaderMatchesChecker with regular expression check

Allow regular expressions in the HeaderMatchesChecker.

This is one issue which groups the following:
#77: Add "ignore lines" option to HeaderMatchesChecker
#20: regex support in HeaderMatchesChecker
#5: scalastyle/scalastyle-maven-plugin#5 Enhance HeaderMatchesChecker with regular expression check

I think this is a good idea. I think adding an option to say whether the header specification is a regexp or not would be the way to go. It should also be able to cope with ignoring lines.

Not compatible with scopt_2.10_3.2.0

Hi,
In my current project we are using scopt's latest version of 2.10_3.2.0 for CLI.
However, when trying to use scalastyle alongwith it, the scalastyle is unable to load scopt.immutable.OptionParser and the build fails.

Considering that the scopt version used in scalastyle, (scopt_2.10_2.1.0) is almost 2 years old, is there a thought towards upgrading it to scopt_2.10_3.2.0?

It'll be really helpful if you could look into it.

Thanks,
Vivek

mvn:exec failing

I just checkout out the repository, and tried to run it with
mvn:exec java

fails, with the output as below

Apache Maven 3.0.4 (rNON-CANONICAL_2012-01-24_13-02_root; 2012-01-24 13:02:02+0000)
Maven home: /opt/maven
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.3.1-1-arch", arch: "amd64", family: "unix"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /opt/maven/conf/settings.xml
[DEBUG] Reading user settings from /home/andrea/.m2/settings.xml
[DEBUG] Using local repository at /home/andrea/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /home/andrea/.m2/repository
[INFO] Scanning for projects...
[DEBUG] Extension realms for project org.scalastyle:scalastyle_2.9.1:jar:0.1.0-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging jar from ClassRealm[plexus.core, parent: null]
[DEBUG] Resolving plugin prefix exec from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Resolved plugin prefix exec to org.codehaus.mojo:exec-maven-plugin from POM org.scalastyle:scalastyle_2.9.1:jar:0.1.0-SNAPSHOT
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: org.scalastyle:scalastyle_2.9.1:jar:0.1.0-SNAPSHOT
[DEBUG] Tasks: [exec:java]
[DEBUG] Style: Regular
[DEBUG] =======================================================================
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Scalastyle style checker for Scala 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[DEBUG] Resolving plugin prefix exec from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Resolved plugin prefix exec to org.codehaus.mojo:exec-maven-plugin from POM org.scalastyle:scalastyle_2.9.1:jar:0.1.0-SNAPSHOT
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] === PROJECT BUILD PLAN ================================================
[DEBUG] Project: org.scalastyle:scalastyle_2.9.1:0.1.0-SNAPSHOT
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): [test]
[DEBUG] Repositories (dependencies): [scala-tools-snapshots (http://scala-tools.org/repo-snapshots/, snapshots), repo1 (http://repo1.maven.org/maven2, snapshots), java.net (http://download.java.net/maven/2/, releases+snapshots), scala-tools (http://scala-tools.org/repo-releases/, releases), central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] Repositories (plugins) : [central (http://repo.maven.apache.org/maven2, releases)]
[DEBUG] --- init fork of org.scalastyle:scalastyle_2.9.1:0.1.0-SNAPSHOT for org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) ---
[DEBUG] Dependencies (collect): []
[DEBUG] Dependencies (resolve): []
[DEBUG] --- exit fork of org.scalastyle:scalastyle_2.9.1:0.1.0-SNAPSHOT for org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) ---
[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal: org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli)
[DEBUG] Style: Regular
[DEBUG] Configuration:


--config
lib/scalastyle_config.xml
src/main/scala
src/test/scala${exec.arguments}
${exec.classpathScope}
${exec.cleanupDaemonThreads} default-value=
${exec.args}
${exec.daemonThreadJoinTimeout}
${exec.includePluginDependencies}
${exec.includeProjectDependencies}
${exec.keepAlive}
${exec.killAfter}

org.scalastyle.Main



${skip}
${sourceRoot}
${exec.stopUnresponsiveDaemonThreads} default-value=
${testSourceRoot}

[DEBUG] =======================================================================
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ scalastyle_2.9.1 >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ scalastyle_2.9.1 <<<
[DEBUG] org.scalastyle:scalastyle_2.9.1:jar:0.1.0-SNAPSHOT
[DEBUG] org.scalariform:scalariform_2.9.1:jar:0.1.1:compile
[DEBUG] org.scala-lang:scala-library:jar:2.9.1:compile
[DEBUG] org.scalatest:scalatest_2.9.1:jar:1.6.1:test
[DEBUG] junit:junit:jar:4.10:test
[DEBUG] org.hamcrest:hamcrest-core:jar:1.1:test
[DEBUG] com.github.scopt:scopt_2.9.1:jar:2.0.0:compile
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ scalastyle_2.9.1 ---
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG] Imported: org.apache.maven.wagon.events < plexus.core
[DEBUG] Imported: org.sonatype.aether.transfer < plexus.core
[DEBUG] Imported: org.apache.maven.exception < plexus.core
[DEBUG] Imported: org.sonatype.aether.metadata < plexus.core
[DEBUG] Imported: org.codehaus.plexus.util.xml.Xpp3Dom < plexus.core
[DEBUG] Imported: org.sonatype.aether.collection < plexus.core
[DEBUG] Imported: org.sonatype.aether.version < plexus.core
[DEBUG] Imported: org.apache.maven.monitor < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.repository < plexus.core
[DEBUG] Imported: org.apache.maven.repository < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.resource < plexus.core
[DEBUG] Imported: org.codehaus.plexus.logging < plexus.core
[DEBUG] Imported: org.apache.maven.profiles < plexus.core
[DEBUG] Imported: org.sonatype.aether.repository < plexus.core
[DEBUG] Imported: org.apache.maven.classrealm < plexus.core
[DEBUG] Imported: org.apache.maven.execution < plexus.core
[DEBUG] Imported: org.sonatype.aether.artifact < plexus.core
[DEBUG] Imported: org.sonatype.aether.spi < plexus.core
[DEBUG] Imported: org.apache.maven.reporting < plexus.core
[DEBUG] Imported: org.apache.maven.usability < plexus.core
[DEBUG] Imported: org.codehaus.plexus.container < plexus.core
[DEBUG] Imported: org.codehaus.plexus.component < plexus.core
[DEBUG] Imported: org.codehaus.plexus.util.xml.pull.XmlSerializer < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.authentication < plexus.core
[DEBUG] Imported: org.apache.maven.lifecycle < plexus.core
[DEBUG] Imported: org.codehaus.plexus.classworlds < plexus.core
[DEBUG] Imported: org.sonatype.aether.graph < plexus.core
[DEBUG] Imported: org.sonatype.aether.* < plexus.core
[DEBUG] Imported: org.apache.maven.settings < plexus.core
[DEBUG] Imported: org.codehaus.classworlds < plexus.core
[DEBUG] Imported: org.sonatype.aether.impl < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.* < plexus.core
[DEBUG] Imported: org.apache.maven.toolchain < plexus.core
[DEBUG] Imported: org.sonatype.aether.deployment < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.observers < plexus.core
[DEBUG] Imported: org.codehaus.plexus.util.xml.pull.XmlPullParserException < plexus.core
[DEBUG] Imported: org.codehaus.plexus.util.xml.pull.XmlPullParser < plexus.core
[DEBUG] Imported: org.apache.maven.configuration < plexus.core
[DEBUG] Imported: org.apache.maven.cli < plexus.core
[DEBUG] Imported: org.sonatype.aether.installation < plexus.core
[DEBUG] Imported: org.codehaus.plexus.context < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.authorization < plexus.core
[DEBUG] Imported: org.apache.maven.project < plexus.core
[DEBUG] Imported: org.apache.maven.rtinfo < plexus.core
[DEBUG] Imported: org.codehaus.plexus.lifecycle < plexus.core
[DEBUG] Imported: org.codehaus.plexus.configuration < plexus.core
[DEBUG] Imported: org.apache.maven.artifact < plexus.core
[DEBUG] Imported: org.apache.maven.model < plexus.core
[DEBUG] Imported: org.apache.maven.* < plexus.core
[DEBUG] Imported: org.apache.maven.wagon.proxy < plexus.core
[DEBUG] Imported: org.sonatype.aether.resolution < plexus.core
[DEBUG] Imported: org.apache.maven.plugin < plexus.core
[DEBUG] Imported: org.codehaus.plexus.* < plexus.core
[DEBUG] Imported: org.codehaus.plexus.personality < plexus.core
[DEBUG] Populating class realm maven.api
[DEBUG] org.codehaus.mojo:exec-maven-plugin:jar:1.2.1:
[DEBUG] org.apache.maven:maven-toolchain:jar:1.0:compile
[DEBUG] org.apache.maven:maven-project:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-settings:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-profile:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-plugin-registry:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-model:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-artifact:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-core:jar:2.0.6:compile
[DEBUG] org.apache.maven:maven-plugin-parameter-documenter:jar:2.0.6:compile
[DEBUG] org.apache.maven.reporting:maven-reporting-api:jar:2.0.6:compile
[DEBUG] org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7:compile
[DEBUG] org.apache.maven:maven-error-diagnostics:jar:2.0.6:compile
[DEBUG] commons-cli:commons-cli:jar:1.0:compile
[DEBUG] org.apache.maven:maven-plugin-descriptor:jar:2.0.6:compile
[DEBUG] org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile
[DEBUG] org.apache.maven:maven-monitor:jar:2.0.6:compile
[DEBUG] classworlds:classworlds:jar:1.1:compile
[DEBUG] org.apache.maven:maven-plugin-api:jar:2.0.6:compile
[DEBUG] org.codehaus.plexus:plexus-utils:jar:2.0.5:compile
[DEBUG] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9:compile
[DEBUG] junit:junit:jar:3.8.2:test (scope managed from compile) (version managed from 3.8.1)
[DEBUG] org.apache.commons:commons-exec:jar:1.1:compile
[DEBUG] Created new class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1
[DEBUG] Importing foreign packages into class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1
[DEBUG] Imported: < maven.api
[DEBUG] Populating class realm plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1
[DEBUG] Included: org.codehaus.mojo:exec-maven-plugin:jar:1.2.1
[DEBUG] Included: org.apache.maven.reporting:maven-reporting-api:jar:2.0.6
[DEBUG] Included: org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7
[DEBUG] Included: commons-cli:commons-cli:jar:1.0
[DEBUG] Included: org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4
[DEBUG] Included: org.codehaus.plexus:plexus-utils:jar:2.0.5
[DEBUG] Included: org.apache.commons:commons-exec:jar:1.1
[DEBUG] Excluded: org.apache.maven:maven-toolchain:jar:1.0
[DEBUG] Excluded: org.apache.maven:maven-project:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-settings:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-profile:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-plugin-registry:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-model:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-core:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-plugin-parameter-documenter:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-error-diagnostics:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-plugin-descriptor:jar:2.0.6
[DEBUG] Excluded: org.apache.maven:maven-monitor:jar:2.0.6
[DEBUG] Excluded: classworlds:classworlds:jar:1.1
[DEBUG] Excluded: org.apache.maven:maven-plugin-api:jar:2.0.6
[DEBUG] Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9
[DEBUG] Excluded: junit:junit:jar:3.8.2
[DEBUG] Configuring mojo org.codehaus.mojo:exec-maven-plugin:1.2.1:java from plugin realm ClassRealm[plugin>org.codehaus.mojo:exec-maven-plugin:1.2.1, parent: sun.misc.Launcher$AppClassLoader@5acac268]
[DEBUG] Configuring mojo 'org.codehaus.mojo:exec-maven-plugin:1.2.1:java' with basic configurator -->
DEBUG arguments = [--config, lib/scalastyle_config.xml, src/main/scala, src/test/scala]
DEBUG classpathScope = runtime
DEBUG cleanupDaemonThreads = false
DEBUG daemonThreadJoinTimeout = 15000
DEBUG includePluginDependencies = false
DEBUG includeProjectDependencies = true
DEBUG keepAlive = false
DEBUG killAfter = -1
DEBUG localRepository = id: local
url: file:///home/andrea/.m2/repository/
layout: none

DEBUG mainClass = org.scalastyle.Main
DEBUG pluginDependencies = [org.codehaus.mojo:exec-maven-plugin:maven-plugin:1.2.1:, org.apache.maven.reporting:maven-reporting-api:jar:2.0.6:compile, org.apache.maven.doxia:doxia-sink-api:jar:1.0-alpha-7:compile, commons-cli:commons-cli:jar:1.0:compile, org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.5:compile, org.apache.commons:commons-exec:jar:1.1:compile]
DEBUG project = MavenProject: org.scalastyle:scalastyle_2.9.1:0.1.0-SNAPSHOT @ /home/andrea/scalastyle/pom.xml
DEBUG remoteRepositories = [ id: scala-tools-snapshots
url: http://scala-tools.org/repo-snapshots/
layout: default
snapshots: [enabled => true, update => never]
releases: [enabled => false, update => always]
, id: repo1
url: http://repo1.maven.org/maven2
layout: default
snapshots: [enabled => true, update => never]
releases: [enabled => false, update => always]
, id: java.net
url: http://download.java.net/maven/2/
layout: default
snapshots: [enabled => true, update => daily]
releases: [enabled => true, update => daily]
, id: scala-tools
url: http://scala-tools.org/repo-releases/
layout: default
snapshots: [enabled => false, update => daily]
releases: [enabled => true, update => daily]
, id: central
url: http://repo.maven.apache.org/maven2
layout: default
snapshots: [enabled => false, update => daily]
releases: [enabled => true, update => daily]
]
DEBUG skip = false
DEBUG stopUnresponsiveDaemonThreads = false
[DEBUG] -- end configuration --
[DEBUG] Invoking : org.scalastyle.Main.main(--config, lib/scalastyle_config.xml, src/main/scala, src/test/scala)
[DEBUG] Plugin Dependencies will be excluded.
[DEBUG] Project Dependencies will be included.
[DEBUG] Collected project artifacts [org.scalariform:scalariform_2.9.1:jar:0.1.1:compile, org.scala-lang:scala-library:jar:2.9.1:compile, com.github.scopt:scopt_2.9.1:jar:2.0.0:compile]
[DEBUG] Collected project classpath [/home/andrea/scalastyle/target/classes]
[DEBUG] Adding to classpath : file:/home/andrea/scalastyle/target/classes/
[DEBUG] Adding project dependency artifact: scalariform_2.9.1 to classpath
[DEBUG] Adding project dependency artifact: scala-library to classpath
[DEBUG] Adding project dependency artifact: scopt_2.9.1 to classpath
[DEBUG] joining on thread Thread[org.scalastyle.Main.main(),5,org.scalastyle.Main]
[WARNING]
java.lang.ClassNotFoundException: org.scalastyle.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:679)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.545s
[INFO] Finished at: Wed Apr 18 08:52:23 BST 2012
[INFO] Final Memory: 3M/57M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project scalastyle_2.9.1: An exception occured while executing the Java class. org.scalastyle.Main -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project scalastyle_2.9.1: An exception occured while executing the Java class. org.scalastyle.Main
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. org.scalastyle.Main
at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:352)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.ClassNotFoundException: org.scalastyle.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:679)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Null check

Possibly allow the use of null within an assert ?

Stopping checks via comments - single line

The use of a single comment after the fact can be cleaner in some situations.

such as

class(something: String) {
assert(something!= null) // scalastyle:singlelineoff null - we also then put a reason why we have turned it off
}

"implement equals and hashCode together" does not detect val hashCode

I sometimes implement hashCodes of immutable classes as vals or lazy vals (especially when the classes represent DAG nodes: this avoid costly hashCode recomputations). Unfortunately, I get the "implement equals and hashCode together" when I do so when equals is also implemented…

Output the actual number from some checks

For some checks it would be useful to get the actual computed number in the output text, not just a message that it exceeds the set limit.

One could then quickly see from the output, which parts have the highest cyclomatic complexity, which methods are the longest, what the value of a "magic number" is, etc.

General questions

Do you have a forum at all ? Or just happy to have issues raised ?

Will be looking to add a few basic rules probably specific to our build. As a start.

  1. to check the name of test classes, if it has the postfix 'Test' then needs to be 'UnitTest', 'AcceptanceTest' etc etc
  2. if a test class then make sure a JUnitRunner is attached. we use ScalaTest but to get them working within Surefire we use junit.

Now i could imagine these could be done with some bespoke regex ?? Or perhaps they would be so custom you would only want them external etc.

Is there any support for loading custom rules off the classpath etc ?

Thanks

Mandatory type for public methods should not apply to overriden methods

I just applied Scalastyle to my project, and it complains everywhere about public methods with implied types. Although I understand why this rule should be enforced, I believe that it is somewhat redundant on overriden methods (or methods that implement abstract ones).

Could this rule be refined to take this into account?

As a side note, I am not sure that this rule should apply to Unit methods either.

Add support for external rules

Certain rules are very specific to a project. A standard way should be added to allow a user to specify a jar which would contain:

scalastyle_definition.xml
The checker classes.

Then, within the scalastyle configuration, you'd allow the user to specify these classes. This would require a dynamic classloader of course.

"Whitespace after plus" should not apply to method definitions.

class Foo {
  def +(bar: Foo): Foo = { … }
}

raises a warning, although it is the standard applied convention AFAIK (at least, auto-indentation in Scala IDE deletes any whitespace between + and (.

BTW, why is this rule not applied to other standard operators such as -, *, or :: ?

Implement comment filters

We should be able to stop scalastyle emitting warnings/errors with appropriate comments, say

// scalastyle:on

// scalastyle:off

We should also be able to specify particular rules to switch on and off, such as:

// scalastyle:off magic.number

Breaking the build

Possible the wrong place for this :) but unsure where to put this.

Does the process emit a return code upon error/warning from processing ?

To make use of this we'd need to break our build and stop checkin.

Thanks

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.