Skip to content

Commit 1555031

Browse files
committed
set up flir
1 parent bc711d2 commit 1555031

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2231
-0
lines changed

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@
3131
^man/dot-create_stack\.Rd$
3232
^man/dot-set_cache\.Rd$
3333
^man/dot-get_local\.Rd$
34+
35+
36+
# flir files
37+
^flir$

.github/workflows/flir.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
name: flir
13+
14+
jobs:
15+
flir:
16+
runs-on: macOS-latest
17+
# Only restrict concurrency for non-PR jobs
18+
concurrency:
19+
group: flir-${{ github.event_name != 'pull_request' || github.run_id }}
20+
env:
21+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
22+
permissions:
23+
contents: write
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: r-lib/actions/setup-r@v2
28+
29+
- name: Install flir
30+
run: install.packages("flir", repos = c("https://etiennebacher.r-universe.dev/", getOption("repos")))
31+
shell: Rscript {0}
32+
33+
- name: Run flir
34+
run: flir::lint()
35+
shell: Rscript {0}
36+
env:
37+
FLIR_ERROR_ON_LINT: true

flir/cache_file_state.rds

44 Bytes
Binary file not shown.

flir/config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
keep:
2+
- any_duplicated
3+
- any_is_na
4+
- class_equals
5+
- condition_message
6+
- double_assignment
7+
- duplicate_argument
8+
- empty_assignment
9+
- equal_assignment
10+
- equals_na
11+
- expect_comparison
12+
- expect_identical
13+
- expect_length
14+
- expect_named
15+
- expect_not
16+
- expect_null
17+
- expect_true_false
18+
- expect_type
19+
- for_loop_index
20+
- function_return
21+
- implicit_assignment
22+
- is_numeric
23+
- length_levels
24+
- length_test
25+
- lengths
26+
- library_call
27+
- list_comparison
28+
- literal_coercion
29+
- matrix_apply
30+
- missing_argument
31+
- nested_ifelse
32+
- numeric_leading_zero
33+
- outer_negation
34+
- package_hooks
35+
- paste
36+
- redundant_equals
37+
- redundant_ifelse
38+
- rep_len
39+
- right_assignment
40+
- sample_int
41+
- semicolon
42+
- seq
43+
- sort
44+
- stopifnot_all
45+
- T_and_F_symbol
46+
- todo_comment
47+
- undesirable_function
48+
- undesirable_operator
49+
- unnecessary_nesting
50+
- unreachable_code
51+
- which_grepl

flir/rules/builtin/T_and_F_symbol.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
id: true_false_symbol
2+
language: r
3+
severity: warning
4+
rule:
5+
pattern: T
6+
kind: identifier
7+
not:
8+
any:
9+
- precedes:
10+
any:
11+
- pattern: <-
12+
- pattern: =
13+
- regex: ^~$
14+
- follows:
15+
any:
16+
- pattern: $
17+
- regex: ^~$
18+
- inside:
19+
any:
20+
- kind: parameter
21+
- kind: call
22+
- kind: binary_operator
23+
follows:
24+
regex: ^~$
25+
stopBy: end
26+
stopBy:
27+
kind:
28+
argument
29+
fix: TRUE
30+
message: Use TRUE instead of the symbol T.
31+
32+
---
33+
34+
id: true_false_symbol-2
35+
language: r
36+
severity: warning
37+
rule:
38+
pattern: F
39+
kind: identifier
40+
not:
41+
any:
42+
- precedes:
43+
any:
44+
- pattern: <-
45+
- pattern: =
46+
- regex: ^~$
47+
- follows:
48+
any:
49+
- pattern: $
50+
- regex: ^~$
51+
- inside:
52+
any:
53+
- kind: parameter
54+
- kind: call
55+
- kind: binary_operator
56+
follows:
57+
regex: ^~$
58+
stopBy: end
59+
stopBy:
60+
kind:
61+
argument
62+
fix: FALSE
63+
message: Use FALSE instead of the symbol F.
64+
65+
---
66+
67+
id: true_false_symbol-3
68+
language: r
69+
severity: warning
70+
rule:
71+
pattern: T
72+
kind: identifier
73+
precedes:
74+
any:
75+
- pattern: <-
76+
- pattern: =
77+
not:
78+
inside:
79+
kind: argument
80+
message: Don't use T as a variable name, as it can break code relying on T being TRUE.
81+
82+
---
83+
84+
id: true_false_symbol-4
85+
language: r
86+
severity: warning
87+
rule:
88+
pattern: F
89+
kind: identifier
90+
precedes:
91+
any:
92+
- pattern: <-
93+
- pattern: =
94+
not:
95+
inside:
96+
kind: argument
97+
message: Don't use F as a variable name, as it can break code relying on F being FALSE.

flir/rules/builtin/absolute_path.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# id: absolute_path-1
2+
# language: r
3+
# severity: warning
4+
# rule:
5+
# kind: string_content
6+
# any:
7+
# - regex: '^~[[:alpha:]]'
8+
# - regex: '^~/[[:alpha:]]'
9+
# - regex: '^[[:alpha:]]:'
10+
# - regex: '^(/|~)$'
11+
# - regex: '^/[[:alpha:]]'
12+
# - regex: '^\\'
13+
# message: Do not use absolute paths.

flir/rules/builtin/any_duplicated.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
id: any_duplicated-1
2+
language: r
3+
severity: warning
4+
rule:
5+
pattern: any($$$ duplicated($MYVAR) $$$)
6+
fix: anyDuplicated(~~MYVAR~~) > 0
7+
message: anyDuplicated(x, ...) > 0 is better than any(duplicated(x), ...).
8+
9+
---
10+
11+
id: any_duplicated-2
12+
language: r
13+
severity: warning
14+
rule:
15+
any:
16+
- pattern: length(unique($MYVAR)) == length($MYVAR)
17+
- pattern: length($MYVAR) == length(unique($MYVAR))
18+
fix: anyDuplicated(~~MYVAR~~) == 0L
19+
message: anyDuplicated(x) == 0L is better than length(unique(x)) == length(x).
20+
21+
---
22+
23+
id: any_duplicated-3
24+
language: r
25+
severity: warning
26+
rule:
27+
pattern: length(unique($MYVAR)) != length($MYVAR)
28+
fix: anyDuplicated(~~MYVAR~~) != 0L
29+
message: |
30+
Use anyDuplicated(x) != 0L (or > or <) instead of length(unique(x)) != length(x)
31+
(or > or <).
32+
33+
---
34+
35+
id: any_duplicated-4
36+
language: r
37+
severity: warning
38+
rule:
39+
any:
40+
- pattern: nrow($DATA) != length(unique($DATA$µCOL))
41+
- pattern: length(unique($DATA$µCOL)) != nrow($DATA)
42+
fix: anyDuplicated(~~DATA~~$~~COL~~) != 0L
43+
message: |
44+
anyDuplicated(DF$col) != 0L is better than length(unique(DF$col)) != nrow(DF)
45+
46+
---
47+
48+
# id: any_duplicated-5
49+
# language: r
50+
# severity: warning
51+
# rule:
52+
# any:
53+
# - pattern:
54+
# context: nrow($DATA) != length(unique($DATA[["µCOL"]]))
55+
# strictness: ast
56+
# - pattern:
57+
# context: length(unique($DATA[["µCOL"]])) != nrow($DATA)
58+
# strictness: ast
59+
# fix: anyDuplicated(~~DATA~~[["~~COL~~"]]) != 0L
60+
# message: |
61+
# anyDuplicated(DF[["col"]]) != 0L is better than length(unique(DF[["col"]])) != nrow(DF)
62+
#
63+
# ---
64+
65+
id: any_duplicated-6
66+
language: r
67+
severity: warning
68+
rule:
69+
any:
70+
- pattern: nrow($DATA) == length(unique($DATA$µCOL))
71+
- pattern: length(unique($DATA$µCOL)) == nrow($DATA)
72+
fix: anyDuplicated(~~DATA~~$~~COL~~) == 0L
73+
message: |
74+
anyDuplicated(DF$col) == 0L is better than length(unique(DF$col)) == nrow(DF)
75+
76+
# ---
77+
#
78+
# id: any_duplicated-7
79+
# language: r
80+
# severity: warning
81+
# rule:
82+
# any:
83+
# - pattern:
84+
# context: nrow($DATA) == length(unique($DATA[["µCOL"]]))
85+
# strictness: ast
86+
# - pattern:
87+
# context: length(unique($DATA[["µCOL"]])) == nrow($DATA)
88+
# strictness: ast
89+
# fix: anyDuplicated(~~DATA~~[["~~COL~~"]]) == 0L
90+
# message: |
91+
# anyDuplicated(DF[["col"]]) == 0L is better than length(unique(DF[["col"]])) == nrow(DF)

flir/rules/builtin/any_is_na.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
id: any_na-1
2+
language: r
3+
severity: warning
4+
rule:
5+
any:
6+
- pattern: any(is.na($MYVAR))
7+
- pattern: any(na.rm = $NARM, is.na($MYVAR))
8+
- pattern: any(is.na($MYVAR), na.rm = $NARM)
9+
fix: anyNA(~~MYVAR~~)
10+
message: anyNA(x) is better than any(is.na(x)).
11+
12+
---
13+
14+
id: any_na-2
15+
language: r
16+
severity: warning
17+
rule:
18+
any:
19+
- pattern: NA %in% $ELEM
20+
- pattern: NA_real_ %in% $ELEM
21+
- pattern: NA_logical_ %in% $ELEM
22+
- pattern: NA_character_ %in% $ELEM
23+
- pattern: NA_complex_ %in% $ELEM
24+
fix: anyNA(~~ELEM~~)
25+
message: anyNA(x) is better than NA %in% x.

flir/rules/builtin/class_equals.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
id: class_equals-1
2+
language: r
3+
severity: warning
4+
rule:
5+
any:
6+
- pattern: class($VAR) == $CLASSNAME
7+
- pattern: $CLASSNAME == class($VAR)
8+
not:
9+
inside:
10+
kind: argument
11+
fix: inherits(~~VAR~~, ~~CLASSNAME~~)
12+
message: Instead of comparing class(x) with ==, use inherits(x, 'class-name') or is.<class> or is(x, 'class')
13+
14+
---
15+
16+
id: class_equals-2
17+
language: r
18+
severity: warning
19+
rule:
20+
any:
21+
- pattern: class($VAR) != $CLASSNAME
22+
- pattern: $CLASSNAME != class($VAR)
23+
not:
24+
inside:
25+
kind: argument
26+
fix: "!inherits(~~VAR~~, ~~CLASSNAME~~)"
27+
message: "Instead of comparing class(x) with !=, use !inherits(x, 'class-name') or is.<class> or is(x, 'class')"
28+
29+
---
30+
31+
id: class_equals-3
32+
language: r
33+
severity: warning
34+
rule:
35+
any:
36+
- pattern: $CLASSNAME %in% class($VAR)
37+
- pattern: class($VAR) %in% $CLASSNAME
38+
constraints:
39+
CLASSNAME:
40+
kind: string
41+
fix: inherits(~~VAR~~, ~~CLASSNAME~~)
42+
message: Instead of comparing class(x) with %in%, use inherits(x, 'class-name') or is.<class> or is(x, 'class')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: condition_message-1
2+
language: r
3+
severity: warning
4+
rule:
5+
pattern: $FUN($$$ paste0($$$MSG) $$$)
6+
kind: call
7+
not:
8+
any:
9+
- has:
10+
kind: extract_operator
11+
- has:
12+
stopBy: end
13+
kind: argument
14+
has:
15+
field: name
16+
regex: "^collapse|recycle0$"
17+
stopBy: end
18+
constraints:
19+
FUN:
20+
regex: "^(packageStartupMessage|stop|warning)$"
21+
fix: ~~FUN~~(~~MSG~~)
22+
message: |
23+
~~FUN~~(paste0(...)) can be rewritten as ~~FUN~~(...).

0 commit comments

Comments
 (0)