Skip to content

Commit 1943911

Browse files
authored
GH-46547: [CI][Dev][R] Use pre-commit for lintr (#46581)
### Rationale for this change We want to migrate to pre-commit from `archery lint`. ### What changes are included in this PR? Use pre-commit for lintr against `r/`. This doesn't use https://github.com/lorenzwalthert/precommit because it doesn't include cyclocomp that we need. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #46547 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Jacob Wujciak-Jens <[email protected]>
1 parent f88c19f commit 1943911

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

.github/workflows/dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
5454
with:
5555
python-version: 3.12
56+
- uses: r-lib/actions/setup-r@bd49c52ffe281809afa6f0fecbf37483c5dd0b93 # v2.11.3
5657
- name: Install pre-commit
5758
run: |
5859
python -m pip install pre-commit

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ repos:
166166
?.pb\.(cc|h)$|
167167
?^cpp/src/generated/|
168168
)
169+
- repo: local
170+
hooks:
171+
- id: lintr
172+
name: R Lint
173+
alias: r-lint
174+
language: r
175+
additional_dependencies:
176+
- cyclocomp
177+
- lintr
178+
entry: |
179+
Rscript r/tools/lint.R
180+
pass_filenames: false
181+
files: >-
182+
^r/.*\.(R|Rmd)$
169183
- repo: https://github.com/pre-commit/mirrors-clang-format
170184
rev: v14.0.6
171185
hooks:

r/tools/lint.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env Rscript
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
lints <- lintr::lint_package("r")
21+
if (length(lints) == 0) {
22+
q("no")
23+
}
24+
25+
print(lints)
26+
q("no", status=1)

0 commit comments

Comments
 (0)