SonarQube规则之坏味道类型
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 (默认 关闭)
坏味道 次要
文件最后应该包含一个空的新行