JAVA code specification check plugin

MyCheckStyle.xml

CheckStyle-IDEA is a tool to improve code quality and check code specification, which can be used to check java code specification.

Click file ->setting to enter the idea setting page

Open the plugins of settings, click to find CheckStyle-IDEA installation, if you can't find it, Browse repositories.. search . CheckStyle  installation

Check CheckStyle and click apply in the lower right corner to make it take effect

Usage: There will be an additional checkstyle plug-in at the bottom left of the main interface of idea, click to run on the left, you can check the normative and error prompts of the code according to the configuration specification!

xml download address

Link: https://pan.baidu.com/s/1oKKvbZD2wHW1VTFP0sEa5A 
Extraction code: ou8y 

1 提示:Type is missing a javadoc commentClass

Description: Missing type description

Solution: add javadoc description

2 提示:“{” should be on the previous line

Explanation: "{" should be on the previous line.

Solution: put "{" on the previous line

3 提示:Methos is missing a javadoc comment

Explanation: A javadoc comment is missing before the method.

Workaround: Add javadoc comments

4 提示: Expected @throws tag for“Exception”

Explanation: Expect @throws' explanation in comments

Solution: Add this line to the comment before the method: * @throws Exception if has error (exception description)

5 提示:“.” Is preceeded with whitespace

Note: There cannot be a space before ".".

Solution: remove the space before the "."

6 提示:“.” Is followed by whitespace

Note: There cannot be a space after the ".".

Solution: remove the space after "."

7 提示:“=” is not preceeded with whitespace

Explanation: A space is missing before the "=".

Solution: add a space before "="

8 提示:“=” is not followed with whitespace

Explanation: Missing space after "=".

Solution: add a space after "="

9 提示:“}” should be on the same line

Explanation: "}" should be on the same line as the next statement.

Workaround: put "}" before the next line

10 提示:Unused @param tag for “unused”

Description: There is no parameter "unused", no comment is required

Solution: "* @param unusedparameter additional (parameter name)" Remove the comment of the unused parameter on this line"

11 Hint: Variable "CA" missingjavadoc

Explanation: The variable 'CA' is missing a javadoc comment

Solution: Add a javadoc comment before the "CA" variable: /** CA. */ (Note: Be sure to add the "." after CA)

12 Tip: Line longer than 80characters

Description: Line length exceeds 80.

Solution: split it into multiple lines. When necessary, you can ctrl+shift+f

13 提示:Line contains a tab character

Explanation: The line contains "tab" characters.

14 Tip: Redundant “Public” modifier

Description: Redundant "public" modifier.

Workaround: redundant "public"

15 提示:Final modifier out of order with the JSL suggestion

Description: Final modifier in wrong order

16 提示: Avoid using the “.*” formof import

Description: Avoid using ".*" in Import format

17 提示:Redundant import from the same package

Description: Import content from the same package

18 Tip: Unusedimport-java.util.list

Description: The java.util.list imported by Import is not used.

Solution: remove the imported redundant class

19 提示:Duplicate import to line 13

Description: Repeat Import of the same content

Solution: remove the imported redundant class

20 Tips: Import from illegalpackage

Description: Import content from illegal package

21 提示:“while” construct must use “{}”

Explanation: 'while' statement is missing '{}'

22 提示: Variable “sTest1” must beprivate and have accessor method

Explanation: The variable "sTest1" should be private and have a method to call it

23 提示: Variable “ABC” must matchpattern “^[a-z][a-zA-Z0-9]*$”

Explanation: The variable "ABC" does not conform to the naming convention "^[az][a-zA-Z0-9]*$"

Solution: Change the name to the regular name "aBC"

24 提示:“(” is followed by whitespace “)”is proceeded by whitespace

Description: "(" cannot have spaces after ")" and cannot have spaces before

Solution: remove the leading or trailing spaces

25 提示:First sentence should end with a period.

Solution: The first line of text in your comment should end with a ".".

26提示: Redundant throws:'NameNotFoundException' is subclass of 'NamingException'.

Description: 'NameNotFoundException' is a subclass of 'NamingException' that repeatedly throws an exception.

Solution: If two exceptions are thrown, one exception class is a subclass of the other, then only the parent class needs to be written

Remove the NameNotFoundException exception, and the corresponding javadoc comment exception comment description also needs to be removed

27 提示: Parameter docType should be final.

Description: The parameter docType should be final type

Solution: add a final in front of the parameter docType

28 提示: Line has trailing spaces.

Description: extra blank line

Solution: remove this blank line

29 提示: Must have at least onestatement.

Description: At least one declaration

Solution: The exception catch in try{}catch(){} cannot be empty, and add a sentence in the exception. such as printing

30 Hint: '>' is not followed by whitespace. And '(' is preceded with whitespace.

Note: When defining sets and enumerations, there must be a space after the last ">", and no space is allowed before "(".

Solution: remove generics (usually generics are prone to this problem)

31 提示:Got an exception - java.lang.RuntimeException: Unable to get classinformation for @throws tag 'SystemException'.

Description: Unreasonable throws.

Solution: Make sure that certain types, such as certain classes and interfaces, are not thrown. Remove the declared exception. Throwing exception in implementing class

Online reference solutions: 1. This is the error reported by CheckStyle. Usually need to Refresh, clean/build this Project. If not, you can try to clean all projects, restart Eclipse.

2. Because the compiled class is not in the classpath of checkstyle. Therefore, as long as the compiled class is configured in the classpath of <checkstyle/>, there will be no problem. In addition, I also found that the line length of checkstyle seems to be a problem. , obviously there is no more than 120 characters, but it still reports an error. Helpless, I changed the Maximumline with in java > code style > formatter in Eclipse to 100, and then formatted it, there is basically no problem.

32 提示: File does not end with anewline.

Solution: delete the class that reported the error, create a new class with the same name, and copy all the code in the past

33 提示:Utility classes should not have a public or default constructor.

Description: Inner classes in interfaces should not have public or default constructors

Solution: In the inner class, define a private constructor, and then declare the inner class as final type. If there is static in front of it, then final must also be placed after static

34 提示:Variable 'functionCode' must be private and have accessor methods

Description:. The variable should be changed to private and then provide access methods

Solution: Change the modifiers of these variables to private, then provide set and get methods, and add the corresponding method javadoc comments and parameter comments. And add final before return value and parameter type. And change the place where this variable is called to be accessed through a method

35 Tip: 'X' hides a field.

Description: The global private int X; and the X variable name of the local publicFoo(int X) are duplicated. Solution: Just change the parameter name in the method public Foo(int newBar)

36 提示: Got an exception -Unexpected character 0xfffd in identifier

Description: This is because CheckStyle does not recognize the specified encoding format.

Online reference solutions:

1. It can be configured in Eclipse and can be specified in Other-->checker

2. You can modify the checkstyle configuration file:

<modulename="Checker">

<propertyname="severity" value="warning"/>

<property name="charset"value="UTF-8"/>

<modulename="TreeWalker">

If it is UTF-8, just add the statement in bold italics and that's it.

37 提示: Got an exception -java.lang.RuntimeException: Unable to get class information for @throws tagwhatever.

Online reference solution: Select CheckSytle's JavaDoc --> Method JavaDoc --> logLoadErrors. If CheckStyle made an error when loading itself, just make a Log, don't make Errors scary. (I haven't encountered this problem, so I haven't tried it) There is another place that may contain the same error. Coding Problems --> Redundant Throws --> logLoadErrors can be selected

38 Hint: Expected @param tag for 'dataManager'.

Description: Missing comment for dataManager parameter

Workaround: add @param dataManager DataManager in annotation

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324468582&siteId=291194637