|
12 | 12 | it "registers an offense when using `#{receiver}.#{method}(Rails.public_path)` (if arity exists)" do |
13 | 13 | expect_offense(<<~RUBY, receiver: receiver, method: method) |
14 | 14 | %{receiver}.%{method}(Rails.public_path) |
15 | | - ^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^ `Rails.public_path` is a `Pathname` so you can just append `#%{method}`. |
| 15 | + ^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^ `Rails.public_path` is a `Pathname`, so you can use `Rails.public_path.%{method}`. |
16 | 16 | RUBY |
17 | 17 |
|
18 | 18 | expect_correction(<<~RUBY) |
|
23 | 23 | it "registers an offense when using `::#{receiver}.#{method}(::Rails.root.join(...))` (if arity exists)" do |
24 | 24 | expect_offense(<<~RUBY, receiver: receiver, method: method) |
25 | 25 | ::%{receiver}.%{method}(::Rails.root.join('db', 'schema.rb')) |
26 | | - ^^^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Rails.root` is a `Pathname` so you can just append `#%{method}`. |
| 26 | + ^^^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Rails.root` is a `Pathname`, so you can use `::Rails.root.join('db', 'schema.rb').%{method}`. |
27 | 27 | RUBY |
28 | 28 |
|
29 | 29 | expect_correction(<<~RUBY) |
|
34 | 34 | it "registers an offense when using `::#{receiver}.#{method}(::Rails.root.join(...), ...)` (if arity exists)" do |
35 | 35 | expect_offense(<<~RUBY, receiver: receiver, method: method) |
36 | 36 | ::%{receiver}.%{method}(::Rails.root.join('db', 'schema.rb'), 20, 5) |
37 | | - ^^^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Rails.root` is a `Pathname` so you can just append `#%{method}`. |
| 37 | + ^^^{receiver}^^{method}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Rails.root` is a `Pathname`, so you can use `::Rails.root.join('db', 'schema.rb').%{method}(20, 5)`. |
38 | 38 | RUBY |
39 | 39 |
|
40 | 40 | expect_correction(<<~RUBY) |
|
56 | 56 | it "registers an offense when using `Dir.glob(Rails.root.join('**/*.rb'))`" do |
57 | 57 | expect_offense(<<~RUBY) |
58 | 58 | Dir.glob(Rails.root.join('**/*.rb')) |
59 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 59 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob('**/*.rb')`. |
60 | 60 | RUBY |
61 | 61 |
|
62 | 62 | expect_correction(<<~RUBY) |
|
67 | 67 | it "registers an offense when using `::Dir.glob(Rails.root.join('**/*.rb'))`" do |
68 | 68 | expect_offense(<<~RUBY) |
69 | 69 | ::Dir.glob(Rails.root.join('**/*.rb')) |
70 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 70 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob('**/*.rb')`. |
71 | 71 | RUBY |
72 | 72 |
|
73 | 73 | expect_correction(<<~RUBY) |
|
78 | 78 | it "registers an offense when using `Dir.glob(Rails.root.join('**/\#{path}/*.rb'))`" do |
79 | 79 | expect_offense(<<~'RUBY') |
80 | 80 | Dir.glob(Rails.root.join("**/#{path}/*.rb")) |
81 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 81 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob("**/#{path}/*.rb")`. |
82 | 82 | RUBY |
83 | 83 |
|
84 | 84 | expect_correction(<<~'RUBY') |
|
89 | 89 | it "registers an offense when using `Dir.glob(Rails.root.join('**', '*.rb'))`" do |
90 | 90 | expect_offense(<<~RUBY) |
91 | 91 | Dir.glob(Rails.root.join('**', '*.rb')) |
92 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 92 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob('**/*.rb')`. |
93 | 93 | RUBY |
94 | 94 |
|
95 | 95 | expect_correction(<<~RUBY) |
|
105 | 105 | it "registers an offense when using `Dir.glob(Rails.root.join('**', '*.rb'))`" do |
106 | 106 | expect_offense(<<~RUBY) |
107 | 107 | Dir.glob(Rails.root.join('**', '*.rb')) |
108 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 108 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob("**/*.rb")`. |
109 | 109 | RUBY |
110 | 110 |
|
111 | 111 | expect_correction(<<~RUBY) |
|
117 | 117 | it "registers an offense when using `Dir.glob(Rails.root.join('**', \"\#{path}\", '*.rb'))`" do |
118 | 118 | expect_offense(<<~'RUBY') |
119 | 119 | Dir.glob(Rails.root.join('**', "#{path}", '*.rb')) |
120 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 120 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob("**/#{path}/*.rb")`. |
121 | 121 | RUBY |
122 | 122 |
|
123 | 123 | expect_correction(<<~'RUBY') |
|
128 | 128 | it 'registers an offense when using `Rails.env` argument within `Dir.glob`' do |
129 | 129 | expect_offense(<<~RUBY) |
130 | 130 | Dir.glob(Rails.root.join("db", "seeds", Rails.env, "*.rb")).sort.each do |file| |
131 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#glob`. |
| 131 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob("db/seeds/\#{Rails.env}/*.rb")`. |
132 | 132 | load file |
133 | 133 | end |
134 | 134 | RUBY |
|
145 | 145 | it 'registers offense when using `Dir[Rails.root.join(...)]`' do |
146 | 146 | expect_offense(<<~RUBY) |
147 | 147 | Dir[Rails.root.join('spec/support/**/*.rb')] |
148 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#[]`. |
| 148 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.glob('spec/support/**/*.rb')`. |
149 | 149 | RUBY |
150 | 150 |
|
151 | 151 | expect_correction(<<~RUBY) |
|
192 | 192 | it 'registers an offense when using `File.open(Rails.root.join(...), ...)` inside an iterator' do |
193 | 193 | expect_offense(<<~RUBY) |
194 | 194 | files.map { |file| File.open(Rails.root.join('db', file), 'wb') } |
195 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#open`. |
| 195 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join('db', file).open('wb')`. |
196 | 196 | RUBY |
197 | 197 |
|
198 | 198 | expect_correction(<<~RUBY) |
|
203 | 203 | it 'registers an offense when using `File.open Rails.root.join ...` without parens' do |
204 | 204 | expect_offense(<<~RUBY) |
205 | 205 | file = File.open Rails.root.join 'docs', 'invoice.pdf' |
206 | | - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname` so you can just append `#open`. |
| 206 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rails.root` is a `Pathname`, so you can use `Rails.root.join('docs', 'invoice.pdf').open`. |
207 | 207 | RUBY |
208 | 208 |
|
209 | 209 | expect_correction(<<~RUBY) |
|
0 commit comments