[PATCH] Clang-format support for removing space before assignment operators

Daniel Jasper djasper at google.com
Wed Sep 25 08:08:26 PDT 2013


Sorry, got side-tracked and forget. Will do this now.


On Tue, Sep 24, 2013 at 5:49 PM, Aaron Wishnick
<aaron.s.wishnick at gmail.com>wrote:

> Ping!
>
>
> On Fri, Sep 13, 2013 at 11:23 AM, Aaron Wishnick <
> aaron.s.wishnick at gmail.com> wrote:
>
>> Thanks. I didn't know about the auto-generation of the docs; that's
>> pretty slick. Sorry about the tabs vs. spaces; I've corrected this in my
>> editor for the future. I don't have commit access, so if you don't mind
>> fixing the style nits, I really appreciate it.
>>
>>
>> On Fri, Sep 13, 2013 at 11:19 AM, Daniel Jasper <djasper at google.com>wrote:
>>
>>> The few nits below aside, this looks good to go in. Do you have commit
>>> access or should I commit this for you? In the latter case, you don't need
>>> to worry about the style nits (I'll fix them before committing).
>>>
>>> +**SpaceBeforeAssignmentOperators** (``bool``)
>>> +  If ``false``, spaces will be removed before '=', '+=', etc.
>>> +
>>>
>>> Not, that these are actually auto-generated using a python script. It
>>> doesn't hurt like this, but it will be eventually overwritten by what is in
>>> the flags comment.
>>>
>>> +               R.SpaceAfterControlStatementKeyword &&
>>> +   SpaceBeforeAssignmentOperators ==
>>> +       R.SpaceBeforeAssignmentOperators;
>>>
>>> These seem to be indented with tabs. Use spaces instead.
>>>
>>> +  if (!Style.SpaceBeforeAssignmentOperators &&
>>> +  Tok.getPrecedence() == prec::Assignment)
>>> +    return false;
>>>
>>> Same as above.
>>>
>>> +  FormatStyle Spaces = getLLVMStyle();
>>> +
>>> +  verifyFormat("int a = 5;", Spaces);
>>>
>>> There seem to be unnecessary spaces in the empty line.
>>>
>>>
>>> On Fri, Sep 13, 2013 at 4:12 PM, Aaron Wishnick <
>>> aaron.s.wishnick at gmail.com> wrote:
>>>
>>>> Thanks for the feedback! I've addressed those three issues, and the
>>>> updated patch is attached.
>>>>
>>>>
>>>> On Fri, Sep 13, 2013 at 4:12 AM, Daniel Jasper <djasper at google.com>wrote:
>>>>
>>>>> You should be able to use "Tok.getPrecedence() == prec::Assignment"
>>>>> instead of the new IsTokenAssignment function. Also, please put the tests
>>>>> into "unittests/Format/FormatTest.cpp". We have plans to turn (some of)
>>>>> those into file-based tests, but for now, I'd like to keep
>>>>> formatting-specific tests together. Also, in addition to actually testing
>>>>> whether the style-configuration works as expected, there are also tests
>>>>> there which test whether the option can be successfully parsed from JSON
>>>>> (see how it is done for the other flags close to the bottom).
>>>>>
>>>>>
>>>>> On Fri, Sep 13, 2013 at 12:14 AM, Aaron Wishnick <
>>>>> aaron.s.wishnick at gmail.com> wrote:
>>>>>
>>>>>> My organization's coding standards include not putting a space before
>>>>>> assignment operators, e.g. "int a= 42;". In order for us to be able to use
>>>>>> clang-format, we need support for this.
>>>>>>
>>>>>> I've attached a patch that adds a new format style option,
>>>>>> "SpaceBeforeAssignmentOperators." All the existing hard-coded styles now
>>>>>> default to having it set to true. I've also included a test.
>>>>>>
>>>>>> Please let me know if this looks good, or if there's anything else I
>>>>>> can do.
>>>>>>
>>>>>> Thank you!
>>>>>> Aaron
>>>>>>
>>>>>> _______________________________________________
>>>>>> cfe-commits mailing list
>>>>>> cfe-commits at cs.uiuc.edu
>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130925/ddeb2136/attachment.html>


More information about the cfe-commits mailing list