Skip to content

Commit 6c5c296

Browse files
committed
code-quality: switch lint-md to .ci/lint.R
1 parent 30f947e commit 6c5c296

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

.ci/linters/md/heading_id_linter.R

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
any_mismatch = FALSE
2-
31
# ensure that ids are limited to alphanumerics and dashes
42
# (in particular, dots and underscores break the links)
53
check_header_ids = function(md) {
4+
if (!grepl('[.]Rmd$', md)) return()
5+
md = readLines(md)
66
# A bit surprisingly, some headings don't start with a letter.
77
# We're interested in those that set an id to link to, i.e., end with {#id}.
88
heading_captures = regmatches(md, regexec("^#+ \\S.*[{]#([^}]*)[}]$", md))
@@ -14,13 +14,5 @@ check_header_ids = function(md) {
1414
"On line %d, bad heading id '%s':\n%s\n",
1515
line, heading_captures[[line]][2], heading_captures[[line]][1]
1616
))
17-
!all(good_ids)
17+
stopifnot('Please fix the vignette issues above' = all(good_ids))
1818
}
19-
20-
any_error = FALSE
21-
for (vignette in list.files('vignettes', pattern = "[.]Rmd$", recursive = TRUE, full.name = TRUE)) {
22-
cat(sprintf("Checking vignette file %s...\n", vignette))
23-
rmd_lines = readLines(vignette)
24-
any_error = check_header_ids(rmd_lines) || any_error
25-
}
26-
if (any_error) stop("Please fix the vignette issues above.")

.ci/linters/md/news_linter.R

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
any_mismatch = FALSE
2-
31
# ensure that numbered list in each section is in sequence
42
check_section_numbering = function(news) {
3+
if (!grepl("NEWS", news)) return()
4+
news = readLines(news)
55
# plain '#' catches some examples; 'd' for 'data.table'
66
sections = grep("^#+ [A-Zd]", news)
77
entries = grep("^[0-9]+[.]", news)
88
entry_value = as.integer(gsub("^([0-9]+)[.].*", "\\1", news[entries]))
99
section_id = findInterval(entries, sections)
10-
10+
1111
any_mismatch = FALSE
1212
for (id in unique(section_id)) {
1313
section_entries = entry_value[section_id == id]
@@ -22,11 +22,12 @@ check_section_numbering = function(news) {
2222
paste0(" [", section_entries[!matched], " --> ", intended_value[!matched], "]", collapse="\n")
2323
))
2424
}
25-
return(any_mismatch)
25+
stopifnot("Please fix the issues above" = !any_mismatch)
2626
}
2727

2828
# ensure that GitHub link text & URL actually agree
2929
check_gh_links = function(news) {
30+
news = readLines(news)
3031
gh_links_info = gregexpr(
3132
"\\[#(?<md_number>[0-9]+)\\]\\(https://github.com/Rdatatable/data.table/(?<link_type>[^/]+)/(?<link_number>[0-9]+)\\)",
3233
news,
@@ -48,14 +49,5 @@ check_gh_links = function(news) {
4849
"In line %d, link pointing to %s %s is written #%s\n",
4950
line_number, link_type, link_number, md_number
5051
)))
51-
return(TRUE)
52-
}
53-
54-
any_error = FALSE
55-
for (news in list.files(pattern = "NEWS")) {
56-
cat(sprintf("Checking NEWS file %s...\n", news))
57-
news_lines = readLines(news)
58-
any_error = check_section_numbering(news_lines) || any_error
59-
any_error = check_gh_links(news_lines) || any_error
52+
stop("Please fix the issues above.")
6053
}
61-
if (any_error) stop("Please fix the NEWS issues above.")

.github/workflows/code-quality.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,4 @@ jobs:
7373
- uses: actions/checkout@v4
7474
- uses: r-lib/actions/setup-r@v2
7575
- name: Lint
76-
run: for (f in list.files('.ci/linters/md', full.names=TRUE)) source(f)
77-
shell: Rscript {0}
76+
run: .ci/lint.R .ci/linters/md . '[.]R?md$'

0 commit comments

Comments
 (0)