Skip to content

Commit 3e0dcc0

Browse files
committed
feat: add linter workflow job that applies linter for the languages that are used in the repo
feat: add linter configuration and 2 test files to test the linter action fix: remove error in python linter test file ci: remove format checker from python ci: add missing lowercase r extension check fix: remove error from the R code to fix pipeline ci: report only serious issues at R linter refactor: remove test files
1 parent e18a41b commit 3e0dcc0

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

.github/workflows/lint.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
# detect which languages are present
11+
detect:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
has-python: ${{ steps.check.outputs.has-python }}
15+
has-r: ${{ steps.check.outputs.has-r }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Detect languages
20+
id: check
21+
run: |
22+
if find . -name "*.py" ! -path "./.git/*" | grep -q .; then
23+
echo "has-python=true" >> $GITHUB_OUTPUT
24+
else
25+
echo "has-python=false" >> $GITHUB_OUTPUT
26+
fi
27+
28+
if find . \( -name "*.R" -o -name "*.Rmd" -o -name "*.r" -o -name "*.qmd" \) ! -path "./.git/*" | grep -q .; then
29+
echo "has-r=true" >> $GITHUB_OUTPUT
30+
else
31+
echo "has-r=false" >> $GITHUB_OUTPUT
32+
fi
33+
34+
lint-python:
35+
needs: detect
36+
if: needs.detect.outputs.has-python == 'true'
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v4
40+
- uses: astral-sh/ruff-action@v3
41+
with:
42+
args: "check ."
43+
44+
lint-r:
45+
needs: detect
46+
if: needs.detect.outputs.has-r == 'true'
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
51+
- uses: r-lib/actions/setup-r@v2
52+
with:
53+
use-public-rspm: true
54+
55+
- name: Install lintr
56+
run: Rscript -e "install.packages('lintr', repos = 'https://cloud.r-project.org')"
57+
58+
- name: Lint R files
59+
run: |
60+
Rscript -e "
61+
issues <- lintr::lint_dir('.', linters = list(
62+
lintr::object_usage_linter(),
63+
lintr::assignment_linter()
64+
))
65+
if (length(issues) > 0) {
66+
print(issues)
67+
quit(status = 1)
68+
} else {
69+
message('No linting issues found.')
70+
}
71+
"

.python-version

Whitespace-only changes.

pyproject.toml

Whitespace-only changes.

0 commit comments

Comments
 (0)