@@ -45,6 +45,61 @@ test_that("transformers are removed if they are unused", {
45
45
expect_equal(t_fun , t_manual )
46
46
})
47
47
48
+ test_that(" tidyverse transformers are correctly dropped" , {
49
+ t_style <- tidyverse_style()
50
+
51
+ t_fun <- transformers_drop(
52
+ " x" , t_style
53
+ )
54
+ # test that all dropping rules match an actual rule in the style guide
55
+ scopes <- intersect(
56
+ names(t_fun $ transformers_drop ),
57
+ names(t_fun )
58
+ )
59
+ purrr :: map2(t_fun $ transformers_drop , t_style [scopes ], function (x , y ) {
60
+ # all x must be in y. select the x that are not in y
61
+ diff <- setdiff(names(x ),names(y ))
62
+ if (length(diff ) > 0 ) {
63
+ rlang :: abort(paste(
64
+ " transformer_dropping specifies exclusion rules for transformers that " ,
65
+ " are not in the style guilde. Please add the rule to the style guide " ,
66
+ " or remove the dropping rules:" , paste(diff , collapse = " , " ))
67
+ )
68
+ }
69
+ })
70
+ names_line_break <- c(
71
+ " set_line_break_around_comma_and_or" ,
72
+ " set_line_break_after_assignment" ,
73
+ " set_line_break_after_opening_if_call_is_multi_line" ,
74
+ " set_line_break_before_closing_call" ,
75
+ " remove_line_break_in_fun_call" ,
76
+ " set_linebreak_after_ggplot2_plus"
77
+ )
78
+ expect_setequal(names(t_fun $ line_break ), names_line_break )
79
+
80
+ names_spaces <- c(
81
+ " remove_space_before_closing_paren" ,
82
+ " remove_space_before_opening_paren" ,
83
+ " remove_space_before_comma" ,
84
+ " spacing_around_op" ,
85
+ " remove_space_after_opening_paren" ,
86
+ " set_space_between_levels"
87
+ )
88
+
89
+ expect_setequal(names(t_fun $ space ), names_spaces )
90
+
91
+ names_indention <- c(" indent_braces" , " indent_op" , " indent_without_paren" )
92
+ expect_setequal(names(t_fun $ indention ), names_indention )
93
+
94
+ names_tokens <- c(
95
+ " fix_quotes" ,
96
+ if (getRversion() < 3.6 ) " force_assignment_op" ,
97
+ " remove_terminal_token_before_and_after"
98
+ )
99
+ expect_setequal(names(t_fun $ token ), names_tokens )
100
+
101
+ })
102
+
48
103
49
104
test_that(" if no transformers_drop is specified, no transformer is removed and no error issued" , {
50
105
t_fun <- transformers_drop(
0 commit comments