Is it possible to have my custom rule run by scalastyle ?

261 views
Skip to first unread message

Prashant Sharma

unread,
Feb 26, 2014, 1:01:08 AM2/26/14
to scalasty...@googlegroups.com
Hi all,

Scala-style config xml file seems to refer to FQN of classes of various checks, but I have tried to fill incorrect names(some junk) and there is no error reported. Apart from that my actual goal is to be able to write our own custom rule in our codebase and run by scalastyle somehow. Any help would be great. 


Thanks
--Prashant

Matthew Farwell

unread,
Feb 27, 2014, 6:20:59 PM2/27/14
to scalasty...@googlegroups.com
Hello,

I have some good news and some bad news. The good news is that it is relatively easy to get your rule to be run. The bad news is the message that is printed isn't very friendly.

Using sbt, you can get the rule to be run by including it on the classpath of the build - the easiest way is to build it separately and either include the jar into project/lib or as a dependency in project/plugins.sbt. Then, including the class name in the scalastyle config will get the rule executed correctly. The reason you never got any error messages out is because it just ignores them for the minute.

However, the message that is produced will be incorrect:

[info] error file=blah.scala message=space.after.comment.message line=7 column=19

Scalastyle uses a lookup into a properties file for the message that is written. Currently it uses a ResourceBundle, and is restricted to a single file, so you can't add this into the jar that you're adding to project/lib. To fix this will require a change to the core library, probably to use typesafe config library instead of a resource bundle. This is on my list of things to do, but will get done quicker if you submit a PR.

BTW, if you want to just contribute the checker to the core, I'd accept it as well.

Thanks.

Matthew Farwell.



--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Scalastyle users.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse scalastyle-use...@googlegroups.com.
Pour envoyer un message à ce groupe, adressez un e-mail à scalasty...@googlegroups.com.
Visitez ce groupe à l'adresse http://groups.google.com/group/scalastyle-users .
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .

Prashant Sharma

unread,
Mar 13, 2014, 5:21:19 AM3/13/14
to scalasty...@googlegroups.com
Thanks Mathew, all of that helped a lot. I can already see there is a PR for typesafe config fix. Haven't had the time to try it out. I was afraid about having multiple typesafe config on the classpath though. 

Apart from that there is a minor correction to the space style, would be good if you can take quick look. Let me know if there is any thing else we can do to speed things up. 

Prashant Sharma


--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "Scalastyle users".
Pour vous désabonner de ce sujet, consultez la page https://groups.google.com/d/topic/scalastyle-users/w1_YozsnRKE/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse scalastyle-use...@googlegroups.com.
Pour publier un message dans ce groupe, envoyez un e-mail à l'adresse scalasty...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/groups/opt_out.

Prashant Sharma

unread,
Mar 31, 2014, 12:14:12 AM3/31/14
to scalasty...@googlegroups.com
There is one other thing, often publishing a special artifact can be a pain and one might want to have scala styles defined in the project itself. So to have this something similar to what is done in Apache Spark project can be done where we have defined scala styles as plugin project and are thus available on the classpath for scala style sbt plugin. This sound like very obvious thing to do now, but still this wasn't the first thing that came to my mind. So it might help someone trying the same.  




Prashant Sharma
Reply all
Reply to author
Forward
0 new messages