sonar規則之壞味道型別
阿新 • • 發佈:2019-01-07
1、Abbreviation As Word In Name (預設 關閉)
壞味道 主要
檢查驗證識別符號名稱中的縮寫(連續大寫字母)長度,還允許執行駱駝案例命名
allowedAbbreviationLength 3
6、Annotation Location (預設 關閉)
壞味道 主要
註釋位置
allowSamelineSingleParameterlessAnnotation
To allow single parameterless annotation to be located on the same line as target element.
預設值true
allowSamelineParameterizedAnnotation
To allow parameterized annotation to be located on the same line as target element.
預設值false
allowSamelineMultipleAnnotations
To allow annotation to be located on the same line as target element.
預設值false
tokens
tokens to check
預設值CLASS_DEF,INTERFACE_DEF,ENUM_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF
7、Annotation Use Style (預設 關閉)
壞味道 主要
trailingArrayComma
Defines the policy for trailing comma in arrays. Default is never.
closingParens
Defines the policy for ending parenthesis. Default is never.
elementStyle
Defines the annotation element styles. Default value is compact_no_array.
8、Artifact ids should follow a naming convention (預設 關閉)
壞味道 次要
共享命名約定允許團隊有效協作。 當pom的artifactId與提供的正則表示式不匹配時,此規則引發了一個問題
regex The regular expression the "artifactId" should match
預設值[a-z][a-z-0-9]+
9、At-clause Order (預設 關閉)
壞味道 主要
檢查從句順序
tagOrder
allows to specify the order by tags.
預設值
@author,@version,@param,@return,@throws,@exception,@see,@since,@serial,@serialField,@serialData,@deprecated target allows to specify targets to check at-clauses.
10、Avoid Escaped Unicode Characters (預設 關閉)
壞味道 主要
避免轉義的Unicode字元
allowIfAllCharactersEscaped
Allow if all characters in literal are escaped.
預設值false
allowNonPrintableEscapes
Allow non-printable escapes.
預設值false
allowByTailComment
Allow use escapes if trail comment is present.
預設值false
allowEscapesForControlCharacters
Allow use escapes for non-printable(control) characters.
預設值false
11、Avoid Nested Blocks (預設 關閉)
壞味道 主要
避免巢狀塊
allowInSwitchCase
Allow nested blocks in case statements. Default is false.
12、Avoid Star Import (預設 關閉)
壞味道 次要
檢查發現使用*符號的匯入語句
excludes packages where star imports are allowed. Note that this property is not recursive, subpackages of excluded packages are not automatically excluded.
allowStaticMemberImports
whether to allow starred static member imports like <code>import static org.junit.Assert.*;</code>. Default is false.
預設值false
allowClassImports whether to allow starred class imports like <code>import java.util.*;</code>. Default is false.
預設值false
13、Boolean Expression Complexity (預設 關閉)
壞味道 主要
將巢狀布林運算子(&&,||和^)限制為指定的深度(預設= 3)。
max the maximum allowed number of boolean operations in one expression. Default is 3.
預設值3
tokens tokens to check. Default is LAND,BAND,LOR,BOR,BXOR.
預設值LAND,BAND,LOR,BOR,BXOR
14、Branches should have sufficient coverage by tests (預設 關閉)
壞味道 主要
分支應有足夠的測試覆蓋
minimumBranchCoverageRatio
預設值65
15、Catch Parameter Name (預設 關閉)
壞味道 主要
檢查catch引數名是否符合format屬性指定的格式
format Specifies valid identifiers. Default is ^(e|t|ex|[a-z][a-z][a-zA-Z]+)$
預設值^(e|t|ex|[a-z][a-z][a-zA-Z]+)$
16、Class Data Abstraction Coupling (預設 關閉)
壞味道 主要
度量衡量給定類中其他類的例項化數。
max the maximum threshold allowed. Default is 7.
excludedClasses User-configured class names to ignore.
excludeClassesRegexps User-configured regular expressions to ignore classes
excludedPackages User-configured packages to ignore
17、Class Fan Out Complexity (預設 關閉)
壞味道 主要
類的依賴類數量
max the maximum threshold allowed. Default is 20.
excludedClasses
User-configured class names to ignore
excludeClassesRegexps
User-configured regular expressions to ignore classes
excludedPackages
User-configured packages to ignore
18、Class names should comply with a naming convention (開放)
壞味道 次要
類名應符合命名約定
format Regular expression used to check the class names against.
預設值^[A-Z][a-zA-Z0-9]*$
19、Classes from "sun.*" packages should not be used (開放)
壞味道 主要
不得使用“sun.*”軟體包的類,sun類*或com.sun *包被視為實現細節,不屬於Java API
Exclude Comma separated list of Sun packages to be ignored by this rule. Example: com.sun.jna,sun.misc
20、Classes should not be coupled to too many other classes (Single Responsibility Principle) (預設 關閉)
壞味道 主要
類不應與太多其他類(單一責任原則)相耦合(依賴)
max Maximum number of classes a single class is allowed to depend upon
預設值20
21、Classes should not be too complex (預設 關閉)
壞味道 嚴重 廢棄
類不應太複雜
max Maximum complexity allowed.
預設值200
22、Classes should not have too many "static" imports (預設 關閉)
壞味道 主要
靜態匯入類允許您使用其公共靜態成員,而不必使用類名。 這可以很方便,但如果靜態匯入太多的類,你的程式碼可能會變得混亂,很難維護
threshold The maximum number of static imports allowed
預設值4
23、Classes should not have too many fields (預設 關閉)
壞味道 主要
類不應有太多欄位
countNonpublicFields
Whether or not to include non-public fields in the count
預設值true
maximumFieldThreshold
The maximum number of fields
預設值20
24、Classes should not have too many methods (預設 關閉)
壞味道 主要
類不應該有太多方法
countNonpublicMethods
Whether or not to include non-public methods in the count.
預設值true
maximumMethodThreshold
The maximum number of methods authorized in a class.
預設值35
25、Close curly brace and the next "else", "catch" and "finally" keywords should be located on the same line (預設 關閉)
壞味道 次要
關閉大括號,下一個“else”,“catch”和“finally”關鍵字應位於同一行
26、Close curly brace and the next "else", "catch" and "finally" keywords should be on two different lines (預設 關閉)
壞味道 次要
關閉大括號和下一個“else”,“catch”和“finally”關鍵字應該在兩個不同的行
29、Comments should not be located at the end of lines of code (預設 關閉)
壞味道 次要
註釋不應位於程式碼行的末尾
legalTrailingCommentPattern
Description Pattern for text of trailing comments that are allowed. By default, comments containing only one word.
預設值^\s*+[^\s]++$
30、Constant Name (預設 關閉)
壞味道 次要
檢查常數名稱是否符合指定的格式
applyToPackage
Controls whether to apply the check to package-private member
預設值true
format Regular expression
預設值^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
applyToPublic
Controls whether to apply the check to public member
預設值true
applyToProtected
Controls whether to apply the check to protected member
預設值true
applyToPrivate Controls whether to apply the check to private member
預設值true
31、Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply (預設 關閉)
壞味道 嚴重
控制流程語句“if”,“for”,“while”,“switch”和“try”不能巢狀太深
max Maximum allowed control flow statement nesting depth.
預設值3
32、Custom Import Order (預設 關閉)
壞味道 主要
檢查匯入宣告組按照使用者指定的順序顯示。 如果有匯入,但是在組態中未指定其組,則匯入應放在匯入列表的末尾。
thirdPartyPackageRegExp RegExp for THIRDPARTY_PACKAGE group imports.
預設值^$
separateLineBetweenGroups
Force empty line separator between import groups.
預設值true
sortImportsInGroupAlphabetically
Force grouping alphabetically.
預設值false
specialImportsRegExp
RegExp for SPECIAL_IMPORTS group imports.
預設值^$
customImportOrderRules List of order declaration customizing by user. standardPackageRegExp
RegExp for STANDARD_JAVA_PACKAGE group imports.
預設值java|javax
33、Cyclomatic Complexity (預設 關閉)
壞味道 主要
檢查針對特定限制的方法的迴圈複雜性
switchBlockAsSingleDecisionPoint whether to treat the whole switch block as a single decision point
預設值false
max the maximum threshold allowed.
預設值10
tokens
tokens to check
預設值
LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_CASE,LITERAL_CATCH,QUESTION,LAND,LOR
34、Default Comes Last (預設 關閉)
壞味道 主要
檢查在switch語句中的所有情況之後的預設值。
skipIfLastAndSharedWithCase
whether to allow default along with case if they are not last
預設值false
35、Empty catch block (預設 關閉)
壞味道 主要
檢查空的catch塊。 有兩個選項可以使驗證更加精確(預設情況下,檢查允許空的catch塊和任何註釋)
exceptionVariableName Format of skipping exception''s variable name.
預設值^$
commentFormat
Format of comment.
預設值.*
36、Empty For Initializer Pad (預設 關閉)
壞味道 次要
檢查初始化程式為空的填充; 那是空的是否需要一個空的初始化程式,或者禁止這樣的空格。 示例:for(; i <j; i ++,j--)
option policy on how to pad an empty for iterator
37、Empty For Iterator Pad
壞味道 次要
檢查一個空的填充迭代器; 那就是空格是否需要一個空的迭代器,否則這樣的空格是被禁止的。 示例:for(Iterator foo = very.long.line.iterator(); foo.hasNext();)
option policy on how to pad an empty for iterator
38、Empty Line Separator (預設 關閉)
壞味道 主要
在標題,包,所有匯入宣告,欄位,建構函式,方法,巢狀類,靜態初始化器和例項初始化器之後檢查空行分隔符
allowNoEmptyLineBetweenFields
Allow no empty line between fields
預設值false
allowMultipleEmptyLines
Allows multiple empty lines between class members.
預設值true
tokens
assignments to check
預設值
PACKAGE_DEF,IMPORT,CLASS_DEF,INTERFACE_DEF,ENUM_DEF,STATIC_INIT,INSTANCE_INIT,METHOD_DEF,CTOR_DEF,VARIABLE_DEF
allowMultipleEmptyLinesInsideClassMembers
Allow multiple empty lines inside class members
預設值true
39、Executable Statement Count (預設 關閉)
壞味道 主要
將可執行語句的數量限制為指定的限制(預設= 30)。
max the maximum threshold allowed. Default is 30.
預設值30
tokens members to check
預設值
CTOR_DEF,METHOD_DEF,INSTANCE_INIT,STATIC_INIT
40、Expressions should not be too complex (預設 關閉)
壞味道 嚴重
表示式不應太複雜
max Maximum number of allowed conditional operators in an expression
預設值3
42、File Length (預設 關閉)
壞味道 主要
如果原始檔變得很長,那麼很難理解。 因此,長類通常應該重構到專注於特定任務的幾個單獨的類中
fileExtensions
file type extension of files to process
max maximum allowable number of lines. Default is 2000.
43、File Tab Character (預設 關閉)
壞味道 次要
檢查原始碼中沒有製表符('\ t')
fileExtensions
file type extension of files to process
eachLine whether to report on each line containing a tab, or just the first instance. Default is false.
44、Files should contain an empty new line at the end (預設 關閉)
壞味道 次要
檔案最後應該包含一個空的新行
壞味道 主要
檢查驗證識別符號名稱中的縮寫(連續大寫字母)長度,還允許執行駱駝案例命名
allowedAbbreviationLength 3
6、Annotation Location (預設 關閉)
壞味道 主要
註釋位置
allowSamelineSingleParameterlessAnnotation
To allow single parameterless annotation to be located on the same line as target element.
預設值true
allowSamelineParameterizedAnnotation
To allow parameterized annotation to be located on the same line as target element.
預設值false
allowSamelineMultipleAnnotations
To allow annotation to be located on the same line as target element.
預設值false
tokens
tokens to check
預設值CLASS_DEF,INTERFACE_DEF,ENUM_DEF,METHOD_DEF,CTOR_DEF,VARIABLE_DEF
7、Annotation Use Style (預設 關閉)
壞味道 主要
trailingArrayComma
Defines the policy for trailing comma in arrays. Default is never.
closingParens
Defines the policy for ending parenthesis. Default is never.
elementStyle
Defines the annotation element styles. Default value is compact_no_array.
8、Artifact ids should follow a naming convention (預設 關閉)
壞味道 次要
共享命名約定允許團隊有效協作。 當pom的artifactId與提供的正則表示式不匹配時,此規則引發了一個問題
regex The regular expression the "artifactId" should match
預設值[a-z][a-z-0-9]+
9、At-clause Order (預設 關閉)
壞味道 主要
檢查從句順序
tagOrder
allows to specify the order by tags.
預設值
@author,@version,@param,@return,@throws,@exception,@see,@since,@serial,@serialField,@serialData,@deprecated target allows to specify targets to check at-clauses.
10、Avoid Escaped Unicode Characters (預設 關閉)
壞味道 主要
避免轉義的Unicode字元
allowIfAllCharactersEscaped
Allow if all characters in literal are escaped.
預設值false
allowNonPrintableEscapes
Allow non-printable escapes.
預設值false
allowByTailComment
Allow use escapes if trail comment is present.
預設值false
allowEscapesForControlCharacters
Allow use escapes for non-printable(control) characters.
預設值false
11、Avoid Nested Blocks (預設 關閉)
壞味道 主要
避免巢狀塊
allowInSwitchCase
Allow nested blocks in case statements. Default is false.
12、Avoid Star Import (預設 關閉)
壞味道 次要
檢查發現使用*符號的匯入語句
excludes packages where star imports are allowed. Note that this property is not recursive, subpackages of excluded packages are not automatically excluded.
allowStaticMemberImports
whether to allow starred static member imports like <code>import static org.junit.Assert.*;</code>. Default is false.
預設值false
allowClassImports whether to allow starred class imports like <code>import java.util.*;</code>. Default is false.
預設值false
13、Boolean Expression Complexity (預設 關閉)
壞味道 主要
將巢狀布林運算子(&&,||和^)限制為指定的深度(預設= 3)。
max the maximum allowed number of boolean operations in one expression. Default is 3.
預設值3
tokens tokens to check. Default is LAND,BAND,LOR,BOR,BXOR.
預設值LAND,BAND,LOR,BOR,BXOR
14、Branches should have sufficient coverage by tests (預設 關閉)
壞味道 主要
分支應有足夠的測試覆蓋
minimumBranchCoverageRatio
預設值65
15、Catch Parameter Name (預設 關閉)
壞味道 主要
檢查catch引數名是否符合format屬性指定的格式
format Specifies valid identifiers. Default is ^(e|t|ex|[a-z][a-z][a-zA-Z]+)$
預設值^(e|t|ex|[a-z][a-z][a-zA-Z]+)$
16、Class Data Abstraction Coupling (預設 關閉)
壞味道 主要
度量衡量給定類中其他類的例項化數。
max the maximum threshold allowed. Default is 7.
excludedClasses User-configured class names to ignore.
excludeClassesRegexps User-configured regular expressions to ignore classes
excludedPackages User-configured packages to ignore
17、Class Fan Out Complexity (預設 關閉)
壞味道 主要
類的依賴類數量
max the maximum threshold allowed. Default is 20.
excludedClasses
User-configured class names to ignore
excludeClassesRegexps
User-configured regular expressions to ignore classes
excludedPackages
User-configured packages to ignore
18、Class names should comply with a naming convention (開放)
壞味道 次要
類名應符合命名約定
format Regular expression used to check the class names against.
預設值^[A-Z][a-zA-Z0-9]*$
19、Classes from "sun.*" packages should not be used (開放)
壞味道 主要
不得使用“sun.*”軟體包的類,sun類*或com.sun *包被視為實現細節,不屬於Java API
Exclude Comma separated list of Sun packages to be ignored by this rule. Example: com.sun.jna,sun.misc
20、Classes should not be coupled to too many other classes (Single Responsibility Principle) (預設 關閉)
壞味道 主要
類不應與太多其他類(單一責任原則)相耦合(依賴)
max Maximum number of classes a single class is allowed to depend upon
預設值20
21、Classes should not be too complex (預設 關閉)
壞味道 嚴重 廢棄
類不應太複雜
max Maximum complexity allowed.
預設值200
22、Classes should not have too many "static" imports (預設 關閉)
壞味道 主要
靜態匯入類允許您使用其公共靜態成員,而不必使用類名。 這可以很方便,但如果靜態匯入太多的類,你的程式碼可能會變得混亂,很難維護
threshold The maximum number of static imports allowed
預設值4
23、Classes should not have too many fields (預設 關閉)
壞味道 主要
類不應有太多欄位
countNonpublicFields
Whether or not to include non-public fields in the count
預設值true
maximumFieldThreshold
The maximum number of fields
預設值20
24、Classes should not have too many methods (預設 關閉)
壞味道 主要
類不應該有太多方法
countNonpublicMethods
Whether or not to include non-public methods in the count.
預設值true
maximumMethodThreshold
The maximum number of methods authorized in a class.
預設值35
25、Close curly brace and the next "else", "catch" and "finally" keywords should be located on the same line (預設 關閉)
壞味道 次要
關閉大括號,下一個“else”,“catch”和“finally”關鍵字應位於同一行
26、Close curly brace and the next "else", "catch" and "finally" keywords should be on two different lines (預設 關閉)
壞味道 次要
關閉大括號和下一個“else”,“catch”和“finally”關鍵字應該在兩個不同的行
29、Comments should not be located at the end of lines of code (預設 關閉)
壞味道 次要
註釋不應位於程式碼行的末尾
legalTrailingCommentPattern
Description Pattern for text of trailing comments that are allowed. By default, comments containing only one word.
預設值^\s*+[^\s]++$
30、Constant Name (預設 關閉)
壞味道 次要
檢查常數名稱是否符合指定的格式
applyToPackage
Controls whether to apply the check to package-private member
預設值true
format Regular expression
預設值^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
applyToPublic
Controls whether to apply the check to public member
預設值true
applyToProtected
Controls whether to apply the check to protected member
預設值true
applyToPrivate Controls whether to apply the check to private member
預設值true
31、Control flow statements "if", "for", "while", "switch" and "try" should not be nested too deeply (預設 關閉)
壞味道 嚴重
控制流程語句“if”,“for”,“while”,“switch”和“try”不能巢狀太深
max Maximum allowed control flow statement nesting depth.
預設值3
32、Custom Import Order (預設 關閉)
壞味道 主要
檢查匯入宣告組按照使用者指定的順序顯示。 如果有匯入,但是在組態中未指定其組,則匯入應放在匯入列表的末尾。
thirdPartyPackageRegExp RegExp for THIRDPARTY_PACKAGE group imports.
預設值^$
separateLineBetweenGroups
Force empty line separator between import groups.
預設值true
sortImportsInGroupAlphabetically
Force grouping alphabetically.
預設值false
specialImportsRegExp
RegExp for SPECIAL_IMPORTS group imports.
預設值^$
customImportOrderRules List of order declaration customizing by user. standardPackageRegExp
RegExp for STANDARD_JAVA_PACKAGE group imports.
預設值java|javax
33、Cyclomatic Complexity (預設 關閉)
壞味道 主要
檢查針對特定限制的方法的迴圈複雜性
switchBlockAsSingleDecisionPoint whether to treat the whole switch block as a single decision point
預設值false
max the maximum threshold allowed.
預設值10
tokens
tokens to check
預設值
LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_CASE,LITERAL_CATCH,QUESTION,LAND,LOR
34、Default Comes Last (預設 關閉)
壞味道 主要
檢查在switch語句中的所有情況之後的預設值。
skipIfLastAndSharedWithCase
whether to allow default along with case if they are not last
預設值false
35、Empty catch block (預設 關閉)
壞味道 主要
檢查空的catch塊。 有兩個選項可以使驗證更加精確(預設情況下,檢查允許空的catch塊和任何註釋)
exceptionVariableName Format of skipping exception''s variable name.
預設值^$
commentFormat
Format of comment.
預設值.*
36、Empty For Initializer Pad (預設 關閉)
壞味道 次要
檢查初始化程式為空的填充; 那是空的是否需要一個空的初始化程式,或者禁止這樣的空格。 示例:for(; i <j; i ++,j--)
option policy on how to pad an empty for iterator
37、Empty For Iterator Pad
壞味道 次要
檢查一個空的填充迭代器; 那就是空格是否需要一個空的迭代器,否則這樣的空格是被禁止的。 示例:for(Iterator foo = very.long.line.iterator(); foo.hasNext();)
option policy on how to pad an empty for iterator
38、Empty Line Separator (預設 關閉)
壞味道 主要
在標題,包,所有匯入宣告,欄位,建構函式,方法,巢狀類,靜態初始化器和例項初始化器之後檢查空行分隔符
allowNoEmptyLineBetweenFields
Allow no empty line between fields
預設值false
allowMultipleEmptyLines
Allows multiple empty lines between class members.
預設值true
tokens
assignments to check
預設值
PACKAGE_DEF,IMPORT,CLASS_DEF,INTERFACE_DEF,ENUM_DEF,STATIC_INIT,INSTANCE_INIT,METHOD_DEF,CTOR_DEF,VARIABLE_DEF
allowMultipleEmptyLinesInsideClassMembers
Allow multiple empty lines inside class members
預設值true
39、Executable Statement Count (預設 關閉)
壞味道 主要
將可執行語句的數量限制為指定的限制(預設= 30)。
max the maximum threshold allowed. Default is 30.
預設值30
tokens members to check
預設值
CTOR_DEF,METHOD_DEF,INSTANCE_INIT,STATIC_INIT
40、Expressions should not be too complex (預設 關閉)
壞味道 嚴重
表示式不應太複雜
max Maximum number of allowed conditional operators in an expression
預設值3
42、File Length (預設 關閉)
壞味道 主要
如果原始檔變得很長,那麼很難理解。 因此,長類通常應該重構到專注於特定任務的幾個單獨的類中
fileExtensions
file type extension of files to process
max maximum allowable number of lines. Default is 2000.
43、File Tab Character (預設 關閉)
壞味道 次要
檢查原始碼中沒有製表符('\ t')
fileExtensions
file type extension of files to process
eachLine whether to report on each line containing a tab, or just the first instance. Default is false.
44、Files should contain an empty new line at the end (預設 關閉)
壞味道 次要
檔案最後應該包含一個空的新行