From 816a9668bb6c56b5fae96cbe6ca8c33aa90be1e5 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Mon, 29 May 2017 08:41:11 +0000 Subject: clang-format: [JS] do not clean up duplicated commas. Summary: In JavaScript, duplicated commas have semantic meaning. x = [a,,b]; The statement above creates an array with three entries, the middle being undefined. Because clang-format should not change semantics, disable this cleanup in JS. Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33641 llvm-svn: 304141 --- clang/lib/Format/Format.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Format/Format.cpp') diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4fa0012f51f..2ef6516e02e 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1910,6 +1910,9 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, tooling::Replacements cleanup(const FormatStyle &Style, StringRef Code, ArrayRef Ranges, StringRef FileName) { + // cleanups only apply to C++ (they mostly concern ctor commas etc.) + if (Style.Language != FormatStyle::LK_Cpp) + return tooling::Replacements(); std::unique_ptr Env = Environment::CreateVirtualEnvironment(Code, FileName, Ranges); Cleaner Clean(*Env, Style); -- cgit v1.2.3