11 #include "../utils/OptionsUtils.h" 12 #include "clang/AST/ASTContext.h" 13 #include "clang/ASTMatchers/ASTMatchFinder.h" 14 #include "llvm/ADT/StringExtras.h" 15 #include "llvm/Support/Regex.h" 27 constexpr
char DefaultSpecialAcronyms[] =
50 FixItHint generateFixItHint(
const ObjCPropertyDecl *Decl) {
51 if (isupper(Decl->getName()[0])) {
52 auto NewName = Decl->getName().str();
53 NewName[0] = tolower(NewName[0]);
54 return FixItHint::CreateReplacement(
55 CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
56 llvm::StringRef(NewName));
61 std::string validPropertyNameRegex(
const std::vector<std::string> &Prefixes) {
62 std::vector<std::string> EscapedPrefixes;
63 EscapedPrefixes.reserve(Prefixes.size());
66 std::transform(Prefixes.begin(), Prefixes.end(),
67 std::back_inserter(EscapedPrefixes), [](
const std::string& s) {
68 return llvm::Regex::escape(s); });
76 return std::string(
"::((") +
77 llvm::join(EscapedPrefixes.begin(), EscapedPrefixes.end(),
"|") +
78 ")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*$";
82 PropertyDeclarationCheck::PropertyDeclarationCheck(StringRef
Name,
86 Options.get(
"Acronyms", DefaultSpecialAcronyms))) {}
93 unless(matchesName(validPropertyNameRegex(SpecialAcronyms))))
99 const auto *MatchedDecl =
100 Result.Nodes.getNodeAs<ObjCPropertyDecl>(
"property");
101 assert(MatchedDecl->getName().size() > 0);
102 diag(MatchedDecl->getLocation(),
103 "property name '%0' should use lowerCamelCase style, according to " 104 "the Apple Coding Guidelines")
105 << MatchedDecl->getName() << generateFixItHint(MatchedDecl);
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
std::string serializeStringList(ArrayRef< std::string > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
Base class for all clang-tidy checks.
std::vector< std::string > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
std::map< std::string, std::string > OptionMap
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
static std::string join(ArrayRef< SpecialMemberFunctionsCheck::SpecialMemberFunctionKind > SMFS, llvm::StringRef AndOr)
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.