Skip to content

Commit 58364b5

Browse files
committed
Use lintr to test that endian is always specified
1 parent 9db01f1 commit 58364b5

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

.lintr

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ linters: linters_with_tags(
1010
object_usage_linter = NULL,
1111
commented_code_linter = NULL,
1212
indentation_linter = NULL,
13-
nonportable_path_linter = NULL
13+
nonportable_path_linter = NULL,
14+
endian_linter = lightr:::endian_linter()
1415
)
1516

DESCRIPTION

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Imports:
2727
Suggests:
2828
digest,
2929
knitr,
30+
lintr,
3031
pavo,
3132
rmarkdown,
3233
spelling,

R/endian_linter.R

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
endian_linter <- function() {
2+
xpath <- "
3+
//SYMBOL_FUNCTION_CALL[text() = 'readBin' or text() = 'writeBin']
4+
/parent::expr
5+
/parent::expr[not(SYMBOL_SUB[text() = 'endian'])]
6+
"
7+
8+
lintr::Linter(function(source_expression) {
9+
if (!lintr::is_lint_level(source_expression, "expression")) {
10+
return(list())
11+
}
12+
13+
xml <- source_expression$xml_parsed_content
14+
15+
bad_expr <- xml2::xml_find_all(xml, xpath)
16+
17+
lintr::xml_nodes_to_lints(
18+
bad_expr,
19+
source_expression = source_expression,
20+
lint_message = paste(
21+
xml2::xml_find_first(bad_expr, "string(.//SYMBOL_FUNCTION_CALL)"),
22+
"should always include a value for 'endian'"
23+
),
24+
type = "warning"
25+
)
26+
})
27+
}

tests/testthat/test_dev.R

-14
This file was deleted.

0 commit comments

Comments
 (0)