rubocop-cask 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubocop-cask.rb +1 -1
- data/lib/rubocop/cask/ast/cask_block.rb +2 -1
- data/lib/rubocop/cask/ast/cask_header.rb +2 -4
- data/lib/rubocop/cask/ast/stanza.rb +3 -3
- data/lib/rubocop/cask/constants.rb +0 -1
- data/lib/rubocop/cask/extend/astrolabe/node.rb +4 -0
- data/lib/rubocop/cask/version.rb +1 -1
- data/lib/rubocop/cop/cask/mixin/cask_help.rb +16 -0
- data/lib/rubocop/cop/cask/no_dsl_version.rb +1 -1
- data/lib/rubocop/cop/cask/stanza_grouping.rb +1 -1
- data/lib/rubocop/cop/cask/stanza_order.rb +1 -1
- data/spec/rubocop/cop/cask/no_dsl_version_spec.rb +3 -3
- data/spec/rubocop/cop/cask/stanza_grouping_spec.rb +73 -16
- data/spec/rubocop/cop/cask/stanza_order_spec.rb +71 -18
- data/spec/support/cop_shared_examples.rb +23 -11
- metadata +3 -3
- data/lib/rubocop/cask/cask_help.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c174d108070beae46129bf27159a945ac505691
|
4
|
+
data.tar.gz: cf04f6d393b83b38a63e2f9bfc8ea12d4dfedef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0583722e3bba308c5ab2a4435ec89e8888cbab4f18535d7a1ba79f6c622682beafc372d8b935bac04dba082adef11c9f7cca3d91e7e459d4db525fe934f75f49
|
7
|
+
data.tar.gz: 22cdf650337a179ce424a0a82fa8e5e7fd4dfebcdb9cf58b561680b372b093206b1ea3b2e66c94d192a896384bc0708175af6fe7ea8b3411e5a9db0e74d041a5
|
data/lib/rubocop-cask.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rubocop'
|
|
3
3
|
require 'rubocop/cask/constants'
|
4
4
|
require 'rubocop/cask/extend/string'
|
5
5
|
require 'rubocop/cask/extend/astrolabe/node'
|
6
|
-
require 'rubocop/cask/cask_help'
|
7
6
|
require 'rubocop/cask/ast/cask_header'
|
8
7
|
require 'rubocop/cask/ast/cask_block'
|
9
8
|
require 'rubocop/cask/ast/stanza'
|
@@ -12,6 +11,7 @@ require 'rubocop/cask/inject'
|
|
12
11
|
|
13
12
|
RuboCop::Cask::Inject.defaults!
|
14
13
|
|
14
|
+
require 'rubocop/cop/cask/mixin/cask_help'
|
15
15
|
require 'rubocop/cop/cask/no_dsl_version'
|
16
16
|
require 'rubocop/cop/cask/stanza_order'
|
17
17
|
require 'rubocop/cop/cask/stanza_grouping'
|
@@ -4,14 +4,12 @@ module RuboCop
|
|
4
4
|
# This class wraps the AST method node that represents the cask header. It
|
5
5
|
# includes various helper methods to aid cops in their analysis.
|
6
6
|
class CaskHeader
|
7
|
-
include CaskHelp
|
8
|
-
|
9
|
-
attr_reader :method_node
|
10
|
-
|
11
7
|
def initialize(method_node)
|
12
8
|
@method_node = method_node
|
13
9
|
end
|
14
10
|
|
11
|
+
attr_reader :method_node
|
12
|
+
|
15
13
|
def dsl_version?
|
16
14
|
hash_node
|
17
15
|
end
|
@@ -3,9 +3,9 @@ require 'forwardable'
|
|
3
3
|
module RuboCop
|
4
4
|
module Cask
|
5
5
|
module AST
|
6
|
-
# This class wraps the AST send node that encapsulates the method
|
7
|
-
# that comprises the stanza. It includes various helper methods to
|
8
|
-
# cops in their analysis.
|
6
|
+
# This class wraps the AST send/block node that encapsulates the method
|
7
|
+
# call that comprises the stanza. It includes various helper methods to
|
8
|
+
# aid cops in their analysis.
|
9
9
|
class Stanza
|
10
10
|
extend Forwardable
|
11
11
|
|
data/lib/rubocop/cask/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module Cask
|
4
|
+
# Common functionality for cops checking casks
|
5
|
+
module CaskHelp
|
6
|
+
def on_block(block_node)
|
7
|
+
super if defined? super
|
8
|
+
return unless respond_to?(:on_cask)
|
9
|
+
return unless block_node.cask_block?
|
10
|
+
|
11
|
+
on_cask(block_node)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Cask::NoDslVersion do
|
|
29
29
|
|
30
30
|
include_examples 'reports offenses'
|
31
31
|
|
32
|
-
include_examples 'autocorrects
|
32
|
+
include_examples 'autocorrects source'
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'with dsl version containing "test"' do
|
@@ -49,7 +49,7 @@ describe RuboCop::Cop::Cask::NoDslVersion do
|
|
49
49
|
|
50
50
|
include_examples 'reports offenses'
|
51
51
|
|
52
|
-
include_examples 'autocorrects
|
52
|
+
include_examples 'autocorrects source'
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -78,7 +78,7 @@ describe RuboCop::Cop::Cask::NoDslVersion do
|
|
78
78
|
|
79
79
|
include_examples 'reports offenses'
|
80
80
|
|
81
|
-
include_examples 'autocorrects
|
81
|
+
include_examples 'autocorrects source'
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -54,7 +54,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
|
|
54
54
|
|
55
55
|
include_examples 'reports offenses'
|
56
56
|
|
57
|
-
include_examples 'autocorrects
|
57
|
+
include_examples 'autocorrects source'
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'when many stanzas are incorrectly grouped' do
|
@@ -129,28 +129,24 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
|
|
129
129
|
|
130
130
|
include_examples 'reports offenses'
|
131
131
|
|
132
|
-
include_examples 'autocorrects
|
132
|
+
include_examples 'autocorrects source'
|
133
133
|
end
|
134
134
|
|
135
|
-
context 'when
|
135
|
+
context 'when caveats stanza is incorrectly grouped' do
|
136
136
|
let(:source) do
|
137
|
-
<<-CASK.undent
|
137
|
+
format(<<-CASK.undent, caveats.strip)
|
138
138
|
cask 'foo' do
|
139
139
|
version :latest
|
140
140
|
sha256 :no_check
|
141
141
|
url 'https://foo.example.com/foo.zip'
|
142
142
|
name 'Foo'
|
143
|
-
caveats <<-EOS.undent
|
144
|
-
This is a multiline caveat.
|
145
|
-
|
146
|
-
Let's hope it doesn't cause any problems!
|
147
|
-
EOS
|
148
143
|
app 'Foo.app'
|
144
|
+
%s
|
149
145
|
end
|
150
146
|
CASK
|
151
147
|
end
|
152
148
|
let(:correct_source) do
|
153
|
-
<<-CASK.undent
|
149
|
+
format(<<-CASK.undent, caveats.strip)
|
154
150
|
cask 'foo' do
|
155
151
|
version :latest
|
156
152
|
sha256 :no_check
|
@@ -158,21 +154,82 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
|
|
158
154
|
url 'https://foo.example.com/foo.zip'
|
159
155
|
name 'Foo'
|
160
156
|
|
157
|
+
app 'Foo.app'
|
158
|
+
|
159
|
+
%s
|
160
|
+
end
|
161
|
+
CASK
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when caveats is a one-line string' do
|
165
|
+
let(:caveats) { "caveats 'This is a one-line caveat.'" }
|
166
|
+
|
167
|
+
include_examples 'autocorrects source'
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when caveats is a heredoc' do
|
171
|
+
let(:caveats) do
|
172
|
+
<<-CAVEATS.undent
|
161
173
|
caveats <<-EOS.undent
|
162
|
-
|
174
|
+
This is a multiline caveat.
|
175
|
+
|
176
|
+
Let's hope it doesn't cause any problems!
|
177
|
+
EOS
|
178
|
+
CAVEATS
|
179
|
+
end
|
180
|
+
|
181
|
+
include_examples 'autocorrects source'
|
182
|
+
end
|
163
183
|
|
164
|
-
|
165
|
-
|
184
|
+
context 'when caveats is a block' do
|
185
|
+
let(:caveats) do
|
186
|
+
<<-CAVEATS.undent
|
187
|
+
caveats do
|
188
|
+
puts 'This is a multiline caveat.'
|
166
189
|
|
190
|
+
puts "Let's hope it doesn't cause any problems!"
|
191
|
+
end
|
192
|
+
CAVEATS
|
193
|
+
end
|
194
|
+
|
195
|
+
include_examples 'autocorrects source'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'when the postflight stanza is incorrectly grouped' do
|
200
|
+
let(:source) do
|
201
|
+
<<-CASK.undent
|
202
|
+
cask 'foo' do
|
203
|
+
version :latest
|
204
|
+
sha256 :no_check
|
205
|
+
url 'https://foo.example.com/foo.zip'
|
206
|
+
name 'Foo'
|
167
207
|
app 'Foo.app'
|
208
|
+
postflight do
|
209
|
+
puts 'We have liftoff!'
|
210
|
+
end
|
168
211
|
end
|
169
212
|
CASK
|
170
213
|
end
|
214
|
+
let(:correct_source) do
|
215
|
+
<<-CASK.undent
|
216
|
+
cask 'foo' do
|
217
|
+
version :latest
|
218
|
+
sha256 :no_check
|
219
|
+
|
220
|
+
url 'https://foo.example.com/foo.zip'
|
221
|
+
name 'Foo'
|
222
|
+
|
223
|
+
app 'Foo.app'
|
171
224
|
|
172
|
-
|
173
|
-
|
174
|
-
|
225
|
+
postflight do
|
226
|
+
puts 'We have liftoff!'
|
227
|
+
end
|
228
|
+
end
|
229
|
+
CASK
|
175
230
|
end
|
231
|
+
|
232
|
+
include_examples 'autocorrects source'
|
176
233
|
end
|
177
234
|
|
178
235
|
# TODO: detect incorrectly grouped stanzas in nested expressions
|
@@ -54,7 +54,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
|
54
54
|
|
55
55
|
include_examples 'reports offenses'
|
56
56
|
|
57
|
-
include_examples 'autocorrects
|
57
|
+
include_examples 'autocorrects source'
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'when many stanzas are out of order' do
|
@@ -118,7 +118,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
|
118
118
|
|
119
119
|
include_examples 'reports offenses'
|
120
120
|
|
121
|
-
include_examples 'autocorrects
|
121
|
+
include_examples 'autocorrects source'
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'when a stanza appears multiple times' do
|
@@ -150,22 +150,80 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'preserves the original order' do
|
153
|
-
|
154
|
-
expect(new_source).to eq(Array(correct_source).join("\n"))
|
153
|
+
expect_autocorrected_source(cop, source, correct_source)
|
155
154
|
end
|
156
155
|
end
|
157
156
|
|
158
|
-
context 'when
|
157
|
+
context 'when the caveats stanza is out of order' do
|
159
158
|
let(:source) do
|
160
|
-
<<-CASK.undent
|
159
|
+
format(<<-CASK.undent, caveats.strip)
|
161
160
|
cask 'foo' do
|
162
161
|
name 'Foo'
|
163
162
|
url 'https://foo.example.com/foo.zip'
|
163
|
+
%s
|
164
|
+
version :latest
|
165
|
+
app 'Foo.app'
|
166
|
+
sha256 :no_check
|
167
|
+
end
|
168
|
+
CASK
|
169
|
+
end
|
170
|
+
let(:correct_source) do
|
171
|
+
format(<<-CASK.undent, caveats.strip)
|
172
|
+
cask 'foo' do
|
173
|
+
version :latest
|
174
|
+
sha256 :no_check
|
175
|
+
url 'https://foo.example.com/foo.zip'
|
176
|
+
name 'Foo'
|
177
|
+
app 'Foo.app'
|
178
|
+
%s
|
179
|
+
end
|
180
|
+
CASK
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'when caveats is a one-line string' do
|
184
|
+
let(:caveats) { "caveats 'This is a one-line caveat.'" }
|
185
|
+
|
186
|
+
include_examples 'autocorrects source'
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when caveats is a heredoc' do
|
190
|
+
let(:caveats) do
|
191
|
+
<<-CAVEATS.undent
|
164
192
|
caveats <<-EOS.undent
|
165
|
-
|
193
|
+
This is a multiline caveat.
|
194
|
+
|
195
|
+
Let's hope it doesn't cause any problems!
|
196
|
+
EOS
|
197
|
+
CAVEATS
|
198
|
+
end
|
199
|
+
|
200
|
+
include_examples 'autocorrects source'
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when caveats is a block' do
|
204
|
+
let(:caveats) do
|
205
|
+
<<-CAVEATS.undent
|
206
|
+
caveats do
|
207
|
+
puts 'This is a multiline caveat.'
|
166
208
|
|
167
|
-
|
168
|
-
|
209
|
+
puts "Let's hope it doesn't cause any problems!"
|
210
|
+
end
|
211
|
+
CAVEATS
|
212
|
+
end
|
213
|
+
|
214
|
+
include_examples 'autocorrects source'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when the postflight stanza is out of order' do
|
219
|
+
let(:source) do
|
220
|
+
<<-CASK.undent
|
221
|
+
cask 'foo' do
|
222
|
+
name 'Foo'
|
223
|
+
url 'https://foo.example.com/foo.zip'
|
224
|
+
postflight do
|
225
|
+
puts 'We have liftoff!'
|
226
|
+
end
|
169
227
|
version :latest
|
170
228
|
app 'Foo.app'
|
171
229
|
sha256 :no_check
|
@@ -180,19 +238,14 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
|
180
238
|
url 'https://foo.example.com/foo.zip'
|
181
239
|
name 'Foo'
|
182
240
|
app 'Foo.app'
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
Let's hope it doesn't cause any problems!
|
187
|
-
EOS
|
241
|
+
postflight do
|
242
|
+
puts 'We have liftoff!'
|
243
|
+
end
|
188
244
|
end
|
189
245
|
CASK
|
190
246
|
end
|
191
247
|
|
192
|
-
|
193
|
-
new_source = autocorrect_source(cop, source)
|
194
|
-
expect(new_source).to eq(Array(correct_source).join("\n"))
|
195
|
-
end
|
248
|
+
include_examples 'autocorrects source'
|
196
249
|
end
|
197
250
|
|
198
251
|
# TODO: detect out-of-order stanzas in nested expressions
|
@@ -1,25 +1,32 @@
|
|
1
1
|
module CopSharedExamples
|
2
2
|
shared_examples 'does not report any offenses' do
|
3
3
|
it 'does not report any offenses' do
|
4
|
-
|
5
|
-
expect(cop.offenses).to be_empty
|
4
|
+
expect_no_offenses(cop, source)
|
6
5
|
end
|
7
6
|
end
|
8
7
|
|
9
8
|
shared_examples 'reports offenses' do
|
10
9
|
it 'reports offenses' do
|
11
|
-
|
12
|
-
expect(cop.offenses.size).to eq(expected_offenses.size)
|
13
|
-
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
14
|
-
expect_offense(expected, actual)
|
15
|
-
end
|
10
|
+
expect_reported_offenses(cop, source, expected_offenses)
|
16
11
|
end
|
17
12
|
end
|
18
13
|
|
19
|
-
shared_examples 'autocorrects
|
20
|
-
it 'autocorrects
|
21
|
-
|
22
|
-
|
14
|
+
shared_examples 'autocorrects source' do
|
15
|
+
it 'autocorrects source' do
|
16
|
+
expect_autocorrected_source(cop, source, correct_source)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def expect_no_offenses(cop, source)
|
21
|
+
inspect_source(cop, source)
|
22
|
+
expect(cop.offenses).to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
def expect_reported_offenses(cop, source, expected_offenses)
|
26
|
+
inspect_source(cop, source)
|
27
|
+
expect(cop.offenses.size).to eq(expected_offenses.size)
|
28
|
+
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
29
|
+
expect_offense(expected, actual)
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
@@ -30,4 +37,9 @@ module CopSharedExamples
|
|
30
37
|
expect(actual.column).to eq(expected[:column])
|
31
38
|
expect(actual.location.source).to eq(expected[:source])
|
32
39
|
end
|
40
|
+
|
41
|
+
def expect_autocorrected_source(cop, source, correct_source)
|
42
|
+
new_source = autocorrect_source(cop, source)
|
43
|
+
expect(new_source).to eq(Array(correct_source).join("\n"))
|
44
|
+
end
|
33
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-cask
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hagins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,12 +42,12 @@ files:
|
|
42
42
|
- lib/rubocop/cask/ast/cask_block.rb
|
43
43
|
- lib/rubocop/cask/ast/cask_header.rb
|
44
44
|
- lib/rubocop/cask/ast/stanza.rb
|
45
|
-
- lib/rubocop/cask/cask_help.rb
|
46
45
|
- lib/rubocop/cask/constants.rb
|
47
46
|
- lib/rubocop/cask/extend/astrolabe/node.rb
|
48
47
|
- lib/rubocop/cask/extend/string.rb
|
49
48
|
- lib/rubocop/cask/inject.rb
|
50
49
|
- lib/rubocop/cask/version.rb
|
50
|
+
- lib/rubocop/cop/cask/mixin/cask_help.rb
|
51
51
|
- lib/rubocop/cop/cask/no_dsl_version.rb
|
52
52
|
- lib/rubocop/cop/cask/stanza_grouping.rb
|
53
53
|
- lib/rubocop/cop/cask/stanza_order.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module RuboCop
|
2
|
-
module Cask
|
3
|
-
# Common functionality for cops checking casks
|
4
|
-
module CaskHelp
|
5
|
-
def on_block(block_node)
|
6
|
-
super if defined? super
|
7
|
-
return unless respond_to?(:on_cask)
|
8
|
-
return unless block_node.cask_block?
|
9
|
-
|
10
|
-
on_cask(block_node)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|