Search code examples
scalacode-formattingrulespackage-namescalariform

Scalafmt package name checker


I have found a nice rule in scalariform that checks the package names and is as follows:

<check enabled="true" class="org.scalastyle.scalariform.PackageNamesChecker" level="warning">
 <parameters>
  <parameter name="regex">^[a-z][A-Za-z]*$</parameter>
 </parameters>
</check>

However, I couldn't find the corresponding rule for scalafmt in the docs. Is there something like that?


Solution

  • As far as I know, Scalafmt is just a code formatter, meaning it won't flag stylistic errors but rather reformat your code according to the predefined rules you have set (for example, add a new line after a bracket, align case statements, etc). Its goal is only formatting code so that it looks consistent between developers.

    On the other hand, Scalastyle (with Scalariform) is defined as :

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

    So it defines "check" rules, like the one you show in your question, to warn you about the fact that your code does not respect these rules. But it won't rewrite/reformat your code accordingly to these rules. It's more like a linting tool than a code formatter. Moreover, its scope is wider, as it provides more rules than just formatting : for example, it can check if you are using null with NullChecker.

    Note that you can use both (and it's generally a good practice), as long as you are not defining contradictory rules!