How check naming convention for logger variables in scala with scalastyle?

178 Views Asked by At

Suppose I need to ensure that all loggers in my scala code are named log only, not LOGGER, LOG or logger. So for this style checking I need to define a Logger (for slf4j or log4j) and when style checker detects a variable with this type it check name.

I see org.scalastyle.scalariform.FieldNamesChecker, but do not see any type checkers, so is it possible to do that with scalastyle rules?

1

There are 1 best solutions below

0
On

Scalastyle only has access to the information in the file, so you might not have the type available.

The best solution is probably to use a Regex. Pretty much all of our loggers have the form:

private val log = LoggerFactory.getLogger(this.getClass)

so you could define a RegexChecker with an appropriate regex for your convention. You won't get all of the cases, but you'd probably get most of them.