FlexPMD 通过审查 AS3/Flex 目录检测常见的不良用法,例如:
FlexPMD 使用了PMD部分机能,原理与其类似,也是通过规则定义检测内容。
截止发稿时 FlexPMD 已有 20 个规则组,包括 100 多个规则,当然你也可以自定义规则以扩展当前机能。
你可以通过以下方式调用 FlexPMD:
官方站点
http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD
安装 FlexPMD 插件
下载 FlexPMD 插件所需 jar 包
生成 FlexPMD 规则配置文件
FlexPMD 有一个在线规则组创建器,你可以通过它了解、屏蔽、追加规则,之后导出这些规则到某一目录(我放在 C:\FlexPMD\rules 下)
配置 FlexPMD 插件
运行 FlexPMD
FlexPMD 已安装完成,使用很简单:
class | type | message(英) | description(英) | message(中) | description(中) |
BindingUtilsRule | Binding | BindingUtils class uses hard coded strings, which won't be picked up by the compiler if you rename this attribute. You should probably consider refactoring using events | 绑定类时使用了硬编码的字符串,编译器不会识别,如果你重命名此属性,你应该考虑事件的重构。 | ||
TooLongBindingExpression | Binding | This binding expression is too long ({0} dots maximum, but {1} actually) | A Binding expression is executed as soon as one of the bindable attributes changed. If a binding expression contains too many expression, there could be some performance issue. | 绑定表达式过长。 | |
BindableModelLocatorRule | Cairngorm | A modelLocator must not be Bindable at a class level | A bindable ModelLocator could leads to performance issues due to bindings | modelLocator必须是类级别且是不可绑定的。 | 绑定的modelLocator会造成性能问题。 |
BadCairngormEventNameFor | Cairngorm | A Cairngorm event name should contain the function area name before the actual event name | You would have something like 'productManagement.getProducts' as an event name. | 一个Cairngorm事件的名称应在实际事件名称前包含功能区名称。 | 你可以取如下的名字作为事件名称: 'productManagement.getProducts' |
UpdateChildrenNumberInUp | Custom Component | Flex specific - Do not add or remove displayable children from updateDisplayList | UpdateDisplayList is called everytime a child is invalidated. So calling addChild or removeChild in this function could be really CPU consuming | 不要通过updateDisplayList方法添加或删除可显示的子对象。 | 对于一个有效的页面元素子对象,updateDisplayList方法时刻被调用,在该方法中添加或删除子对象会非常消耗CPU。 |
CallLaterDirectlyRule | Custom Component | Flex specific - Don't call 'callLater' explicitly | If you needed to call 'callLater' explicitly, then you probably did not extend the correct component life cycle. | 不要明确的调用callLater。 | 如果你明确地调用了“callLater,那么你可能没有了正确的组件生命周期。 |
EmptyCatchStatementRule | Empty Statement | This catch statement is empty | catch语句是空的。 | ||
EmptyIfStmtRule | Empty Statement | No statements in this if statement | Empty If Statement finds instances where a condition is checked but nothing is done about it. | if语句是空的。 | |
ExcessiveImportRule | Maintanability | A high number of imports can indicate a high degree of coupling within an object. ({0} maximum but {1} actually) | A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold. | 导入(import)对象的数量过高表明对象内的耦合程度高。 | 导入(import)对象的数量过高表明对象内的耦合程度高。可以设置导入对象数的上限,超过时产生提示。 |
TrueFalseConditionRule | Maintanability | This test contains a hard coded boolean value. You could remove it by having '{0}' | 包含了硬编码的布尔值。 | ||
NonStaticConstantFieldRu | Maintanability | A constant field should be static ({0}) | constant类型的变量应该设置成静态的。 | ||
UseGenericTypeRule | Maintanability | Use strongly typed objects instead of * | 使用强类型的对象取代禁止使用的类。 | ||
UselessOverridenFunction | Maintanability | This method is empty. This should be removed ({0}) | 方法为空。 | ||
EmptyStatementRule | Maintanability | This statement is empty | 表达式为空。 | ||
TooShortVariableRule | Naming | This variable name is too short ({0} characters minimum, but {1} actually) | Detects when a field, local, or parameter has a very short name. | 名字太短。 | 字段,参数等变量名字太短。 |
PackageCaseRule | Naming | A package name should be lower case ({0}) | Detects when a package definition contains upper case characters. | 路径名应该小写。 | 发现存在大写的路径名。 |
VariableNameEndingWithNu | Naming | Using digits at the end of a symbol does not help understanging the meaning of it. ({0}) | 在变量名字最后使用数字,不利于理解它的含义。 | ||
PropertyHiddenByLocalVar | Naming | A class property is hidden by this local variable ({0}) | 类的属性被本地局部变量隐藏。 | ||
IncorrectClassCase | Naming | A class name must start by a majuscule character | 类名字必须以大写字母开头。 | ||
InterfaceNamingRule | Naming | Interface name should start with I | 接口名字应该以字母I开头。 | ||
CyclomaticComplexityRule | performance | This method is too complex. Maximum complexity is {0}, but its cyclomatic complexity was {1} | 方法的圈复杂度(cyclomatic complexity)过高。 注1 | ||
BindableClassRule | performance | Globally bindable classes can lead to unexpected behaviour especially when you have a setter to a property, and hits the performance of the application | 全局绑定类可能会造成预料不到的结果,尤其是该类含有setter的属性。 | ||
AvoidInstanciationInLoop | performance | Instanciating a variable in a loop can be expensive | 在循环中定义变量会增加系统开销。 | ||
DeeplyNestedIfRule | performance | Nested if statements are not a good design | 嵌套if语句不是好的设计。 | ||
TooLongFunctionRule | Sizing | This function is far too long ({0} maximum, but {1} actually) | Violations of this rule usually indicate that the method has too much responsibility. Try to reduce the method size by creating helper methods and removing any copy/pasted code. | 方法内容过长。 | 方法过长会包含过多的业务逻辑,尽量从业务逻辑上切分独立的方法。 |
TooManyPublicRule | Sizing | Too many public fields or functions detected ({0} maximum, but {1} actually) | A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it. | 类中公有属性和公有方法过多。 | 类中公有属性和公有方法过多,会给代码重构,维护,测试等增加负担。 |
TooManyFieldsRule | Sizing | Too many field detected ({0} maximum, but {1} actually) | Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zipcode fields could instead have one Address field. | 字段定义过多。 | 可以尝试重新设计,和并相同业务逻辑的字段,如: 用address字段取代city/state/zipcode3个字段。 |
ImportFromSamePackageRul | Style | Imports from the same package are not necessary | 没必要导入相同的包。 | ||
SwitchStatementsShouldHa | Switches | A switch statement does not contain a default statement | Switch statements should have a default label in order to detect corner cases. | Switch表达式中缺少default表达式。 | Switch表达式中应该有default表达式来处理例外情况。 |
NestedSwitchRule | Switches | Switch must not be nested | As a general practice, switch statement should not be used. Prefer using inheritance. It is even harder to read when switch statements are nested. | Switch不应该嵌套使用。 | 嵌套使用的Switch语句会增加阅读的复杂度。 |
NonBreakableSwitchCaseRu | Switches | Switch case must include break statement | Switch表达式中应包含break语句。 | ||
IdenticalSwitchCasesRule | Switches | Two switch cases should not be identical | Switch表达式中不应该含有相同的case。 | ||
UnusedParameterRule | Unused | This parameter ({0}) of this function is not used | 方法的参数未被使用。 | ||
UnusedLocalVariableRule | Unused | This variable ({0}) is not used | 定义的变量未被使用。 | ||
UnusedPrivateMethodRule | Unused | This private method ({0}) does not seem to be used | 定义的私有方法未被使用。 | ||
UnusedFieldRule | Unused | This private attribute ({0}) does not seem to be used | 定义的私有属性未被使用。 | ||
EmptyPrivateMethodRule | Unused | This private method ({0}) is used but its content is empty | 定义的私有方法内容为空。 |
注1,圈复杂度(cyclomatic complexity): |
一种代码复杂度的衡量标准。在软件测试的概念里,圈复杂度用来衡量一个模块判定结构的复杂程度,数量上表现为独立现行路径条数,即合理的预防错误所需测试的最少路径条数,圈复杂度大说明程序代码可能质量低且难于测试和维护。具体内容,见《软件复杂度概述》。 |