-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQTTClassNameRule.cpp
More file actions
executable file
·115 lines (93 loc) · 2.61 KB
/
QTTClassNameRule.cpp
File metadata and controls
executable file
·115 lines (93 loc) · 2.61 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "oclint/AbstractASTVisitorRule.h"
#include "oclint/RuleSet.h"
#include "oclint/RuleConfiguration.h"
#include <iostream>
using namespace std;
using namespace clang;
using namespace oclint;
class QTTClassNameRule : public AbstractASTVisitorRule<QTTClassNameRule>
{
private:
string _threshold;
public:
virtual const string name() const override
{
return "类名规范";
}
virtual int priority() const override
{
return 3;
}
virtual const string category() const override
{
return _threshold + "类名";
}
#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";
}
/* fill in the file name only when it does not match the rule identifier
virtual const std::string fileName() const override
{
return "";
}
*/
/* add each threshold's key, description, and its default value to the map.
virtual const std::map<std::string, std::string> thresholds() const override
{
std::map<std::string, std::string> thresholdMapping;
return thresholdMapping;
}
*/
/* add additional document for the rule, like references, notes, etc.
virtual const std::string additionalDocument() const override
{
return "";
}
*/
/* uncomment this method when the rule is enabled to be suppressed.
virtual bool enableSuppress() const override
{
return true;
}
*/
#endif
virtual void setUp() override {
_threshold = RuleConfiguration::stringForKey("TEAM_NAME", "趣头条");
}
virtual void tearDown() override {}
bool VisitObjCProtocolDecl(ObjCProtocolDecl *node)
{
string name = node->getNameAsString();
string::iterator itor = name.begin();
if(!(*itor >= 'A' && *itor <= 'Z')){
addViolation(node, this, name+"协议名请用大写字母开头");
}
return true;
}
bool VisitObjCImplDecl(ObjCImplDecl *node)
{
string name = node->getNameAsString();
string::iterator itor = name.begin();
if(!(*itor >= 'A' && *itor <= 'Z')){
addViolation(node, this, name+"类名请用大写字母开头");
}
return true;
}
};
static RuleSet rules(new QTTClassNameRule());