-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQTTEnumRule.cpp
More file actions
executable file
·79 lines (64 loc) · 1.67 KB
/
QTTEnumRule.cpp
File metadata and controls
executable file
·79 lines (64 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "oclint/AbstractASTVisitorRule.h"
#include "oclint/RuleSet.h"
#include "oclint/RuleConfiguration.h"
#include <iostream>
using namespace std;
using namespace clang;
using namespace oclint;
class QTTEnumRule : public AbstractASTVisitorRule<QTTEnumRule>
{
private:
string _teamname;
public:
virtual const string name() const override
{
return "枚举规范";
}
virtual int priority() const override
{
return 3;
}
virtual const string category() const override
{
return _teamname + "枚举";
}
#ifdef DOCGEN
virtual const std::string since() const override
{
return "0.13.1";
}
virtual const std::string description() const override
{
return ""; // TODO: fill in the description of the rule.
}
virtual const std::string example() const override
{
return R"rst(
.. code-block:: cpp
void example()
{
// TODO: modify the example for this rule.
}
)rst";
}
#endif
virtual void setUp() override {
_teamname = RuleConfiguration::stringForKey("TEAM_NAME", "趣头条");
}
virtual void tearDown() override {}
bool VisitEnumDecl(EnumDecl *node)
{
addViolation(node, this, node->getNameAsString()+"枚举尽量使用NS_ENUM/NS_OPTIONS");
return true;
}
bool VisitEnumConstantDecl(EnumConstantDecl *node)
{
string name = node->getNameAsString();
string::iterator itor = name.begin();
if(*itor == '_'){
addViolation(node, this, "枚举不要下划线开头");
}
return true;
}
};
static RuleSet rules(new QTTEnumRule());