diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2016-11-30 18:06:42 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2016-11-30 18:06:42 +0000 |
commit | de666a7753f9e6d554e24ae46cf86173cad64314 (patch) | |
tree | f6086ed44c3bbeebcfb8e7a7bb658d55c1cac1fa /clang-tidy/ClangTidy.cpp | |
parent | b24beea8f8b8804c52127014692f8f0f0763caba (diff) |
[clang-tidy] Make format style customizable
Summary: I came across an outstanding FIXME to make the format style customizable. Inspired by the include fixer, I added an new option `-style` to configure the fallback style in case no clang-format configuration file is found. The default remains "llvm".
Reviewers: Prazek, aaron.ballman, hokein, alexfh
Subscribers: cfe-commits, malcolm.parsons
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D27142
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@288258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/ClangTidy.cpp')
-rw-r--r-- | clang-tidy/ClangTidy.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/clang-tidy/ClangTidy.cpp b/clang-tidy/ClangTidy.cpp index a03f3fe9..1d22f724 100644 --- a/clang-tidy/ClangTidy.cpp +++ b/clang-tidy/ClangTidy.cpp @@ -88,13 +88,13 @@ private: class ErrorReporter { public: - ErrorReporter(bool ApplyFixes) + ErrorReporter(bool ApplyFixes, StringRef FormatStyle) : Files(FileSystemOptions()), DiagOpts(new DiagnosticOptions()), DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)), Diags(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs), &*DiagOpts, DiagPrinter), SourceMgr(Diags, Files), ApplyFixes(ApplyFixes), TotalFixes(0), - AppliedFixes(0), WarningsAsErrors(0) { + AppliedFixes(0), WarningsAsErrors(0), FormatStyle(FormatStyle) { DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors(); DiagPrinter->BeginSourceFile(LangOpts); } @@ -196,8 +196,7 @@ public: continue; } StringRef Code = Buffer.get()->getBuffer(); - // FIXME: Make the style customizable. - format::FormatStyle Style = format::getStyle("file", File, "LLVM"); + format::FormatStyle Style = format::getStyle("file", File, FormatStyle); llvm::Expected<Replacements> CleanReplacements = format::cleanupAroundReplacements(Code, FileAndReplacements.second, Style); @@ -248,6 +247,7 @@ private: unsigned TotalFixes; unsigned AppliedFixes; unsigned WarningsAsErrors; + StringRef FormatStyle; }; class ClangTidyASTConsumer : public MultiplexConsumer { @@ -538,8 +538,8 @@ runClangTidy(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider, } void handleErrors(const std::vector<ClangTidyError> &Errors, bool Fix, - unsigned &WarningsAsErrorsCount) { - ErrorReporter Reporter(Fix); + StringRef FormatStyle, unsigned &WarningsAsErrorsCount) { + ErrorReporter Reporter(Fix, FormatStyle); vfs::FileSystem &FileSystem = *Reporter.getSourceManager().getFileManager().getVirtualFileSystem(); auto InitialWorkingDir = FileSystem.getCurrentWorkingDirectory(); |