rubocop-cask 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eedae76807564012ce59a4b4a81af9751a851d2a
4
- data.tar.gz: f7d783a06b07aaa8ddb2fdeec8f1ad9969851c40
3
+ metadata.gz: 4c174d108070beae46129bf27159a945ac505691
4
+ data.tar.gz: cf04f6d393b83b38a63e2f9bfc8ea12d4dfedef6
5
5
  SHA512:
6
- metadata.gz: e3009d1c3e6233735a9d308720627f8e44a504270d730e52fb08b7734957bd4e4bd26d322a1baf3538e816b848dfcf533392ceb1fbc8c83c8b48ea4e0be9d90f
7
- data.tar.gz: 65e425329851c85db2789774311a20b8fe6680638dc285ec703ee7e448be73e10bf6602de593ea639d855a912dd49355dd070c9fed9d2675e8e6e79fcf093e4c
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'
@@ -26,7 +26,8 @@ module RuboCop
26
26
  end
27
27
 
28
28
  def stanzas
29
- @stanzas ||= cask_body.each_descendant(:send)
29
+ @stanzas ||= cask_body.descendants
30
+ .select(&:stanza?)
30
31
  .map { |n| Stanza.new(n) }
31
32
  end
32
33
 
@@ -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 call
7
- # that comprises the stanza. It includes various helper methods to aid
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
 
@@ -45,7 +45,6 @@ module RuboCop
45
45
  STANZA_GROUP_HASH =
46
46
  STANZA_GROUPS.each_with_object({}) do |stanza_group, hash|
47
47
  stanza_group.each { |stanza| hash[stanza] = stanza_group }
48
- hash
49
48
  end.freeze
50
49
 
51
50
  STANZA_ORDER = STANZA_GROUPS.flatten.freeze
@@ -18,6 +18,10 @@ module Astrolabe
18
18
  send_type? && CASK_METHOD_NAMES.include?(method_name)
19
19
  end
20
20
 
21
+ def stanza?
22
+ (send_type? || block_type?) && STANZA_ORDER.include?(method_name)
23
+ end
24
+
21
25
  def heredoc?
22
26
  loc.is_a?(Parser::Source::Map::Heredoc)
23
27
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cask
5
5
  # Version information for the Cask RuboCop plugin.
6
6
  module Version
7
- STRING = '0.2.0'
7
+ STRING = '0.2.1'
8
8
 
9
9
  def self.gem_version
10
10
  Gem::Version.new(STRING)
@@ -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
@@ -17,7 +17,7 @@ module RuboCop
17
17
  # end
18
18
  class NoDslVersion < Cop
19
19
  extend Forwardable
20
- include RuboCop::Cask::CaskHelp
20
+ include CaskHelp
21
21
 
22
22
  MESSAGE = 'Use `%s` instead of `%s`'
23
23
 
@@ -9,7 +9,7 @@ module RuboCop
9
9
  # for more info.
10
10
  class StanzaGrouping < Cop
11
11
  extend Forwardable
12
- include RuboCop::Cask::CaskHelp
12
+ include CaskHelp
13
13
 
14
14
  MISSING_LINE_MSG = 'stanza groups should be separated by a single ' \
15
15
  'empty line'
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # for more info.
9
9
  class StanzaOrder < Cop
10
10
  extend Forwardable
11
- include RuboCop::Cask::CaskHelp
11
+ include CaskHelp
12
12
 
13
13
  MESSAGE = '`%s` stanza out of order'
14
14
 
@@ -29,7 +29,7 @@ describe RuboCop::Cop::Cask::NoDslVersion do
29
29
 
30
30
  include_examples 'reports offenses'
31
31
 
32
- include_examples 'autocorrects offenses'
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 offenses'
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 offenses'
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 offenses'
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 offenses'
132
+ include_examples 'autocorrects source'
133
133
  end
134
134
 
135
- context 'when a stanza includes a heredoc' do
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
- This is a multiline caveat.
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
- Let's hope it doesn't cause any problems!
165
- EOS
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
- it 'autocorrects as expected' do
173
- new_source = autocorrect_source(cop, source)
174
- expect(new_source).to eq(Array(correct_source).join("\n"))
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 offenses'
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 offenses'
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
- new_source = autocorrect_source(cop, source)
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 a stanza includes a heredoc' do
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
- This is a multiline caveat.
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
- Let's hope it doesn't cause any problems!
168
- EOS
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
- caveats <<-EOS.undent
184
- This is a multiline caveat.
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
- it 'autocorrects as expected' do
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
- inspect_source(cop, source)
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
- inspect_source(cop, source)
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 offenses' do
20
- it 'autocorrects offenses' do
21
- new_source = autocorrect_source(cop, source)
22
- expect(new_source).to eq(Array(correct_source).join("\n"))
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.0
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-03 00:00:00.000000000 Z
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