Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy with --export-fixes doesn't apply formatting (but it works with --fix) #55569

Closed
sean-mcmanus opened this issue May 18, 2022 · 3 comments
Labels
clang-tidy question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@sean-mcmanus
Copy link

sean-mcmanus commented May 18, 2022

I'm using clang-tidy 14.0.3 (on Windows 11, I could try Linux/Mac if you want, but I assume it doesn't matter).

Use test.cpp

int main()
{
    if (true)
        return 0;
}

with some .clang-format file in the folder like

BasedOnStyle: LLVM
UseTab: Never
IndentWidth: 4
TabWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
AccessModifierOffset: -4
NamespaceIndentation: All
FixNamespaceComments: false
SeparateDefinitionBlocks: Always

and run clang-tidy.exe --config="{Checks: 'readability-braces-around-statements', FormatStyle: file}" --export-fixes=<path>/out.yaml <path>/test.cpp --

Bug: The out.yaml is

---
MainSourceFile:  '<path>/test.cpp'
Diagnostics:
  - DiagnosticName:  readability-braces-around-statements
    DiagnosticMessage:
      Message:         statement should be inside braces
      FilePath:        '<path>/test.cpp'
      FileOffset:      30
      Replacements:
        - FilePath:        '<path>/test.cpp'
          Offset:          30
          Length:          0
          ReplacementText: ' {'
        - FilePath:        '<path>/test.cpp'
          Offset:          49
          Length:          0
          ReplacementText: "\n}"
    Level:           Warning
    BuildDirectory:  '<path>'
...

which doesn't have the formatting applied -- in particular, the } has no indentation.

The bug doesn't repro when --export-fixes isn't used: clang-tidy.exe --config="{Checks: 'readability-braces-around-statements', FormatStyle: file}" --fix <path>/test.cpp -- gives the expected result:


int main()
{
    if (true)
    {
        return 0;
    }
}

It also repros with clang-tidy.exe --config="{Checks: 'modernize-concat-nested-namespaces', FormatStyle: file}" --export-fixes=<path>/out.yaml <path>/test.cpp -- -std=c++17.

with test.cpp

namespace foo1
{
    namespace foo2
    {
        int i;
    }
}

so it seems like it may repro with all checks.

I'm guessing we could work around the issue via running clang-format on the edited lines afterwards.

@sean-mcmanus sean-mcmanus changed the title clang-tidy with --export-fixes doesn't apply formatting with readability-braces-around-statements (but it works with --fix) clang-tidy with --export-fixes doesn't apply formatting (but it works with --fix) May 18, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented May 18, 2022

@llvm/issue-subscribers-clang-tidy

@njames93
Copy link
Member

The --export-fixes option isn't meant to format any changes.
The idea is the formatting is done after all the fixes have been applied, using clang-apply-replacements.

@sean-mcmanus
Copy link
Author

Ok.

@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

4 participants