-
Notifications
You must be signed in to change notification settings - Fork 2
/
.lintr.R
1163 lines (1068 loc) · 41.1 KB
/
.lintr.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
linters <- list(
# Description:
#
# Check that no absolute paths are used (e.g. "/var", "C:\System",
# "~/docs").
#
# Arguments:
#
# lax: Less stringent linting, leading to fewer false positives. If
# 'TRUE', only lint path strings, which
#
# • contain at least two path elements, with one having at
# least two characters and
#
# • contain only alphanumeric chars (including UTF-8),
# spaces, and win32-allowed punctuation
#
absolute_path_linter(lax = TRUE),
# Description:
#
# 'anyDuplicated()' exists as a replacement for
# 'any(duplicated(.))', which is more efficient for simple objects,
# and is at worst equally efficient. Therefore, it should be used in
# all situations instead of the latter.
#
any_duplicated_linter(),
# Description:
#
# 'anyNA()' exists as a replacement for 'any(is.na(x))' which is
# more efficient for simple objects, and is at worst equally
# efficient. Therefore, it should be used in all situations instead
# of the latter.
#
any_is_na_linter(),
# Description:
#
# Check that <- is always used for assignment.
#
# Arguments:
#
# allow_cascading_assign: Logical, default 'TRUE'. If 'FALSE', '<<-' and
# ->> are not allowed.
#
# allow_right_assign: Logical, default 'FALSE'. If 'TRUE', -> and ->> are
# allowed.
#
# allow_trailing: Logical, default 'TRUE'. If 'FALSE' then assignments
# aren't allowed at end of lines.
#
# allow_pipe_assign: Logical, default 'FALSE'. If 'TRUE', magrittr's %<>%
# assignment is allowed.
#
assignment_linter(allow_cascading_assign = TRUE, allow_right_assign = FALSE, allow_trailing = TRUE, allow_pipe_assign = FALSE),
# Description:
#
# Check for usage of unavailable functions. Not reliable for testing
# r-devel dependencies.
#
# Arguments:
#
# r_version: Minimum R version to test for compatibility
#
# except: Character vector of functions to be excluded from linting.
# Use this to list explicitly defined backports, e.g. those
# imported from the '{backports}' package or manually defined
# in your package.
#
backport_linter(r_version = getRversion(), except = character()),
# Description:
#
# 'length(which(x == y)) == 0' is the same as '!any(x == y)', but
# the latter is more readable and more efficient.
#
boolean_arithmetic_linter(),
# Description:
#
# Perform various style checks related to placement and spacing of
# curly braces:
#
# Arguments:
#
# allow_single_line: if 'TRUE', allow an open and closed curly pair on
# the same line.
#
brace_linter(allow_single_line = TRUE),
# Description:
#
# Usage like 'class(x) == "character"' is prone to error since class
# in R is in general a vector. The correct version for S3 classes is
# 'inherits()': 'inherits(x, "character")'. Often, class 'k' will
# have an 'is.' equivalent, for example 'is.character()' or
# 'is.data.frame()'.
#
class_equals_linter(),
# Description:
#
# Check that all commas are followed by spaces, but do not have
# spaces before them.
#
# Arguments:
#
# allow_trailing: If 'TRUE', the linter allows a comma to be followed
# directly by a closing bracket without a space.
#
commas_linter(allow_trailing = FALSE),
# Description:
#
# Check that there is no commented code outside roxygen blocks.
#
commented_code_linter(),
# Description:
#
# This linter discourages combining condition functions like
# 'stop()' with string concatenation functions 'paste()' and
# 'paste0()'. This is because
#
# • 'stop(paste0(...))' is redundant as it is exactly equivalent
# to 'stop(...)'
#
# • 'stop(paste(...))' is similarly equivalent to 'stop(...)'
# with separators (see examples)
#
# The same applies to the other default condition functions as well,
# i.e., 'warning()', 'message()', and 'packageStartupMessage()'.
#
condition_message_linter(),
# Description:
#
# For readability of test outputs, testing only one thing per call
# to 'testthat::expect_true()' is preferable, i.e., expect_true(A);
# expect_true(B) is better than 'expect_true(A && B)', and
# expect_false(A); expect_false(B) is better than 'expect_false(A ||
# B)'.
#
# Arguments:
#
# allow_named_stopifnot: Logical, 'TRUE' by default. If 'FALSE', "named"
# calls to 'stopifnot()', available since R 4.0.0 to provide
# helpful messages for test failures, are also linted.
#
# allow_filter: Character naming the method for linting calls to
# 'filter()'. The default, '"never"', means 'filter()' and
# 'dplyr::filter()' calls are linted; '"not_dplyr"' means only
# 'dplyr::filter()' calls are linted; and '"always"' means no
# calls to 'filter()' are linted. Calls like 'stats::filter()'
# are never linted.
#
conjunct_test_linter(allow_named_stopifnot = TRUE, allow_filter = c("never", "not_dplyr", "always")),
# Description:
#
# 'stopifnot()' accepts any number of tests, so sequences like
# stopifnot(x); stopifnot(y) are redundant. Ditto for tests using
# 'assertthat::assert_that()' without specifying msg=.
#
consecutive_assertion_linter(),
# Description:
#
# Check for overly complicated expressions. See
# 'cyclocomp::cyclocomp()'.
#
# Arguments:
#
# complexity_limit: Maximum cyclomatic complexity, default 15.
# Expressions more complex than this are linted. See
# 'cyclocomp::cyclocomp()'.
#
cyclocomp_linter(complexity_limit = 15L),
# Description:
#
# Check for duplicate arguments in function calls. Some cases are
# run-time errors (e.g. 'mean(x = 1:5, x = 2:3)'), otherwise this
# linter is used to discourage explicitly providing duplicate names
# to objects (e.g. 'c(a = 1, a = 2)'). Duplicate-named objects are
# hard to work with programmatically and should typically be
# avoided.
#
# Arguments:
#
# except: A character vector of function names as exceptions. Defaults
# to functions that allow sequential updates to variables,
# currently 'dplyr::mutate()' and 'dplyr::transmute()'.
#
duplicate_argument_linter(except = c("mutate", "transmute")),
# Description:
#
# Assignment of '{}' is the same as assignment of 'NULL'; use the
# latter for clarity. Closely related:
# 'unnecessary_concatenation_linter()'.
#
empty_assignment_linter(),
# Description:
#
# Check for 'x == NA', 'x != NA' and 'x %in% NA'. Such usage is
# almost surely incorrect - checks for missing values should be done
# with 'is.na()'.
#
equals_na_linter(),
# Description:
#
# 'testthat::expect_gt()', 'testthat::expect_gte()',
# 'testthat::expect_lt()', 'testthat::expect_lte()', and
# 'testthat::expect_equal()' exist specifically for testing
# comparisons between two objects. 'testthat::expect_true()' can
# also be used for such tests, but it is better to use the tailored
# function instead.
#
expect_comparison_linter(),
# Description:
#
# This linter enforces the usage of 'testthat::expect_identical()'
# as the default expectation for comparisons in a testthat suite.
# 'expect_true(identical(x, y))' is an equivalent but unadvised
# method of the same test. Further, 'testthat::expect_equal()'
# should only be used when 'expect_identical()' is inappropriate,
# i.e., when 'x' and 'y' need only be _numerically equivalent_
# instead of fully identical (in which case, provide the tolerance=
# argument to 'expect_equal()' explicitly). This also applies when
# it's inconvenient to check full equality (e.g., names can be
# ignored, in which case 'ignore_attr = "names"' should be supplied
# to 'expect_equal()' (or, for 2nd edition, 'check.attributes =
# FALSE').
#
expect_identical_linter(),
# Description:
#
# 'testthat::expect_length()' exists specifically for testing the
# 'length()' of an object. 'testthat::expect_equal()' can also be
# used for such tests, but it is better to use the tailored function
# instead.
#
expect_length_linter(),
# Description:
#
# 'testthat::expect_named()' exists specifically for testing the
# 'names()' of an object. 'testthat::expect_equal()' can also be
# used for such tests, but it is better to use the tailored function
# instead.
#
expect_named_linter(),
# Description:
#
# 'testthat::expect_false()' exists specifically for testing that an
# output is 'FALSE'. 'testthat::expect_true()' can also be used for
# such tests by negating the output, but it is better to use the
# tailored function instead. The reverse is also true - use
# 'expect_false(A)' instead of 'expect_true(!A)'.
#
expect_not_linter(),
# Description:
#
# Require usage of 'expect_null(x)' over 'expect_equal(x, NULL)' and
# similar usages.
#
expect_null_linter(),
# Description:
#
# 'testthat::expect_s3_class()' exists specifically for testing the
# class of S3 objects. 'testthat::expect_equal()',
# 'testthat::expect_identical()', and 'testthat::expect_true()' can
# also be used for such tests, but it is better to use the tailored
# function instead.
#
expect_s3_class_linter(),
# Description:
#
# 'testthat::expect_s4_class()' exists specifically for testing the
# class of S4 objects. 'testthat::expect_true()' can also be used
# for such tests, but it is better to use the tailored function
# instead.
#
expect_s4_class_linter(),
# Description:
#
# 'testthat::expect_true()' and 'testthat::expect_false()' exist
# specifically for testing the 'TRUE'/'FALSE' value of an object.
# 'testthat::expect_equal()' and 'testthat::expect_identical()' can
# also be used for such tests, but it is better to use the tailored
# function instead.
#
expect_true_false_linter(),
# Description:
#
# 'testthat::expect_type()' exists specifically for testing the
# storage type of objects. 'testthat::expect_equal()',
# 'testthat::expect_identical()', and 'testthat::expect_true()' can
# also be used for such tests, but it is better to use the tailored
# function instead.
#
expect_type_linter(),
# Description:
#
# Check that the '[[' operator is used when extracting a single
# element from an object, not '[' (subsetting) nor '$' (interactive
# use).
#
extraction_operator_linter(),
# Description:
#
# Invoking a regular expression engine is overkill for cases when
# the search pattern only involves static patterns.
#
# Arguments:
#
# allow_unescaped: Logical, default 'FALSE'. If 'TRUE', only patterns
# that require regex escapes (e.g. '"\\$"' or '"[$]"') will be
# linted. See examples.
#
fixed_regex_linter(allow_unescaped = FALSE),
# Description:
#
# for (x in x) is a poor choice of indexing variable. This
# overwrites 'x' in the calling scope and is confusing to read.
#
for_loop_index_linter(),
# Description:
#
# Check that arguments with defaults come last in all function
# declarations, as per the tidyverse design guide.
#
# Changing the argument order can be a breaking change. An
# alternative to changing the argument order is to instead set the
# default for such arguments to 'NULL'.
#
function_argument_linter(),
# Description:
#
# Check that all left parentheses in a function call do not have
# spaces before them (e.g. 'mean (1:3)'). Although this is
# syntactically valid, it makes the code difficult to read.
#
function_left_parentheses_linter(),
# Description:
#
# 'return(x <- ...)' is either distracting (because 'x' is ignored),
# or confusing (because assigning to 'x' has some side effect that
# is muddled by the dual-purpose expression).
#
function_return_linter(),
# Description:
#
# 'if (!A) x else y' is the same as 'if (A) y else x', but the
# latter is easier to reason about in the else case. The former
# requires double negation that can be avoided by switching the
# statement order.
#
# Arguments:
#
# exceptions: Character vector of calls to exclude from linting. By
# default, 'is.null()', 'is.na()', and 'missing()' are excluded
# given the common idiom '!is.na(x)' as "x is present".
#
if_not_else_linter(exceptions = c("is.null", "is.na", "missing")),
# Description:
#
# 'ifelse(x > M, M, x)' is the same as 'pmin(x, M)', but harder to
# read and requires several passes over the vector.
#
ifelse_censor_linter(),
# Description:
#
# Assigning inside function calls makes the code difficult to read,
# and should be avoided, except for functions that capture
# side-effects (e.g. 'capture.output()').
#
# Arguments:
#
# except: A character vector of functions to be excluded from linting.
#
# allow_lazy: logical, default 'FALSE'. If 'TRUE', assignments that only
# trigger conditionally (e.g. in the RHS of '&&' or '||'
# expressions) are skipped.
#
# allow_scoped: Logical, default 'FALSE'. If 'TRUE', "scoped
# assignments", where the object is assigned in the statement
# beginning a branch and used only within that branch, are
# skipped.
#
implicit_assignment_linter(except = c("bquote", "expression", "expr", "quo", "quos", "quote"), allow_lazy = FALSE, allow_scoped = FALSE),
# Description:
#
# Check that integers are explicitly typed using the form '1L'
# instead of '1'.
#
# Arguments:
#
# allow_colon: Logical, default 'FALSE'. If 'TRUE', expressions involving
# ':' won't throw a lint regardless of whether the inputs are
# implicitly integers.
#
implicit_integer_linter(allow_colon = FALSE),
# Description:
#
# Check that indentation is consistent
#
# Arguments:
#
# indent: Number of spaces, that a code block should be indented by
# relative to its parent code block. Used for multi-line code
# blocks ('{ ... }'), function calls ('( ... )') and
# extractions ([ ... ], [[ ... ]]). Defaults to 2.
#
# hanging_indent_style: Indentation style for multi-line function calls
# with arguments in their first line. Defaults to tidyverse
# style, i.e. a block indent is used if the function call
# terminates with ) on a separate line and a hanging indent if
# not. Note that function multi-line function calls without
# arguments on their first line will always be expected to have
# block-indented arguments. If 'hanging_indent_style' is
# '"tidy"', multi-line function definitions are expected to be
# double-indented if the first line of the function definition
# contains no arguments and the closing parenthesis is not on
# its own line.
#
# # complies to any style
# map(
# x,
# f,
# additional_arg = 42
# )
#
# # complies to "tidy" and "never"
# map(x, f,
# additional_arg = 42
# )
#
# # complies to "always"
# map(x, f,
# additional_arg = 42
# )
#
# # complies to "tidy" and "always"
# map(x, f,
# additional_arg = 42)
#
# # complies to "never"
# map(x, f,
# additional_arg = 42)
#
# # complies to "tidy"
# function(
# a,
# b) {
# # body
# }
#
# assignment_as_infix: Treat <- as a regular (i.e. left-associative)
# infix operator? This means, that infix operators on the right
# hand side of an assignment do not trigger a second level of
# indentation:
#
# # complies to any style
# variable <- a %+%
# b %+%
# c
#
# # complies to assignment_as_infix = TRUE
# variable <-
# a %+%
# b %+%
# c
#
# # complies to assignment_as_infix = FALSE
# variable <-
# a %+%
# b %+%
# c
#
indentation_linter(indent = 4L, hanging_indent_style = c("tidy", "always", "never"), assignment_as_infix = TRUE),
# Description:
#
# Check that infix operators are surrounded by spaces. Enforces the
# corresponding Tidyverse style guide rule; see
# <https://style.tidyverse.org/syntax.html#infix-operators>.
#
# Arguments:
#
# exclude_operators: Character vector of operators to exclude from
# consideration for linting. Default is to include the
# following "low-precedence" operators: '+', '-', '~', '>',
# '>=', '<', '<=', '==', '!=', '&', '&&', '|', '||', <-, :=,
# <<-, ->, ->>, '=', '/', '*', and any infix operator (exclude
# infixes by passing '"%%"'). Note that '"="' here includes
# three different operators, from the parser's point of view.
# To lint only some of these, pass the corresponding parse tags
# (i.e., some of '"EQ_ASSIGN"', '"EQ_SUB"', and '"EQ_FORMALS"';
# see 'utils::getParseData()').
#
# allow_multiple_spaces: Logical, default 'TRUE'. If 'FALSE', usage like
# 'x = 2' will also be linted; excluded by default because such
# usage can sometimes be used for better code alignment, as is
# allowed by the style guide.
#
infix_spaces_linter(exclude_operators = NULL, allow_multiple_spaces = TRUE),
# Description:
#
# 'as.Date(c(a, b))' is logically equivalent to 'c(as.Date(a),
# as.Date(b))'. The same equivalence holds for several other
# vectorized functions like 'as.POSIXct()' and math functions like
# 'sin()'. The former is to be preferred so that the most expensive
# part of the operation ('as.Date()') is applied only once.
#
inner_combine_linter(),
# Description:
#
# 'is.numeric()' returns 'TRUE' when 'typeof(x)' is 'double' or
# 'integer' - testing 'is.numeric(x) || is.integer(x)' is thus
# redundant.
#
is_numeric_linter(),
# Description:
#
# Any valid symbol can be used as a keyword argument to an R
# function call. Sometimes, it is necessary to quote (or backtick)
# an argument that is not an otherwise valid symbol (e.g. creating a
# vector whose names have spaces); besides this edge case, quoting
# should not be done.
#
keyword_quote_linter(),
# Description:
#
# 'length(levels(x))' is the same as 'nlevels(x)', but harder to
# read.
#
length_levels_linter(),
# Description:
#
# Usage like 'length(x == 0)' is a mistake. If you intended to check
# 'x' is empty, use 'length(x) == 0'. Other mistakes are possible,
# but running 'length()' on the outcome of a logical comparison is
# never the best choice.
#
length_test_linter(),
# Description:
#
# 'lengths()' is a function that was added to base R in version
# 3.2.0 to get the length of each element of a list. It is
# equivalent to 'sapply(x, length)', but faster and more readable.
#
lengths_linter(),
# Description:
#
# Force library calls to all be at the top of the script.
#
# Arguments:
#
# allow_preamble: Logical, default 'TRUE'. If 'FALSE', no code is allowed
# to precede the first 'library()' call, otherwise some setup
# code is allowed, but all 'library()' calls must follow
# consecutively after the first one.
#
library_call_linter(allow_preamble = TRUE),
# Description:
#
# Check that the line length of both comments and code is less than
# 'length'.
#
# Arguments:
#
# length: maximum line length allowed. Default is 80L (Hollerith
# limit).
#
line_length_linter(length = 80L),
# Description:
#
# 'as.integer(1)' (or 'rlang::int(1)') is the same as '1L' but the
# latter is more concise and gets typed correctly at compilation.
#
literal_coercion_linter(),
# Description:
#
# 'colSums()' and 'rowSums()' are clearer and more performant
# alternatives to 'apply(x, 2, sum)' and 'apply(x, 1, sum)'
# respectively in the case of 2D arrays, or matrices
#
matrix_apply_linter(),
# Description:
#
# Check for missing arguments in function calls (e.g.
# 'stats::median(1:10, )').
#
# Arguments:
#
# except: a character vector of function names as exceptions.
#
# allow_trailing: always allow trailing empty arguments?
#
missing_argument_linter(except = c("alist", "quote", "switch"), allow_trailing = FALSE),
# Description:
#
# Check for missing packages in 'library()', 'require()',
# 'loadNamespace()', and 'requireNamespace()' calls.
#
missing_package_linter(),
# Description:
#
# Check for missing packages and symbols in namespace calls. Note
# that using 'check_exports=TRUE' or 'check_nonexports=TRUE' will
# load packages used in user code so it could potentially change the
# global state.
#
# Arguments:
#
# check_exports: Check if 'symbol' is exported from 'namespace' in
# 'namespace::symbol' calls.
#
# check_nonexports: Check if 'symbol' exists in 'namespace' in
# 'namespace:::symbol' calls.
#
namespace_linter(check_exports = TRUE, check_nonexports = TRUE),
# Description:
#
# Calling 'ifelse()' in nested calls is problematic for two main
# reasons:
#
# 1. It can be hard to read -- mapping the code to the expected
# output for such code can be a messy task/require a lot of
# mental bandwidth, especially for code that nests more than
# once
#
# 2. It is inefficient -- 'ifelse()' can evaluate _all_ of its
# arguments at both yes and no (see
# <https://stackoverflow.com/q/16275149>); this issue is
# exacerbated for nested calls
#
nested_ifelse_linter(),
# Description:
#
# Check that 'file.path()' is used to construct safe and portable
# paths.
#
# Arguments:
#
# lax: Less stringent linting, leading to fewer false positives. If
# 'TRUE', only lint path strings, which
#
# • contain at least two path elements, with one having at
# least two characters and
#
# • contain only alphanumeric chars (including UTF-8),
# spaces, and win32-allowed punctuation
#
#nonportable_path_linter(lax = TRUE),
# Description:
#
# While .1 and 0.1 mean the same thing, the latter is easier to read
# due to the small size of the '.' glyph.
#
numeric_leading_zero_linter(),
# Description:
#
# Check that object names are not too long. The length of an object
# name is defined as the length in characters, after removing
# extraneous parts:
#
# Arguments:
#
# length: maximum variable name length allowed.
#
#object_length_linter(length = 30L),
# Description:
#
# Check that object names conform to a naming style. The default
# naming styles are "snake_case" and "symbols".
#
# Arguments:
#
# styles: A subset of \Sexpr[stage=render,
# results=rd]{lintr:::regexes_rd}. A name should match at least
# one of these styles. The '"symbols"' style refers to names
# containing _only_ non-alphanumeric characters; e.g., defining
# %+% from ggplot2 or %>% from magrittr would not generate lint
# markers, whereas %m+% from lubridate (containing both
# alphanumeric _and_ non-alphanumeric characters) would.
#
# regexes: A (possibly named) character vector specifying a custom
# naming convention. If named, the names will be used in the
# lint message. Otherwise, the regexes enclosed by '/' will be
# used in the lint message. Note that specifying 'regexes'
# overrides the default 'styles'. So if you want to combine
# 'regexes' and 'styles', both need to be explicitly specified.
#
#object_name_linter(styles = c("snake_case", "symbols"), regexes = character()),
# Description:
#
# Check that closures have the proper usage using
# 'codetools::checkUsage()'. Note that this runs 'base::eval()' on
# the code, so *do not use with untrusted code*.
#
# Arguments:
#
# interpret_glue: If 'TRUE', interpret 'glue::glue()' calls to avoid
# false positives caused by local variables which are only used
# in a glue expression.
#
# skip_with: A logical. If 'TRUE' (default), code in 'with()' expressions
# will be skipped. This argument will be passed to 'skipWith'
# argument of 'codetools::checkUsage()'.
#
#object_usage_linter(interpret_glue = TRUE, skip_with = TRUE),
# Description:
#
# 'any(!x)' is logically equivalent to '!any(x)'; ditto for the
# equivalence of 'all(!x)' and '!any(x)'. Negating after aggregation
# only requires inverting one logical value, and is typically more
# readable.
#
outer_negation_linter(),
# Description:
#
# Check various common "gotchas" in '.onLoad()', '.onAttach()',
# '.Last.lib()', and '.onDetach()' namespace hooks that will cause R
# CMD check issues. See Writing R Extensions for details.
#
package_hooks_linter(),
# Description:
#
# Check that there is a space between right parenthesis and a body
# expression.
#
paren_body_linter(),
# Description:
#
# The following issues are linted by default by this linter (see
# arguments for which can be de-activated optionally):
#
# Arguments:
#
# allow_empty_sep: Logical, default 'FALSE'. If 'TRUE', usage of
# 'paste()' with 'sep = ""' is not linted.
#
# allow_to_string: Logical, default 'FALSE'. If 'TRUE', usage of
# 'paste()' and 'paste0()' with 'collapse = ", "' is not
# linted.
#
# allow_file_path: String, one of '"never"', '"double_slash"', or
# '"always"'; '"double_slash"' by default. If '"never"', usage
# of 'paste()' and 'paste0()' to construct file paths is not
# linted. If '"double_slash"', strings containing consecutive
# forward slashes will not lint. The main use case here is for
# URLs - "paths" like '"https://"' will not induce lints, since
# constructing them with 'file.path()' might be deemed
# unnatural. Lastly, if '"always"', strings with consecutive
# forward slashes will also lint. Note that '"//"' is never
# linted when it comes at the beginning or end of the input, to
# avoid requiring empty inputs like 'file.path("", ...)' or
# 'file.path(..., "")'.
#
paste_linter(allow_empty_sep = FALSE, allow_to_string = FALSE, allow_file_path = c("double_slash", "always", "never")),
# Description:
#
# Force explicit calls in magrittr pipes, e.g., '1:3 %>% sum()'
# instead of '1:3 %>% sum'. Note that native pipe always requires a
# function call, i.e. 1:3 |> sum will produce an error.
#
pipe_call_linter(),
# Description:
#
# Check that pipe operators are used consistently by file, or
# optionally specify one valid pipe operator.
#
# Arguments:
#
# pipe: Which pipe operator is valid (either '"%>%"' or '"|>"'). By
# default ('"auto"'), the linter has no preference but will
# check that each file uses only one type of pipe operator.
#
pipe_consistency_linter(pipe = c("auto", "%>%", "|>")),
# Description:
#
# Check that each step in a pipeline is on a new line, or the entire
# pipe fits on one line.
#
pipe_continuation_linter(),
# Description:
#
# Check that the desired quote delimiter is used for string
# constants.
#
# Arguments:
#
# delimiter: Which quote delimiter to accept. Defaults to the tidyverse
# default of " (double-quoted strings).
#
quotes_linter(delimiter = c("\"", "'")),
# Description:
#
# Testing 'x == TRUE' is redundant if 'x' is a logical vector.
# Wherever this is used to improve readability, the solution should
# instead be to improve the naming of the object to better indicate
# that its contents are logical. This can be done using prefixes
# (is, has, can, etc.). For example, 'is_child',
# 'has_parent_supervision', 'can_watch_horror_movie' clarify their
# logical nature, while 'child', 'parent_supervision',
# 'watch_horror_movie' don't.
#
redundant_equals_linter(),
# Description:
#
# Expressions like 'ifelse(x, TRUE, FALSE)' and 'ifelse(x, FALSE,
# TRUE)' are redundant; just 'x' or '!x' suffice in R code where
# logical vectors are a core data structure. 'ifelse(x, 1, 0)' is
# also 'as.numeric(x)', but even this should be needed only rarely.
#
# Arguments:
#
# allow10: Logical, default 'FALSE'. If 'TRUE', usage like 'ifelse(x, 1,
# 0)' is allowed, i.e., only usage like 'ifelse(x, TRUE,
# FALSE)' is linted.
#
redundant_ifelse_linter(allow10 = FALSE),
# Description:
#
# Using 'value = TRUE' in 'grep()' returns the subset of the input
# that matches the pattern, e.g. 'grep("[a-m]", letters, value =
# TRUE)' will return the first 13 elements ('a' through 'm').
#
regex_subset_linter(),
# Description:
#
# Check that while (TRUE) is not used for infinite loops.
#
repeat_linter(),
# Description:
#
# It is preferable to register routines for efficiency and safety.
#
routine_registration_linter(),
# Description:
#
# 'vector %in% set' is appropriate for matching a vector to a set,
# but if that set has size 1, '==' is more appropriate. %chin% from
# '{data.table}' is matched as well.
#
scalar_in_linter(),
# Description:
#
# Check that no semicolons terminate expressions.
#
# Arguments:
#
# allow_compound: Logical, default 'FALSE'. If 'TRUE', "compound"
# semicolons (e.g. as in x; y, i.e., on the same line of code)
# are allowed.
#
# allow_trailing: Logical, default 'FALSE'. If 'TRUE', "trailing"
# semicolons (i.e., those that terminate lines of code) are
# allowed.
#
semicolon_linter(allow_compound = FALSE, allow_trailing = FALSE),
# Description:
#
# This linter checks for '1:length(...)', '1:nrow(...)',
# '1:ncol(...)', '1:NROW(...)' and '1:NCOL(...)' expressions in
# base-R, or their usage in conjunction with 'seq()' (e.g.,
# 'seq(length(...))', 'seq(nrow(...))', etc.).
#
seq_linter(),
# Description:
#
# This linter checks for some common mistakes when using 'order()'
# or 'sort()'.
#
sort_linter(),
# Description:
#
# Check that parentheses and square brackets do not have spaces
# directly inside them, i.e., directly following an opening
# delimiter or directly preceding a closing delimiter.
#
spaces_inside_linter(),
# Description:
#
# Check that all left parentheses have a space before them unless
# they are in a function call.
#
spaces_left_parentheses_linter(),
# Description:
#
# Check for an inconsistent number of arguments or arguments with
# incompatible types (for literal arguments) in 'sprintf()' calls.
#
sprintf_linter(),
# Description:
#
# 'startsWith()' is used to detect fixed initial substrings; it is
# more readable and more efficient than equivalents using 'grepl()'
# or 'substr()'. c.f. 'startsWith(x, "abc")', 'grepl("^abc", x)',
# 'substr(x, 1L, 3L) == "abc"'.
#
# Arguments:
#
# allow_grepl: Logical, default 'FALSE'. If 'TRUE', usages with 'grepl()'
# are ignored. Some authors may prefer the conciseness offered
# by 'grepl()' whereby 'NA' input maps to 'FALSE' output, which
# doesn't have a direct equivalent with 'startsWith()' or
# 'endsWith()'.
#
string_boundary_linter(allow_grepl = FALSE),
# Description:
#
# Designed for code bases written for versions of R before 4.0
# seeking to upgrade to R >= 4.0, where one of the biggest pain
# points will surely be the flipping of the default value of
# 'stringsAsFactors' from 'TRUE' to 'FALSE'.
#
strings_as_factors_linter(),
# Description:
#
# 'system.file()' has a '...' argument which, internally, is passed
# to 'file.path()', so including it in user code is repetitive.
#
system_file_linter(),
# Description:
#
# Avoid the symbols 'T' and 'F', and use 'TRUE' and 'FALSE' instead.
#
T_and_F_symbol_linter(),
# Description: