/// http://llvm.org/docs/CodingStandards.html.
FormatStyle getLLVMStyle();
-/// \brief Returns a format style complying with Google's C++ style guide:
+/// \brief Returns a format style complying with one of Google's style guides:
/// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.
-FormatStyle getGoogleStyle();
-
-/// \brief Returns a format style complying with Google's JavaScript style
-/// guide:
/// http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml.
-FormatStyle getGoogleJSStyle();
-
-/// \brief Returns a format style complying with Google's Protocol Buffer style:
/// https://developers.google.com/protocol-buffers/docs/style.
-FormatStyle getGoogleProtoStyle();
+FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language);
/// \brief Returns a format style complying with Chromium's style guide:
/// http://www.chromium.org/developers/coding-style.
-FormatStyle getChromiumStyle();
+FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language);
/// \brief Returns a format style complying with Mozilla's style guide:
/// https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style.
return LLVMStyle;
}
-FormatStyle getGoogleStyle() {
+FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
FormatStyle GoogleStyle = getLLVMStyle();
+ GoogleStyle.Language = Language;
+
GoogleStyle.AccessModifierOffset = -1;
GoogleStyle.AlignEscapedNewlinesLeft = true;
GoogleStyle.AllowShortIfStatementsOnASingleLine = true;
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
- return GoogleStyle;
-}
-
-FormatStyle getGoogleJSStyle() {
- FormatStyle GoogleJSStyle = getGoogleStyle();
- GoogleJSStyle.Language = FormatStyle::LK_JavaScript;
- GoogleJSStyle.BreakBeforeTernaryOperators = false;
- GoogleJSStyle.MaxEmptyLinesToKeep = 2;
- GoogleJSStyle.SpacesInContainerLiterals = false;
- return GoogleJSStyle;
-}
+ if (Language == FormatStyle::LK_JavaScript) {
+ GoogleStyle.BreakBeforeTernaryOperators = false;
+ GoogleStyle.MaxEmptyLinesToKeep = 2;
+ GoogleStyle.SpacesInContainerLiterals = false;
+ } else if (Language == FormatStyle::LK_Proto) {
+ GoogleStyle.AllowShortFunctionsOnASingleLine = false;
+ }
-FormatStyle getGoogleProtoStyle() {
- FormatStyle GoogleProtoStyle = getGoogleStyle();
- GoogleProtoStyle.Language = FormatStyle::LK_Proto;
- GoogleProtoStyle.AllowShortFunctionsOnASingleLine = false;
- return GoogleProtoStyle;
+ return GoogleStyle;
}
-FormatStyle getChromiumStyle() {
- FormatStyle ChromiumStyle = getGoogleStyle();
+FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
+ FormatStyle ChromiumStyle = getGoogleStyle(Language);
ChromiumStyle.AllowAllParametersOfDeclarationOnNextLine = false;
ChromiumStyle.AllowShortIfStatementsOnASingleLine = false;
ChromiumStyle.AllowShortLoopsOnASingleLine = false;
if (Name.equals_lower("llvm")) {
*Style = getLLVMStyle();
} else if (Name.equals_lower("chromium")) {
- *Style = getChromiumStyle();
+ *Style = getChromiumStyle(Language);
} else if (Name.equals_lower("mozilla")) {
*Style = getMozillaStyle();
} else if (Name.equals_lower("google")) {
- switch (Language) {
- case FormatStyle::LK_JavaScript:
- *Style = getGoogleJSStyle();
- break;
- case FormatStyle::LK_Proto:
- *Style = getGoogleProtoStyle();
- break;
- default:
- *Style = getGoogleStyle();
- }
+ *Style = getGoogleStyle(Language);
} else if (Name.equals_lower("webkit")) {
*Style = getWebKitStyle();
} else if (Name.equals_lower("gnu")) {
namespace clang {
namespace format {
+FormatStyle getGoogleStyle() {
+ return getGoogleStyle(FormatStyle::LK_Cpp);
+}
+
class FormatTest : public ::testing::Test {
protected:
std::string format(llvm::StringRef Code, unsigned Offset, unsigned Length,
" backing:NSBackingStoreBuffered\n"
" defer:NO]);\n"
"}",
- getChromiumStyle());
+ getChromiumStyle(FormatStyle::LK_Cpp));
verifyFormat("[contentsContainer replaceSubview:[subviews objectAtIndex:0]\n"
" with:contentsNativeView];");
EXPECT_TRUE(getPredefinedStyle("gOOgle", FormatStyle::LK_Cpp, &Styles[2]));
EXPECT_ALL_STYLES_EQUAL(Styles);
- Styles[0] = getGoogleJSStyle();
+ Styles[0] = getGoogleStyle(FormatStyle::LK_JavaScript);
EXPECT_TRUE(
getPredefinedStyle("Google", FormatStyle::LK_JavaScript, &Styles[1]));
EXPECT_TRUE(
getPredefinedStyle("gOOgle", FormatStyle::LK_JavaScript, &Styles[2]));
EXPECT_ALL_STYLES_EQUAL(Styles);
- Styles[0] = getChromiumStyle();
+ Styles[0] = getChromiumStyle(FormatStyle::LK_Cpp);
EXPECT_TRUE(getPredefinedStyle("Chromium", FormatStyle::LK_Cpp, &Styles[1]));
EXPECT_TRUE(getPredefinedStyle("cHRoMiUM", FormatStyle::LK_Cpp, &Styles[2]));
EXPECT_ALL_STYLES_EQUAL(Styles);
EXPECT_ALL_STYLES_EQUAL(Styles);
Styles.resize(5);
- Styles[0] = getGoogleJSStyle();
+ Styles[0] = getGoogleStyle(FormatStyle::LK_JavaScript);
Styles[1] = getLLVMStyle();
Styles[1].Language = FormatStyle::LK_JavaScript;
EXPECT_EQ(0, parseConfiguration("BasedOnStyle: Google", &Styles[1]).value());
return Result;
}
- static std::string format(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleJSStyle()) {
+ static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
return format(Code, 0, Code.size(), Style);
}
static FormatStyle getGoogleJSStyleWithColumns(unsigned ColumnLimit) {
- FormatStyle Style = getGoogleJSStyle();
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
Style.ColumnLimit = ColumnLimit;
return Style;
}
- static void verifyFormat(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleJSStyle()) {
+ static void verifyFormat(
+ llvm::StringRef Code,
+ const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
}
};
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
verifyFormat("var arr = [1, 2, 3];");
verifyFormat("var obj = {a: 1, b: 2, c: 3};");
+
+ verifyFormat("var obj = {a: 1, b: 2, c: 3};",
+ getChromiumStyle(FormatStyle::LK_JavaScript));
}
TEST_F(FormatTestJS, SingleQuoteStrings) {
}
static std::string format(llvm::StringRef Code) {
- FormatStyle Style = getGoogleProtoStyle();
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
Style.ColumnLimit = 60; // To make writing tests easier.
return format(Code, 0, Code.size(), Style);
}