Commit Graph

2102 Commits

Author SHA1 Message Date
Mitchell Balan c5c487f0d4 Revert "[clang-format] Add option to specify explicit config file"
There were a number of unexpected test failures.

This reverts commit 10b1a87ba3.
2020-03-11 16:14:42 -04:00
Mitchell Balan 10b1a87ba3 [clang-format] Add option to specify explicit config file
Summary:
This diff extends the -style=file option to allow a config file to be specified explicitly. This is useful (for instance) when adding IDE commands to reformat code to a personal style.

Reviewers: djasper, ioeric, krasimir, MyDeveloperDay

Reviewed by: MyDeveloperDay

Contributed by: tnorth

Subscribers: cfe-commits, lebedev.ri, MyDeveloperDay, klimek, sammccall, mitchell-stellar

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D72326
2020-03-11 15:56:44 -04:00
Jonathan Coe 1fb9c29833 [clang-format] Improved identification of C# nullables
Summary:
Allow `?` inside C# generics.

Do not mistake casts like `(Type?)` as conditional operators.

Reviewers: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75983
2020-03-11 12:58:52 +00:00
Jonathan Coe 5c917bd9a7 [clang-format] No space in `new()` and `this[Type x]` in C#
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75984
2020-03-11 12:53:53 +00:00
Jonathan Coe 0c28a0938c [clang-format] Correct indentation for `[key] = value,` entries in C# object initialisers
Restores content of commit cb3f20d27c
reverted in commit 5a101f3773
with a corrected commit message.

Summary: Do not use continuation indent for '[' in blocks in C# code.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75747
2020-03-10 09:36:52 +00:00
Jonathan Coe 5a101f3773 Revert "[clang-format] Correct indentation for `[key] = value,` entries in C++ object initialisers"
Commit message says "C++" where it should say "C#".

This reverts commit cb3f20d27c.
2020-03-10 09:30:34 +00:00
Jonathan Coe cb3f20d27c [clang-format] Correct indentation for `[key] = value,` entries in C++ object initialisers
Summary: Do not use continuation indent for '[' in blocks in C# code.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75747
2020-03-09 18:04:34 +00:00
Jonathan Coe eb682b8027 [clang-format] C# does not indent braced initializers as continuations
Summary: C# treats object initializers as braced init blocks. Braced init blocks are no longer indented as continuations.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75731
2020-03-09 17:36:21 +00:00
Jonathan Coe b28ed9cec8 [clang-format] cleanup from D75517
Summary:
Fix typo in comment.

Add closing brace to test text.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75856
2020-03-09 17:31:36 +00:00
Mitchell Balan 2eff1c3ce4 [clang-format] Extend AllowShortLoopsOnASingleLine to do ... while loops.
Summary:
If AllowShortLoopsOnASingleLine is enabled,

  do
    a++;
  while (true);

becomes

  do a++;
  while (true);

Reviewers: MyDeveloperDay, mitchell-stellar

Reviewed by: mitchell-stellar

Contributed by: DaanDeMeyer

Subscribers: cfe-commits

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D75022
2020-03-06 11:13:23 -05:00
Krasimir Georgiev 36c2ab8d04 [clang-format] do not insert spaces around inline asm symbolic names
Summary:
Fixes https://bugs.llvm.org/show_bug.cgi?id=45108.

The `[` in such cases was mis-annotated as an `TT_ArrayInitializerLSquare`.

Reviewers: hans

Reviewed By: hans

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75675
2020-03-05 14:17:21 +01:00
Jonathan Coe fe61bc1a0b [clang-format] Improve identification of C# nullables
Summary: Consider `? identifier =` and `? identifier;` to be nullable within function bodies.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75606
2020-03-04 18:10:27 +00:00
Jonathan Coe 7d2fdd3f66 [clang-format] parse C# object initialisers
Summary:
Treat C# object initializers as braced lists.

Allow lambdas inside C# braced lists.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75473
2020-03-04 12:14:00 +00:00
Jonathan Coe 736fef97c7 [clang-format] Do not format C# array subscript operators as attributes
Summary:
Fix misidentification of C# array subscript operators.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75517
2020-03-03 22:21:33 +00:00
Jonathan Coe 9f8a7e82b8 [clang-format] Allow nested [] in C# attributes
Summary: Keep track of unpaired [] when identifying C# attribute lines

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75455
2020-03-03 17:35:09 +00:00
Jonathan Coe 9c4afce702 [clang-format] Rename CSharpNullConditionalSq and add missing test
Summary:
Rename CSharpNullConditionalSq to CSharpNullConditionalLSquare.

Add test for spaces inside [] with C# Null conditionals.

Address comments missed from https://reviews.llvm.org/D75368.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75456
2020-03-02 15:46:33 +00:00
Jonathan Coe c3af063c2b [clang-format] Handle NullCoalescing and NullConditional operators in C#
Summary:
Disable merging of Type? into a single token.

Merge ?? ?. and ?[ into a single token.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75368
2020-03-02 13:55:54 +00:00
Jonathan Coe f829615205 [clang-format] Improve C# handling of spaces in square brackets
Reviewers: MyDeveloperDay, krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75336
2020-02-28 12:44:15 +00:00
Jonathan Coe 5f52a93b69 [clang-format] Recognize C# nullable types
Summary:
Do not confuse C# nullable types with conditional expressions.

Do not put a space before the `?` in `[access-modifier] Type? variableName;`

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir, MyDeveloperDay

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75261
2020-02-28 11:09:55 +00:00
Jonathan Coe 7dfe0cc7f5 [clang-format] Recognize C# named argument colons as a token type
Summary:
No longer merge 'name' and ':' into a single token.

Ensure that line breaks cannot be placed before or after a named-argument colon.

Ensure that no space is inserted before a named-argument colon.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits, MyDeveloperDay

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75244
2020-02-27 13:47:29 +00:00
Jonathan Coe 548e540d2c [clang-format] Handle commas in [] in C#
Summary:
Respect setting `SpacesInSquareBrackets` for commas in square brackets in C# code.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75182
2020-02-27 11:49:30 +00:00
Jonathan Coe e8c5fea243 [clang-format] Special handling of spaces for C# code
Summary:
Ensure that there are spaces around braces '{', '}'.

Ensure that there is a space before and after '=>'.

Ensure that 'async' and 'when' are considered as keywords when inserting spaces.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D75129
2020-02-26 15:27:03 +00:00
Jonathan Coe 2bd6974aaa [clang-format] Wrap lines for C# property accessors
Summary: Ensure that auto-implemented properties `{ get; private set }` are wrapped on to one line for C# code.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D75006
2020-02-25 14:23:47 +00:00
Jonathan Coe a11ff39ba2 [clang-format] Merge name and colon into a single token for C# named arguments
Summary:
Merge 'argumentName' and ':' into a single token in foo(argumentName: bar).

Add C# named argument as a token type.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74894
2020-02-20 19:23:38 +00:00
Alexander Lanin 709fd989b6 [clang-tidy] fix readability-redundant-member-init auto-fix of Function-try-block
Summary: This fixes https://bugs.llvm.org/show_bug.cgi?id=39310

Reviewers: malcolm.parsons, ioeric

Reviewed By: malcolm.parsons

Subscribers: xazax.hun

Tags: #clang-format, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D74800
2020-02-19 23:04:05 +00:00
Wawha fa0118e6e5 [clang-format] Add new option BeforeLambdaBody in Allman style.
This option add a line break then a lambda is inside a function call.

Reviewers : djasper, klimek, krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D44609
2020-02-13 22:16:41 +01:00
Jonathan Coe b46f925d68 [clang-format] Improve handling of C# attributes
Summary:
C# attributes can appear on classes and methods, in which case they should go on their own line, or on method parameters in which case
they should be left inline.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: MyDeveloperDay

Subscribers: klimek

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74265
2020-02-11 12:00:17 +00:00
Jonathan Coe f40a7972cb [clang-format] Do not merge short C# class definitions into one line
Summary: Skip access specifiers before record definitions when deciding whether
or not to wrap lines so that C# class definitions do not get wrapped into a
single line.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74050
2020-02-05 17:38:33 +00:00
Jonathan Coe ca1fd460f1 [clang-format] Do not treat C# attribute targets as labels
Summary: Merge '[', 'target' , ':' into a single token for C# attributes to
prevent the target from being seen as a label.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D74043
2020-02-05 17:30:24 +00:00
Jonathan Coe 50d8977c45 [clang-format] Allow a comment to follow a C# attribute specifier
Summary: Add comments to the list of tokens that can follow the ']' at the end of a C# attribute specifier to prevent comments after attribute specifiers from being formatted as continuations.

Reviewers: MyDeveloperDay, krasimir

Reviewed By: MyDeveloperDay

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73977
2020-02-04 19:00:54 +00:00
mydeveloperday 70c98671fa [clang-format] Add option for not breaking line before ObjC params
Summary:
From `clang-format` version 3.7.0 and up, , there is no way to keep following format of ObjectiveC block:
```
- (void)_aMethod
{
    [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
        u = c;
    }]
}
```
Regardless of the change in `.clang-format` configuration file, all parameters will be lined up so that colons will be on the same column, like following:
```
- (void)_aMethod
{
    [self.test1 t:self
                w:self
         callback:^(typeof(self) self, NSNumber *u, NSNumber *v) {
             u = c;
         }]
}
```

Considering with ObjectiveC, the first code style is cleaner & more readable for some people, I've added a config option: `ObjCDontBreakBeforeNestedBlockParam` (boolean) so that if it is enable, the first code style will be favored.

Reviewed By: MyDeveloperDay

Patch By: ghvg1313

Tags: #clang, #clang-format

Differential Revision: https://reviews.llvm.org/D70926
2020-02-01 17:39:34 +00:00
Jonathan Coe 0bb60e29f1 [clang-format] Fixes for spaces around C# object initializers
Summary: Fix spaces around typename and [] in C# object initializers.

Reviewers: MyDeveloperDay, klimek, krasimir

Reviewed By: MyDeveloperDay, krasimir

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D72401
2020-01-31 14:22:01 +00:00
Jonathan Coe f9f0919db7 [clang-format] Improve support for multiline C# strings
Reviewers: krasimir

Reviewed By: krasimir

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73622
2020-01-30 13:45:48 +00:00
Sanne Wouda 4ec2a26732 Fix clang test build 2020-01-29 13:03:27 +00:00
Martin Probst a324fcf1ae clang-format: insert trailing commas into containers.
Summary:
This change adds an option to insert trailing commas into container
literals. For example, in JavaScript:

    const x = [
      a,
      b,
       ^~~~~ inserted if missing.
    ]

This is implemented as a seperate post-processing pass after formatting
(because formatting might change whether the container literal does or
does not wrap). This keeps the code relatively simple and orthogonal,
though it has the notable drawback that the newly inserted comma is not
taken into account for formatting decisions (e.g. it might exceed the 80
char limit). To avoid exceeding the ColumnLimit, a comma is only
inserted if it fits into the limit.

Trailing comma insertion conceptually conflicts with argument
bin-packing: inserting a comma disables bin-packing, so we cannot do
both. clang-format rejects FormatStyle configurations that do both with
this change.

Reviewers: krasimir, MyDeveloperDay

Subscribers: cfe-commits

Tags: #clang
2020-01-29 13:23:54 +01:00
Jonathan Coe 9d212e83e9 [clang-format] Handle quotes and escaped braces in C# interpolated strings
Summary:
This addresses issues raised in https://bugs.llvm.org/show_bug.cgi?id=44454.

There are outstanding issues with multi-line verbatim strings in C# that will be addressed in a follow-up PR.

Reviewers: krasimir, MyDeveloperDay

Reviewed By: krasimir, MyDeveloperDay

Subscribers: MyDeveloperDay

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73492
2020-01-28 14:46:27 +00:00
Martin Probst 02656f29ab clang-format: [JS] options for arrow functions.
Summary:
clang-format currently always wraps the body of non-empty arrow
functions:

    const x = () => {
      z();
    };

This change implements support for the `AllowShortLambdasOnASingleLine`
style options, controlling the indent style for arrow function bodies
that have one or fewer statements. SLS_All puts all on a single line,
SLS_Inline only arrow functions used in an inline position.

    const x = () => { z(); };

Multi-statement arrow functions continue to be wrapped. Function
expressions (`a = function() {}`) and function/method declarations are
unaffected as well.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73335
2020-01-27 16:27:25 +01:00
Krasimir Georgiev 36a8f7f6d8 [clang-format] Handle escaped " in C# string-literals
Reviewers: krasimir

Reviewed By: krasimir

Subscribers: klimek, MyDeveloperDay

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D73353
2020-01-27 12:57:20 +01:00
Sam McCall b3b68c0f80 [Format] Fix 'auto x(T&&, T &&)->F' with PAS_Left.
Summary:
An heuristic targetting `x && x->foo` was targed overly broadly and caused the
last T&& to be treated as a binary operator.

Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73334
2020-01-24 11:03:46 +01:00
Krasimir Georgiev 1e0174a93c Treat C# `using` as a control statement
Contributed by jbcoe!

Summary: Unless SpaceBeforeParensOptions is set to SBPO_Never, a space will be put between `using` and `(` in C# code.

Reviewers: klimek, MyDeveloperDay, krasimir

Reviewed By: krasimir

Subscribers: MyDeveloperDay, cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D72144
2020-01-23 13:19:55 +01:00
Martin Probst 4c9d691445 clang-format: [JS] fix `??` opreator wrapping.
Summary:
clang-format currently treats the nullish coalescing operator `??` like
the ternary operator. That causes multiple nullish terms to be each
indented relative to the last `??`, as they would in a ternary.

The `??` operator is often used in chains though, and as such more
similar to other binary operators, such as `||`. So to fix the indent,
set its token type to `||`, so it inherits the same treatment.

This opens up the question of operator precedence. However, `??` is
required to be parenthesized when mixed with `||` and `&&`, so this is
not a problem that can come up in syntactically legal code.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73026
2020-01-20 17:07:14 +01:00
mydeveloperday ea2be45254 [clang-format] Expand the SpacesAroundConditions option to include catch statements
Summary: This diff expands the SpacesAroundConditions option added in D68346 to include adding spaces to catch statements.

Reviewed By: MyDeveloperDay

Patch by: timwoj

Differential Revision: https://reviews.llvm.org/D72793
2020-01-19 15:56:04 +00:00
mydeveloperday 14c044756e [clang-format] Add IndentCaseBlocks option
Summary:
The documentation for IndentCaseLabels claimed that the "Switch
statement body is always indented one level more than case labels". This
is technically false for the code block immediately following the label.
Its closing bracket aligns with the start of the label.

If the case label are not indented, it leads to a style where the
closing bracket of the block aligns with the closing bracket of the
switch statement, which can be hard to parse.

This change introduces a new option, IndentCaseBlocks, which when true
treats the block as a scope block (which it technically is).

(Note: regenerated ClangFormatStyleOptions.rst using tools/dump_style.py)

Reviewed By: MyDeveloperDay

Patch By: capn

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D72276
2020-01-19 15:52:26 +00:00
mydeveloperday d82adf328f Allow space after C-style cast in C# code
Reviewed By: MyDeveloperDay, krasimir

Patch By: jbcoe

Differential Revision: https://reviews.llvm.org/D72150
2020-01-19 15:41:40 +00:00
Martin Probst 9835cf1590 clang-format: [JS] pragmas for tslint, tsc.
Summary:
tslint and tsc (the TypeScript compiler itself) use comment pragmas of
the style:

  // tslint:disable-next-line:foo
  // @ts-ignore

These must not be wrapped and must stay on their own line, in isolation.
For tslint, this required adding it to the pragma regexp. The comments
starting with `@` are already left alone, but this change adds test
coverage for them.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72907
2020-01-17 13:39:05 +01:00
Krasimir Georgiev 33463cfba2 clang-format: fix spacing in `operator const char*()`
Summary:
Revision a75f8d98d7 fixed spacing for operators,
but caused the const and non-const versions to diverge:
```
// With Style.PointerAlignment = FormatStyle::PAS_Left:

struct A {
  operator char*() { return ""; }
  operator const char *() const { return ""; }
};

```
The code was checking if the type specifier was directly preceded by `operator`.
However there could be comments and `const/volatile` in between.

Reviewers: mprobst

Reviewed By: mprobst

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72911
2020-01-17 13:33:41 +01:00
Martin Probst 0734fb21ed clang-format: [JS] Handle more keyword-named methods.
Summary:
Including `do`, `for`, and `while`, `if`, `else`, `try`, `catch`, in
addition to the previously handled fields. The unit test explicitly uses
methods, but this code path handles both fields and methods.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72827
2020-01-17 10:10:16 +01:00
Martin Probst 736a380212 clang-format: [JS] tests for async wrapping.
Summary:
Adds tests to ensure that `async method() ...` does not wrap between async and
the method name, which would cause automatic semicolon insertion.

Reviewers: krasimir

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70377
2020-01-16 11:23:11 +01:00
Mitchell Balan d45aafa2fb [clang-format] fix conflict between FormatStyle::BWACS_MultiLine and BeforeCatch/BeforeElse
Summary:
Found a bug introduced with BraceWrappingFlags AfterControlStatement MultiLine. This feature conflicts with the existing BeforeCatch and BeforeElse flags.

For example, our team uses BeforeElse.

if (foo ||
    bar) {
  doSomething();
}
else {
  doSomethingElse();
}

If we enable MultiLine (which we'd really love to do) we expect it to work like this:

if (foo ||
    bar)
{
  doSomething();
}
else {
  doSomethingElse();
}

What we actually get is:

if (foo ||
    bar)
{
  doSomething();
}
else
{
  doSomethingElse();
}

Reviewers: MyDeveloperDay, Bouska, mitchell-stellar

Patch by: pastey

Subscribers: Bouska, cfe-commits

Tags: clang

Differential Revision: https://reviews.llvm.org/D71939
2020-01-06 09:21:41 -05:00
Nico Weber ba3484c051 [clang-format/java] format multiple qualified annotations on one declaration better
Before:
    class Foo {
      @CommandLineFlags
          .Add
          @Features.foo
          public void test() {}
    }

Now:
    class Foo {
        @Features.foo
        @CommandLineFlags.Add
        public void test() { }
    }

See also https://crbug.com/1034115
2020-01-03 12:11:44 -05:00