Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package names should comply with a naming convention (squid:S00120) and underscore

Tags:

java

sonarlint

SonarLint produces an error:

Package names should comply with a naming convention (squid:S00120) ... With the default regular expression ^[a-z]+(\.[a-z][a-z0-9]*)*$.

However the JLS allows and even recommends using the underscore. Clause 6.1. Declarations says, i.a.,

If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.

Can I change the regular expression or must it be fixed in the product?

like image 532
Jonathan Rosenne Avatar asked Dec 17 '17 19:12

Jonathan Rosenne


People also ask

What are naming conventions for a package?

Naming Conventions Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .

Is underscore allowed in package name?

Package names are all lowercase, with consecutive words simply concatenated together (no underscores).

Can we use underscore in package name in Java?

In Java you can use underscore ( _ ) in your package names and it conforms to Java naming conventions.

How do you name a python package?

How to name a Package in python? Only use lower case while naming a Package in Python. Use an underscore as a separator to join multiple words when needed and produce a logical name. However, keeping a short name (preferably one word long) is what PEP 8 prefer.

Do package names have to comply with the s00120 naming convention?

Earlier it had not, which has been discussed here Package names should comply with a naming convention (squid:S00120) and underscore.

Is it possible to add underscore to a package name?

Note that the current default expression now allows underscores. Earlier it had not, which has been discussed here Package names should comply with a naming convention (squid:S00120) and underscore.

What are the package naming conventions in conda?

To facilitate communication and documentation, conda observes the package naming conventions listed below. The name of a package, without any reference to a particular version. Conda package names are normalized and they may contain only lowercase alpha characters, numeric digits, underscores, hyphens, or dots.

How do I fix the sq warning in package names?

This rule states that the name of the package should conform to a regular expression, which does not allow capital letters. To fix the SQ warning, you should correct your package name to com.sample.loading.routebuilder or com.sample.loading.route_builder.


Video Answer


1 Answers

Consider using a SonarQube server. You can connect your SonarLint plugin to the server and manipulate the way SL performs SCA in your IDE.

One of the nicer features of SQ is the ability to disable SCA rules and remove them from all future scan. Using this feature, you can disable the package name rule (which I also find annoying),a and not have it clutter up the editing view.

Another option is to create a new rule, which will enforce a new regular expression convention on the package names - for example, allowing package names to be Camel Case.

Finally, as stated by Jonathan Rosenne in a comment to the question, the package name issue SONARJAVA-2596 which Jonathan had opened following this question has been fixed, as can be seen here.

Reference:

  • How to disable a rule in SonarQube
  • Writing Custom Java Rules 101
like image 88
Rann Lifshitz Avatar answered Sep 23 '22 04:09

Rann Lifshitz