Skip to content

Commit 80805a1

Browse files
authored
[CI] Move some CI linting jobs to pre-commit (#11953)
1 parent e44af1f commit 80805a1

5 files changed

Lines changed: 26 additions & 45 deletions

File tree

.github/workflows/lint.yml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,3 @@ jobs:
5151
shell: bash -el {0}
5252
run: |
5353
python ops/script/lint_python.py --format=0 --type-check=0 --pylint=1
54-
55-
cpp-lint:
56-
runs-on: ubuntu-latest
57-
name: Code linting for C++
58-
steps:
59-
- uses: actions/checkout@v4
60-
with:
61-
submodules: 'true'
62-
- uses: actions/setup-python@v5
63-
with:
64-
python-version: "3.10"
65-
architecture: 'x64'
66-
- name: Install Python packages
67-
run: |
68-
python -m pip install wheel setuptools cmakelint cpplint==1.6.1 pylint
69-
- name: Run lint
70-
run: |
71-
python3 ops/script/lint_cpp.py
72-
bash ops/script/lint_cmake.sh

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ permissions:
77

88
jobs:
99
pre-commit:
10-
name: Run pre-commit (non-blocking)
10+
name: Run pre-commit
1111
runs-on: ubuntu-latest
12-
continue-on-error: true
1312
steps:
1413
- uses: actions/checkout@v4
1514
with:

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,23 @@ repos:
1212
- id: check-executables-have-shebangs
1313
- id: check-shebang-scripts-are-executable
1414
- id: mixed-line-ending
15+
- repo: local
16+
hooks:
17+
- id: lint-cpp
18+
name: C++ lint (cpplint)
19+
entry: python ops/script/lint_cpp.py
20+
language: python
21+
types: [file]
22+
files: \.(cc|c|cpp|h|cu|hpp)$
23+
exclude: (dmlc-core|gputreeshap)
24+
additional_dependencies:
25+
- cpplint==1.6.1
26+
- id: lint-cmake
27+
name: CMake lint (cmakelint)
28+
entry: cmakelint --linelength=120 --filter=-convention/filename,-package/stdargs,-readability/wonkycase
29+
language: python
30+
types: [file]
31+
files: (CMakeLists\.txt$|^cmake/.*\.cmake$)
32+
exclude: (dmlc-core|gputreeshap)
33+
additional_dependencies:
34+
- cmakelint

doc/contrib/coding_guide.rst

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ Running Formatting Checks Locally
116116
Once you submit a pull request to `dmlc/xgboost <https://github.com/dmlc/xgboost>`_, we perform
117117
two automatic checks to enforce coding style conventions. To expedite the code review process, you are encouraged to run the checks locally on your machine prior to submitting your pull request.
118118

119-
Pre-commit (Optional)
120-
=====================
121-
We provide a minimal `pre-commit <https://pre-commit.com/>`_ configuration for basic whitespace
122-
and file-sanity checks. It only runs on changed files by default.
119+
Pre-commit
120+
==========
121+
We provide a `pre-commit <https://pre-commit.com/>`_ configuration for basic formatting and
122+
file-sanity checks. It only runs on changed files by default, and the same checks run in CI
123+
as a required (blocking) job.
123124

124125
To enable it locally:
125126

@@ -169,12 +170,6 @@ To run checks for cpplint locally:
169170
python ./ops/script/lint_cpp.py
170171
171172
172-
See next section for clang-tidy. For CMake scripts:
173-
174-
.. code-block:: bash
175-
176-
bash ./ops/script/lint_cmake.sh
177-
178173
Lastly, the linter for jvm-packages is integrated into the maven build process.
179174

180175

ops/script/lint_cmake.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)