oclint规则 Convention(公约)
来源:互联网 发布:ai矢量图软件免费下载 编辑:程序博客网 时间:2024/05/17 09:10
Convention¶
循环最后避免分支 AvoidBranchingStatementAsLastInLoop¶
Since: 0.7
在循环最后加入分支,理解起来会比较混乱,并且很有可能因为忘记而引起一些错误
This rule is defined by the following class: oclint-rules/rules/convention/AvoidBranchingStatementAsLastInLoopRule.cpp
Example:
void example(){ for (int i = 0; i < 10; i++) { if (foo(i)) { continue; } break; // this break is confusing }}
BaseClassDestructorShouldBeVirtualOrProtected¶
Since: 0.10.2
Make base class destructors public and virtual, or protected and nonvirtual
定义类: oclint-rules/rules/convention/BaseClassDestructorShouldBeVirtualOrProtectedRule.cpp
Example:
class Base{public: ~Base(); // this should be either protected or virtual}class C : public Base{ virtual ~C();}
References:
Sutter & Alexandrescu (November 2004). “C++ Coding Standards: 101 Rules, Guidelines, and Best Practices”.Addison-Wesley Professional
全覆盖的Switch不需要默认值 CoveredSwitchStatementsDontNeedDefault¶
Since: 0.8
一个全覆盖的Switch语句不应该有默认值设置。
定义类: oclint-rules/rules/convention/CoveredSwitchStatementsDontNeedDefaultRule.cpp
Example:
typedef enum { value1 = 0, value2 = 1} eValues;void aMethod(eValues a){ switch(a) { case value1: break; case value2: break; default: // this break is obsolete because all break; // values of variable a are already covered. }}
默认值没有在Switch的最后 DefaultLabelNotLastInSwitchStatement¶
Since: 0.6
默认值应该在switch语句的最后,不然代码会很混乱
定义类: oclint-rules/rules/convention/DefaultLabelNotLastInSwitchStatementRule.cpp
Example:
void example(int a){ switch (a) { case 1: break; default: // the default case should be last break; case 2: break; }}
虚拟类的析构函数 DestructorOfVirtualClass¶
Since: 0.8
这条规则要求虚拟类的析构函数必须是虚拟的
This rule is defined by the following class: oclint-rules/rules/convention/DestructorOfVirtualClassRule.cpp
Example:
class Base { // class Base should have a virtual destructor ~Base() public: virtual void f();};class Child : public Base { public: ~Child(); // destructor ~Child() should be virtual};
倒置逻辑 InvertedLogic¶
Since: 0.4
倒置逻辑让程序不容易理解
定义类: oclint-rules/rules/convention/InvertedLogicRule.cpp
Example:
int example(int a){ int i; if (a != 0) // if (a == 0) { // { i = 1; // i = 0; } // } else // else { // { i = 0; // i = 1; } // } return !i ? -1 : 1; // return i ? 1 : -1;}
Switch语句丢失Break MissingBreakInSwitchStatement¶
Since: 0.6
一个Switch语句中没有Break 很可能是一个错误。
定义类: oclint-rules/rules/convention/MissingBreakInSwitchStatementRule.cpp
Example:
void example(int a){ switch (a) { case 1: break; case 2: // do something default: break; }}
Switch中不是case NonCaseLabelInSwitchStatement¶
Since: 0.6
标签作为Switch语句的一部分是无法让人理解。
定义类: oclint-rules/rules/convention/NonCaseLabelInSwitchStatementRule.cpp
Example:
void example(int a){ switch (a) { case 1: break; label1: // label in a switch statement in really confusing break; default: break; }}
IvarAssignmentOutsideAccessorsOrInit¶
Since: 0.8
(这个规则限制外部访问其直接访问或者初始化)This rule prevents assigning an ivar outside of getters, setters, and init
method.
定义类: oclint-rules/rules/convention/ObjCAssignIvarOutsideAccessorsRule.cpp
Example:
@interface Foo : NSObject{ int _bar;}@property (assign, nonatomic) int bar;@end@implementation Foo@synthesize bar = _bar;- (void)doSomething { _bar = 3; // access _bar outside its getter, setter or init}@end
参数值重置 ParameterReassignment¶
Since: 0.6
大多数情况下,参数重新设置值,是有问题的。
定义类: oclint-rules/rules/convention/ParameterReassignmentRule.cpp
Example:
void example(int a){ if (a < 0) { a = 0; // reassign parameter a to 0 }}
用短判断退出然后继续执行UseEarlyExitsAndContinue¶
Since: 0.8
使用较短的语句退出,可以让代码阅读更容易理解。不用记住之前很长的判断
定义类: oclint-rules/rules/convention/PreferEarlyExitRule.cpp
Example:
int *doSomething(int a) { if (!foo(a) && bar(a) && doOtherThing(a)) { // ... some really long code .... } return 0;}// is preferred asint *doSomething(int a) { if (foo(a)) { return 0; } if (!bar(a)) { return 0; } if (!doOtherThing(a)) { return 0; } // ... some long code ....}
Switch 语句应该有一个默认值 SwitchStatementsShouldHaveDefault¶
Since: 0.6
Switch 语句应该有一个默认值
定义类: oclint-rules/rules/convention/SwitchStatementsShouldHaveDefaultRule.cpp
Example:
void example(int a){ switch (a) { case 1: break; case 2: break; // should have a default }}
Switch分支语句太少 TooFewBranchesInSwitchStatement¶
Since: 0.6
如果Switch语句只有很少的分支应该使用if else 语句
定义类: oclint-rules/rules/convention/TooFewBranchesInSwitchStatementRule.cpp
Example:
void example(int a){ switch (a) { case 1: break; default: break; } // Better to use an if statement and check if variable a equals 1.}
Thresholds:
- MINIMUM_CASES_IN_SWITCH
- The reporting threshold for count of case statements in a switch statement, default value is 3.
- 默认值是3
- oclint规则 Convention(公约)
- OCLint的部分规则(Convention 部分)
- oclint规则 Size(大小)
- oclint规则 Unused(无用)
- oclint规则
- [OCLint]OCLint代码检查规则
- oclint规则 Redundant(沉余)
- OCLint的部分规则(Basic 部分)
- OCLint的部分规则(Unuseed 部分)
- OCLint的部分规则(Size 部分)
- OCLint的部分规则(Redundant 部分)
- OCLint的部分规则(Naming 部分)
- OCLint的部分规则(Migration 部分)
- OCLint的部分规则(Empty 部分)
- OCLint的部分规则(Design 部分)
- OCLint的部分规则(CoCoa 部分)
- oclint 规则选择
- oclint规则 Cocoa
- Date与Calendar、部分类型的转换
- hive复合数据类型之map
- android - 奔溃日志收集,UncaughtExceptionHandler实现
- 用js动态生成css代码
- java笔记-多态
- oclint规则 Convention(公约)
- 2016.08.19上午【初中部 NOIP普及组 】模拟赛题解
- USACO 2010 Open Silver 3.Time Travel 链表?
- hjr学习-分类算法:朴素贝叶斯算法
- 【华为OJ】查找整数二进制中1的个数
- 工厂区分短见
- POJ 2342 Anniversary party 洛谷 P1352 没有上司的舞会
- 毕业生自传(浴血奋战)
- 《算法导论》chapter1/2