Clang-Format: Ensure new line at the end of files #118031

Merged
Sergey Sharybin merged 1 commits from Sergey/blender:clang_format_newline into main 2024-02-09 14:32:19 +01:00

Not all editors are configured by default to ensure new line at the
end of file.

To reduce noise and make code more uniform ensure the new lines are
ensured by the clang-format.

Not all editors are configured by default to ensure new line at the end of file. To reduce noise and make code more uniform ensure the new lines are ensured by the clang-format.
Sergey Sharybin added 1 commit 2024-02-09 11:03:37 +01:00
e186ecd1ef Clang-Format: Ensure new line at the end of files
Not all editors are configured by default to ensure new line at the
end of file.

To reduce noise and make code more uniform ensure the new lines are
ensured by the clang-format.
Bastien Montagne approved these changes 2024-02-09 11:08:36 +01:00
Bastien Montagne left a comment
Owner

+1, always annoyed when this is missing...

+1, always annoyed when this is missing...

+1, always annoyed when this is missing...

Ditto

> +1, always annoyed when this is missing... Ditto
Campbell Barton approved these changes 2024-02-09 11:38:17 +01:00
Sergey Sharybin merged commit c6b6714555 into main 2024-02-09 14:32:19 +01:00
Sergey Sharybin deleted branch clang_format_newline 2024-02-09 14:32:22 +01:00

I think this should be committed to blender-v4.1-release as well, it is causing problems when merging changes into main.

For example:
blender/blender@86522d9ab1
blender/blender@0801fcd6b3

I think this should be committed to `blender-v4.1-release` as well, it is causing problems when merging changes into main. For example: blender/blender@86522d9ab1f2bdfc692d87eeec5def81885a70eb blender/blender@0801fcd6b32fc16740036558d2dab30f228e77d7

There seems to be a bug with this feature where it does the opposite, removing the new line.
https://github.com/llvm/llvm-project/issues/63150

There seems to be a bug with this feature where it does the opposite, removing the new line. https://github.com/llvm/llvm-project/issues/63150
Author
Owner

The report you've linked is about removing trailing new lines when you have multiple at the end of file. This can become more explicit configuration to ensure consistency by (so that we don't rely on default, which might change):

# Ensure single new line at the end of source files.
InsertNewlineAtEOF: True
KeepEmptyLinesAtEOF: False

The commit from Sebastian you've linked has 2 trailing new lines at the end of the sequencer_clipboard.cc file, which then got stripped down to a single new line by Bastien's cleanup.

We looked into it with Sebastian, and it seems that the clang_format.py script does not work well when the new line is inserted by clang-format, leading to extra new line adde to the vim's buffer. Using the language-server integration of clang-format does not experience this issue. I also do not experience such issue with neither make format nor VS Code with its official clang-format extension.

The proposal is:

  • Add KeepEmptyLinesAtEOF: False to the .clang-format
  • Commit the changes to 4.1
  • People using clang_format.py Vim integration need to ensure the integration properly handles new lines inserted by a formatter
The report you've linked is about removing trailing new lines when you have multiple at the end of file. This can become more explicit configuration to ensure consistency by (so that we don't rely on default, which might change): ``` # Ensure single new line at the end of source files. InsertNewlineAtEOF: True KeepEmptyLinesAtEOF: False ``` The commit from Sebastian you've linked has 2 trailing new lines at the end of the `sequencer_clipboard.cc` file, which then got stripped down to a single new line by Bastien's cleanup. We looked into it with Sebastian, and it seems that the `clang_format.py` script does not work well when the new line is inserted by `clang-format`, leading to extra new line adde to the vim's buffer. Using the language-server integration of clang-format does not experience this issue. I also do not experience such issue with neither `make format` nor VS Code with its official clang-format extension. The proposal is: - Add `KeepEmptyLinesAtEOF: False` to the `.clang-format` - Commit the changes to 4.1 - People using `clang_format.py` Vim integration need to ensure the integration properly handles new lines inserted by a formatter

To be more specific, I think that this line is the clang_format.py script is the issue:

stdout.decode(encoding).split('\n')

Here it takes the stdout from clang-format and splits it on every new line.
The script probably didn't anticipate that clang-format would insert a new line before EOF, so in this case it instead thinks that it added a new empty line at the end of the file. And thus we get double new lines.

I switched to using the LSP for formatting, and it now matches make format for me.

To be more specific, I think that this line is the `clang_format.py` script is the issue: ``` stdout.decode(encoding).split('\n') ``` Here it takes the `stdout` from clang-format and splits it on every new line. The script probably didn't anticipate that clang-format would insert a new line before EOF, so in this case it instead thinks that it added a new empty line at the end of the file. And thus we get double new lines. I switched to using the LSP for formatting, and it now matches `make format` for me.

@Sergey thanks for looking into this, what you propose sounds good to me.

@Sergey thanks for looking into this, what you propose sounds good to me.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118031
No description provided.