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

[Dev] Add language aliases to clang-format (introduce language specific reformatting) #44528

Closed
hiroyuki-sato opened this issue Oct 24, 2024 · 1 comment

Comments

@hiroyuki-sato
Copy link
Contributor

hiroyuki-sato commented Oct 24, 2024

Describe the enhancement requested

The pre-commit command has the feature format the source.
It will be more useful if the pre-commit commands support reformatting the code for specific languages only.

Current behavior.

For example,
There are three wrong format files.

% git status .
On branch pre-commit
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   c_glib/arrow-glib/basic-data-type.cpp
	modified:   cpp/src/arrow/type.cc
	modified:   r/src/dataset.cpp
no changes added to commit (use "git add" and/or "git commit -a")

pre-commit run --color=always --all-files check and reformat codes in all sub directories.

pre-commit run --color=always --all-files
Release Audit Tool.......................................................Passed
Docker Format............................................................Failed
- hook id: hadolint-docker
- exit code: 125

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

Python Format............................................................Passed
cython-lint..............................................................Passed
C++ Format...............................................................Failed
- hook id: clang-format
- files were modified by this hook
C++ Lint.................................................................Passed
C/GLib Format............................................................Failed
- hook id: clang-format
- files were modified by this hook
MATLAB (C++) Format......................................................Passed
Python (C++) Format......................................................Passed
R (C++) Format...........................................................Failed
- hook id: clang-format
- files were modified by this hook
CMake Format.............................................................Passed
Sphinx Lint..............................................................Passed

The tree files have been reformated by the pre-commit command.

% git status .
On branch pre-commit
nothing to commit, working tree clean

New commands

For example, the following command reformat codes in c_glib directory only.

% pre-commit run --color=always --all-files c-glib-cpp-format
C/GLib Format............................................................Failed
- hook id: clang-format
- files were modified by this hook

r and cpp directories don't change the code.

% git status .
On branch pre-commit
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   cpp/src/arrow/type.cc
	modified:   r/src/dataset.cpp

no changes added to commit (use "git add" and/or "git commit -a")

This command reformat codes in the r subdirectory only.

pre-commit run --color=always --all-files r-format
R (C++) Format...........................................................Failed
- hook id: clang-format
- files were modified by this hook
git status .
On branch pre-commit
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   c_glib/arrow-glib/basic-data-type.cpp
	modified:   cpp/src/arrow/type.cc

no changes added to commit (use "git add" and/or "git commit -a")

Component(s)

Developer Tools

hiroyuki-sato added a commit to hiroyuki-sato/arrow that referenced this issue Oct 24, 2024
Co-Authored-by: Sutou Kouhei <kou@ clear-code.com>
@hiroyuki-sato hiroyuki-sato changed the title Add language aliases to clang-format (introduce language specific reformatting) [Dev] Add language aliases to clang-format (introduce language specific reformatting) Oct 24, 2024
hiroyuki-sato added a commit to hiroyuki-sato/arrow that referenced this issue Oct 25, 2024
kou pushed a commit that referenced this issue Oct 25, 2024
…ng (#44529)

### Rationale for this change

This change implements GH-44528.

`pre-commit run --color=always --all-files c-glib-cpp-format`

Languages:  
* C++ (`cpp-format`)
* c_glib(`c-glib-cpp-format`)
* MATLAB(`matlab-cpp-format`)
* Python (`python-cpp-format`)
* R(`r-cpp-format`)

### What changes are included in this PR?

Add aliases to the `clang-format` in the pre-commit configuration file.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.

* GitHub Issue: #44528

Authored-by: Hiroyuki Sato <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
@kou kou added this to the 19.0.0 milestone Oct 25, 2024
@kou
Copy link
Member

kou commented Oct 25, 2024

Issue resolved by pull request 44529
#44529

@kou kou closed this as completed Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants