-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShortMemberNamesCheck.cpp
43 lines (37 loc) · 1.32 KB
/
ShortMemberNamesCheck.cpp
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
//===--- ShortMemberNamesCheck.cpp - clang-tidy----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ShortMemberNamesCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace valpo {
void ShortMemberNamesCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(fieldDecl().bind("field"), this);
}
void ShortMemberNamesCheck::check(const MatchFinder::MatchResult &Result) {
const auto *field = Result.Nodes.getNodeAs<FieldDecl>("field");
if (field == nullptr) {
diag(SourceLocation(),"no match", DiagnosticIDs::Fatal);
return;
}
else {
const auto fieldClass = dyn_cast<CXXRecordDecl>(field->getParent());
if (fieldClass == nullptr) {
return;
}
if (field->getAccess() != AS_private && field->getName().size() < 3) {
diag(field->getLocation(), "non private member %0 has a very short name") << field;
}
}
}
} // namespace valpo
} // namespace tidy
} // namespace clang