Skip to content

Commit 4dc6b22

Browse files
committed
build(tools): update R linter and fixture files for lintr compatibility
Replace `require` with `requireNamespace` when checking for the lintr package, add `warnPartialMatchDollar` option, remove `extraction_operator_linter` from defaults, and update `undesirable_function_linter` to reference `lintr::default_undesirable_functions`. Update R test fixture files to use single quotes and integer literals to reflect updated linting rules. --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 393dad7 commit 4dc6b22

3 files changed

Lines changed: 44 additions & 44 deletions

File tree

  • lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures
  • tools/lint/r

lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/bad/file.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ options( digits = 16L );
99
#' main();
1010
main <- function() {
1111
# Define benchmark parameters:
12-
name <- "abs";
12+
name <- 'abs';
1313
iterations <- 1000000L;
1414
repeats <- 3L;
1515

@@ -18,7 +18,7 @@ main <- function() {
1818
#' @examples
1919
#' print_version();
2020
print_version <- function() {
21-
cat( "TAP version 13\n" );
21+
cat( 'TAP version 13\n' );
2222
}
2323

2424
#' Print the TAP summary.
@@ -29,12 +29,12 @@ main <- function() {
2929
#' @examples
3030
#' print_summary( 3, 3 );
3131
print_summary <- function( total, passing ) {
32-
cat( "#\n" );
33-
cat( paste0( "1..", total, "\n" ) ); # TAP plan
34-
cat( paste0( "# total ", total, "\n" ) );
35-
cat( paste0( "# pass ", passing, "\n" ) );
36-
cat( "#\n" );
37-
cat( "# ok\n" );
32+
cat( '#\n' );
33+
cat( paste0( '1..', total, '\n' ) ); # TAP plan
34+
cat( paste0( '# total ', total, '\n' ) );
35+
cat( paste0( '# pass ', passing, '\n' ) );
36+
cat( '#\n' );
37+
cat( '# ok\n' );
3838
}
3939

4040
#' Print benchmark results.
@@ -46,18 +46,18 @@ main <- function() {
4646
#' print_results( 10000L, 0.131009101868 );
4747
print_results <- function( iterations, elapsed ) {
4848
rate <- iterations / elapsed;
49-
cat( " ---\n" );
50-
cat( paste0( " iterations: ", iterations, "\n" ) );
51-
cat( paste0( " elapsed: ", elapsed, "\n" ) );
52-
cat( paste0( " rate: ", rate, "\n" ) );
53-
cat( " ...\n" );
49+
cat( ' ---\n' );
50+
cat( paste0( ' iterations: ', iterations, '\n' ) );
51+
cat( paste0( ' elapsed: ', elapsed, '\n' ) );
52+
cat( paste0( ' rate: ', rate, '\n' ) );
53+
cat( ' ...\n' );
5454
}
5555

5656
#' Run a benchmark.
5757
#'
5858
#' ## Notes
5959
#'
60-
#' * We compute and return a total "elapsed" time, rather than the minimum
60+
#' * We compute and return a total 'elapsed' time, rather than the minimum
6161
#' evaluation time, to match benchmark results in other languages (e.g.,
6262
#' Python).
6363
#'
@@ -69,9 +69,9 @@ main <- function() {
6969
#' elapsed <- benchmark( 10000L );
7070
benchmark <- function( iterations ) {
7171
# Run the benchmarks:
72-
results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1)) - 500.0 ), times = iterations );
72+
results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1L)) - 500.0 ), times = iterations );
7373

74-
# Sum all the raw timing results to get a total "elapsed" time:
74+
# Sum all the raw timing results to get a total 'elapsed' time:
7575
elapsed <- sum( results$time );
7676

7777
# Convert the elapsed time from nanoseconds to seconds:
@@ -81,11 +81,11 @@ main <- function() {
8181
}
8282

8383
print_version();
84-
for ( i in 1:repeats ) {
85-
cat( paste0( "# r::", name, "\n" ) );
84+
for ( i in 1L:repeats ) {
85+
cat( paste0( '# r::', name, '\n' ) );
8686
elapsed <- benchmark( iterations );
8787
print_results( iterations, elapsed );
88-
cat( paste0( "ok ", i, " benchmark finished", "\n" ) );
88+
cat( paste0( 'ok ', i, ' benchmark finished', '\n' ) );
8989
}
9090
print_summary( repeats, repeats );
9191
}

lib/node_modules/@stdlib/_tools/lint/license-header-file-list/test/fixtures/good/file.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ options( digits = 16L );
2525
#' main();
2626
main <- function() {
2727
# Define benchmark parameters:
28-
name <- "abs";
28+
name <- 'abs';
2929
iterations <- 1000000L;
3030
repeats <- 3L;
3131

@@ -34,7 +34,7 @@ main <- function() {
3434
#' @examples
3535
#' print_version();
3636
print_version <- function() {
37-
cat( "TAP version 13\n" );
37+
cat( 'TAP version 13\n' );
3838
}
3939

4040
#' Print the TAP summary.
@@ -45,12 +45,12 @@ main <- function() {
4545
#' @examples
4646
#' print_summary( 3, 3 );
4747
print_summary <- function( total, passing ) {
48-
cat( "#\n" );
49-
cat( paste0( "1..", total, "\n" ) ); # TAP plan
50-
cat( paste0( "# total ", total, "\n" ) );
51-
cat( paste0( "# pass ", passing, "\n" ) );
52-
cat( "#\n" );
53-
cat( "# ok\n" );
48+
cat( '#\n' );
49+
cat( paste0( '1..', total, '\n' ) ); # TAP plan
50+
cat( paste0( '# total ', total, '\n' ) );
51+
cat( paste0( '# pass ', passing, '\n' ) );
52+
cat( '#\n' );
53+
cat( '# ok\n' );
5454
}
5555

5656
#' Print benchmark results.
@@ -62,18 +62,18 @@ main <- function() {
6262
#' print_results( 10000L, 0.131009101868 );
6363
print_results <- function( iterations, elapsed ) {
6464
rate <- iterations / elapsed;
65-
cat( " ---\n" );
66-
cat( paste0( " iterations: ", iterations, "\n" ) );
67-
cat( paste0( " elapsed: ", elapsed, "\n" ) );
68-
cat( paste0( " rate: ", rate, "\n" ) );
69-
cat( " ...\n" );
65+
cat( ' ---\n' );
66+
cat( paste0( ' iterations: ', iterations, '\n' ) );
67+
cat( paste0( ' elapsed: ', elapsed, '\n' ) );
68+
cat( paste0( ' rate: ', rate, '\n' ) );
69+
cat( ' ...\n' );
7070
}
7171

7272
#' Run a benchmark.
7373
#'
7474
#' ## Notes
7575
#'
76-
#' * We compute and return a total "elapsed" time, rather than the minimum
76+
#' * We compute and return a total 'elapsed' time, rather than the minimum
7777
#' evaluation time, to match benchmark results in other languages (e.g.,
7878
#' Python).
7979
#'
@@ -85,9 +85,9 @@ main <- function() {
8585
#' elapsed <- benchmark( 10000L );
8686
benchmark <- function( iterations ) {
8787
# Run the benchmarks:
88-
results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1)) - 500.0 ), times = iterations );
88+
results <- microbenchmark::microbenchmark( abs( (1000.0*runif(1L)) - 500.0 ), times = iterations );
8989

90-
# Sum all the raw timing results to get a total "elapsed" time:
90+
# Sum all the raw timing results to get a total 'elapsed' time:
9191
elapsed <- sum( results$time );
9292

9393
# Convert the elapsed time from nanoseconds to seconds:
@@ -97,11 +97,11 @@ main <- function() {
9797
}
9898

9999
print_version();
100-
for ( i in 1:repeats ) {
101-
cat( paste0( "# r::", name, "\n" ) );
100+
for ( i in 1L:repeats ) {
101+
cat( paste0( '# r::', name, '\n' ) );
102102
elapsed <- benchmark( iterations );
103103
print_results( iterations, elapsed );
104-
cat( paste0( "ok ", i, " benchmark finished", "\n" ) );
104+
cat( paste0( 'ok ', i, ' benchmark finished', '\n' ) );
105105
}
106106
print_summary( repeats, repeats );
107107
}

tools/lint/r/linter.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# [1]: https://github.com/jimhester/lintr
2626

2727
# Ensure that the `lintr` package is installed...
28-
if ( !require( 'lintr', quietly = TRUE, character.only = TRUE ) ) {
28+
if ( !requireNamespace( 'lintr', quietly = TRUE ) ) {
2929
install.packages( 'lintr', repos = 'http://lib.stat.cmu.edu/R/CRAN/', quiet = TRUE );
3030
}
3131

@@ -38,8 +38,11 @@ if ( n == 0L ) {
3838
stop( 'Must provide at least one file to lint.', call. = FALSE );
3939
}
4040

41+
# Warn on partial `$` matches as replacement for deprecated `extraction_operator_linter`:
42+
options(warnPartialMatchDollar = TRUE)
43+
4144
# Specify which linters to use...
42-
linters <- lintr::linters_with_defaults( defaults = default_linters,
45+
linters <- lintr::linters_with_defaults(
4346
# Check that no absolute paths are used:
4447
absolute_path_linter = lintr::absolute_path_linter(),
4548

@@ -52,9 +55,6 @@ linters <- lintr::linters_with_defaults( defaults = default_linters,
5255
# Allow commented code outside roxygen blocks:
5356
commented_code_linter = NULL, # lintr::commented_code_linter,
5457

55-
# Require the `[[` operator is used when extracting a single element from an object, not `[` (subsetting) or `$` (interactive use):
56-
extraction_operator_linter = lintr::extraction_operator_linter(),
57-
5858
# Require that integers are explicitly typed using the form `1L` instead of `1`:
5959
implicit_integer_linter = lintr::implicit_integer_linter(),
6060

@@ -111,7 +111,7 @@ linters <- lintr::linters_with_defaults( defaults = default_linters,
111111
T_and_F_symbol_linter = lintr::T_and_F_symbol_linter(),
112112

113113
# Report the use of undesirable functions (e.g., `attach` or `sapply`) and suggest an alternative:
114-
undesirable_function_linter = lintr::undesirable_function_linter( fun = within( default_undesirable_functions, rm( options ) ) ),
114+
undesirable_function_linter = lintr::undesirable_function_linter( fun = within( lintr::default_undesirable_functions, rm( options ) ) ),
115115

116116
# Report the use of undesirable operators (e.g., `:::` or `<<-`) and suggest an alternative:
117117
undesirable_operator_linter = lintr::undesirable_operator_linter(),

0 commit comments

Comments
 (0)