-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow for
flint
and fix some lints (#313)
- Loading branch information
1 parent
c035d95
commit 81f772e
Showing
63 changed files
with
2,233 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,7 @@ | |
^.lintr$ | ||
man-roxygen | ||
^inst/NEWS\.Rd$ | ||
|
||
|
||
# flint files | ||
^flint$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
name: flint | ||
|
||
jobs: | ||
flint: | ||
runs-on: macOS-latest | ||
# Only restrict concurrency for non-PR jobs | ||
concurrency: | ||
group: flint-${{ github.event_name != 'pull_request' || github.run_id }} | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
|
||
- name: Install flint | ||
run: install.packages("flint", repos = c("https://etiennebacher.r-universe.dev/", getOption("repos"))) | ||
shell: Rscript {0} | ||
|
||
- name: Run flint | ||
run: flint::lint() | ||
shell: Rscript {0} | ||
env: | ||
FLINT_ERROR_ON_LINT: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,6 +237,7 @@ | |
close(connection) | ||
}, | ||
warning = function(w) { | ||
# flint-ignore | ||
is_404 <<- grepl("404", w) | ||
} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
keep: | ||
- any_duplicated | ||
- any_is_na | ||
- class_equals | ||
- condition_message | ||
- double_assignment | ||
- duplicate_argument | ||
- empty_assignment | ||
- equal_assignment | ||
- equals_na | ||
- expect_comparison | ||
- expect_identical | ||
- expect_length | ||
- expect_named | ||
- expect_not | ||
- expect_null | ||
- expect_true_false | ||
- expect_type | ||
- for_loop_index | ||
- function_return | ||
- implicit_assignment | ||
- is_numeric | ||
- length_levels | ||
- length_test | ||
- lengths | ||
- library_call | ||
- list_comparison | ||
- literal_coercion | ||
- matrix_apply | ||
- missing_argument | ||
- nested_ifelse | ||
- numeric_leading_zero | ||
- outer_negation | ||
- package_hooks | ||
- paste | ||
- redundant_equals | ||
- redundant_ifelse | ||
- rep_len | ||
- right_assignment | ||
- sample_int | ||
- semicolon | ||
- seq | ||
- sort | ||
- stopifnot_all | ||
- T_and_F_symbol | ||
- undesirable_function | ||
- undesirable_operator | ||
- unnecessary_nesting | ||
- which_grepl | ||
|
||
exclude: | ||
- todo_comment | ||
- unreachable_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
id: true_false_symbol | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: T | ||
kind: identifier | ||
not: | ||
any: | ||
- precedes: | ||
any: | ||
- pattern: <- | ||
- pattern: = | ||
- regex: ^~$ | ||
- follows: | ||
any: | ||
- pattern: $ | ||
- regex: ^~$ | ||
- inside: | ||
any: | ||
- kind: parameter | ||
- kind: call | ||
- kind: binary_operator | ||
follows: | ||
regex: ^~$ | ||
stopBy: end | ||
stopBy: | ||
kind: | ||
argument | ||
fix: TRUE | ||
message: Use TRUE instead of the symbol T. | ||
|
||
--- | ||
|
||
id: true_false_symbol-2 | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: F | ||
kind: identifier | ||
not: | ||
any: | ||
- precedes: | ||
any: | ||
- pattern: <- | ||
- pattern: = | ||
- regex: ^~$ | ||
- follows: | ||
any: | ||
- pattern: $ | ||
- regex: ^~$ | ||
- inside: | ||
any: | ||
- kind: parameter | ||
- kind: call | ||
- kind: binary_operator | ||
follows: | ||
regex: ^~$ | ||
stopBy: end | ||
stopBy: | ||
kind: | ||
argument | ||
fix: FALSE | ||
message: Use FALSE instead of the symbol F. | ||
|
||
--- | ||
|
||
id: true_false_symbol-3 | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: T | ||
kind: identifier | ||
precedes: | ||
any: | ||
- pattern: <- | ||
- pattern: = | ||
not: | ||
inside: | ||
kind: argument | ||
message: Don't use T as a variable name, as it can break code relying on T being TRUE. | ||
|
||
--- | ||
|
||
id: true_false_symbol-4 | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: F | ||
kind: identifier | ||
precedes: | ||
any: | ||
- pattern: <- | ||
- pattern: = | ||
not: | ||
inside: | ||
kind: argument | ||
message: Don't use F as a variable name, as it can break code relying on F being FALSE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# id: absolute_path-1 | ||
# language: r | ||
# severity: warning | ||
# rule: | ||
# kind: string_content | ||
# any: | ||
# - regex: '^~[[:alpha:]]' | ||
# - regex: '^~/[[:alpha:]]' | ||
# - regex: '^[[:alpha:]]:' | ||
# - regex: '^(/|~)$' | ||
# - regex: '^/[[:alpha:]]' | ||
# - regex: '^\\' | ||
# message: Do not use absolute paths. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
id: any_duplicated-1 | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: any($$$ duplicated($MYVAR) $$$) | ||
fix: anyDuplicated(~~MYVAR~~) > 0 | ||
message: anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...). | ||
|
||
--- | ||
|
||
id: any_duplicated-2 | ||
language: r | ||
severity: warning | ||
rule: | ||
any: | ||
- pattern: length(unique($MYVAR)) == length($MYVAR) | ||
- pattern: length($MYVAR) == length(unique($MYVAR)) | ||
fix: anyDuplicated(~~MYVAR~~) == 0L | ||
message: anyDuplicated(x) == 0L is better than length(unique(x)) == length(x). | ||
|
||
--- | ||
|
||
id: any_duplicated-3 | ||
language: r | ||
severity: warning | ||
rule: | ||
pattern: length(unique($MYVAR)) != length($MYVAR) | ||
fix: anyDuplicated(~~MYVAR~~) != 0L | ||
message: | | ||
Use anyDuplicated(x) != 0L (or > or <) instead of length(unique(x)) != length(x) | ||
(or > or <). | ||
--- | ||
|
||
id: any_duplicated-4 | ||
language: r | ||
severity: warning | ||
rule: | ||
any: | ||
- pattern: nrow($DATA) != length(unique($DATA$µCOL)) | ||
- pattern: length(unique($DATA$µCOL)) != nrow($DATA) | ||
fix: anyDuplicated(~~DATA~~$~~COL~~) != 0L | ||
message: | | ||
anyDuplicated(DF$col) != 0L is better than length(unique(DF$col)) != nrow(DF) | ||
--- | ||
|
||
# id: any_duplicated-5 | ||
# language: r | ||
# severity: warning | ||
# rule: | ||
# any: | ||
# - pattern: | ||
# context: nrow($DATA) != length(unique($DATA[["µCOL"]])) | ||
# strictness: ast | ||
# - pattern: | ||
# context: length(unique($DATA[["µCOL"]])) != nrow($DATA) | ||
# strictness: ast | ||
# fix: anyDuplicated(~~DATA~~[["~~COL~~"]]) != 0L | ||
# message: | | ||
# anyDuplicated(DF[["col"]]) != 0L is better than length(unique(DF[["col"]])) != nrow(DF) | ||
# | ||
# --- | ||
|
||
id: any_duplicated-6 | ||
language: r | ||
severity: warning | ||
rule: | ||
any: | ||
- pattern: nrow($DATA) == length(unique($DATA$µCOL)) | ||
- pattern: length(unique($DATA$µCOL)) == nrow($DATA) | ||
fix: anyDuplicated(~~DATA~~$~~COL~~) == 0L | ||
message: | | ||
anyDuplicated(DF$col) == 0L is better than length(unique(DF$col)) == nrow(DF) | ||
# --- | ||
# | ||
# id: any_duplicated-7 | ||
# language: r | ||
# severity: warning | ||
# rule: | ||
# any: | ||
# - pattern: | ||
# context: nrow($DATA) == length(unique($DATA[["µCOL"]])) | ||
# strictness: ast | ||
# - pattern: | ||
# context: length(unique($DATA[["µCOL"]])) == nrow($DATA) | ||
# strictness: ast | ||
# fix: anyDuplicated(~~DATA~~[["~~COL~~"]]) == 0L | ||
# message: | | ||
# anyDuplicated(DF[["col"]]) == 0L is better than length(unique(DF[["col"]])) == nrow(DF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
id: any_na-1 | ||
language: r | ||
severity: warning | ||
rule: | ||
any: | ||
- pattern: any(is.na($MYVAR)) | ||
- pattern: any(na.rm = $NARM, is.na($MYVAR)) | ||
- pattern: any(is.na($MYVAR), na.rm = $NARM) | ||
fix: anyNA(~~MYVAR~~) | ||
message: anyNA(x) is better than any(is.na(x)). | ||
|
||
--- | ||
|
||
id: any_na-2 | ||
language: r | ||
severity: warning | ||
rule: | ||
any: | ||
- pattern: NA %in% $ELEM | ||
- pattern: NA_real_ %in% $ELEM | ||
- pattern: NA_logical_ %in% $ELEM | ||
- pattern: NA_character_ %in% $ELEM | ||
- pattern: NA_complex_ %in% $ELEM | ||
fix: anyNA(~~ELEM~~) | ||
message: anyNA(x) is better than NA %in% x. |
Oops, something went wrong.