Skip to content

clang-format adds spurious binding to JSON file with DisableFormat: true #52705

@Andrew-William-Smith

Description

@Andrew-William-Smith

With clang-format built from the head of main and the following .clang-format file, which should fully disable formatting for JSON files:

---
Language: Json
DisableFormat: true

The following file:

{
  "key": "value"
}

Is reformatted as follows, with a spurious binding that results in invalid JSON:

x = {
  "key": "value"
}

With DisableFormat: false or no .clang-format file at all, the binding is not added to the file.


Research note: This issue is a result of the way that clang-format implements JSON formatting by adding a binding to the top-level object in order to force clang::format to treat the code as plain JavaScript. I have already tracked down the issue and am currently preparing a patch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorclang-formatgood first issuehttps://github.com/llvm/llvm-project/contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions