-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQTTBlankStyleRule.cpp
More file actions
executable file
·166 lines (145 loc) · 5.07 KB
/
QTTBlankStyleRule.cpp
File metadata and controls
executable file
·166 lines (145 loc) · 5.07 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "oclint/AbstractASTVisitorRule.h"
#include "oclint/RuleSet.h"
#include "oclint/RuleConfiguration.h"
#include <iostream>
using namespace std;
using namespace clang;
using namespace oclint;
class QTTBlankStyleRule : public AbstractASTVisitorRule<QTTBlankStyleRule>
{
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";
}
/* 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 {
_teamname = RuleConfiguration::stringForKey("TEAM_NAME", "趣头条");
}
virtual void tearDown() override {}
bool VisitObjCPropertyDecl(ObjCPropertyDecl *node)
{
string methodDeclStr;
ASTContext *context = _carrier->getASTContext();
SourceLocation begin = node->getSourceRange().getBegin();
SourceLocation end = node->getSourceRange().getEnd(); methodDeclStr.assign(context->getSourceManager().getCharacterData(begin),end.getRawEncoding()-begin.getRawEncoding());
for(string::iterator it = methodDeclStr.begin(); it!= methodDeclStr.end(); it++)
{
if (*it == '(') {
if (it-2 >= methodDeclStr.begin()) {
if (!(*(it-1) == ' ' && *(it-2) == 'y') && *(it+1) != '^') {
addViolation(node, this, node->getNameAsString() + "@property左括号请遵循空格规范");
return true;
}
}
}
if (*it == ',') {
if (it+1 < methodDeclStr.end()) {
if (*(it+1) != ' ') {
addViolation(node, this, node->getNameAsString() + "@property中逗号请遵循空格规范");
return true;
}
}
}
if (*it == ')') {
if (it+1 < methodDeclStr.end()) {
if (*(it+1) != ' ') {
addViolation(node, this, node->getNameAsString() + "@property右括号请遵循空格规范");
return true;
}
}
}
if (*it == '*') {
if (it-1 >= methodDeclStr.begin()) {
if (*(it-1) != ' ') {
addViolation(node, this, node->getNameAsString() + "@property属性*修饰请遵循空格规范");
return true;
}
}
}
}
return true;
}
bool VisitObjCMethodDecl(ObjCMethodDecl *node)
{
string methodDeclStr;
ASTContext *context = _carrier->getASTContext();
SourceLocation begin = node->getSourceRange().getBegin();
SourceLocation end = node->getSourceRange().getEnd(); methodDeclStr.assign(context->getSourceManager().getCharacterData(begin),end.getRawEncoding()-begin.getRawEncoding());
for(string::iterator it = methodDeclStr.begin(); it!= methodDeclStr.end(); it++)
{
if (*it =='-' || *it =='+') {
if (it+2 < methodDeclStr.end()) {
if (!((*(it+1) == ' ')&&(*(it+2) == '('))) {
addViolation(node, this, "方法前面-或+请遵循空格规范");
return true;
}
}
}
if (*it =='{') {
if (it-1 >= methodDeclStr.begin()) {
if (*(it-1) != ' ' && *(it-1) != '\n') {
addViolation(node, this, "方法大括号请遵循空格规范");
}
}
return true;
}
}
return true;
}
};
static RuleSet rules(new QTTBlankStyleRule());