rubocop-cask 0.0.0 → 0.0.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: 28972420dc9ce7f5af5f9acd84d29315618b81b6
4
- data.tar.gz: 7805e7dc619fd148d982a7397a7cf49c0eb7aa17
3
+ metadata.gz: a7bfd4f036ef39c44b9eb7b4674f42f9b01914c8
4
+ data.tar.gz: 22211aefd4d93daeb700fcdbb2b1749b539cbc5f
5
5
  SHA512:
6
- metadata.gz: 898b80daadf2ab178beae041529bb41e580d6fb59c031b46c03411132d9ec0a829099204024efa22e5940f02e46d412ed723a30797ee4c4c9f0a58d1c4250a6a
7
- data.tar.gz: 950eaf10f6c9cf303b10d0d38b89355ddb6ac3652b19788e63f71cef51a01d7c0ae043a5c855b2479e20d60473b2c21f22cc940d193dc09ec5ae6521f68e7c7e
6
+ metadata.gz: 7ff1dfab7f15095c227549f4dc54d44c1cab1c398b64767c070c01e38d60b46f65f4c5233ae1a101111428a1e1bcfc436f8c18f1a2f43c9aa60c976a73134689
7
+ data.tar.gz: 5807adcf506a9da06929422184d3d831665abf94d5f532d0c11d801f86718812b78f54cb7023af5d7f8ccdae348ff452ddd65892def4bfa64ee3f703a824266a
@@ -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.0.0'
7
+ STRING = '0.0.1'
8
8
 
9
9
  def self.gem_version
10
10
  Gem::Version.new(STRING)
@@ -14,7 +14,7 @@ module RuboCop
14
14
  # ...
15
15
  # end
16
16
  class NoDslVersion < Cop
17
- MESSAGE = "Use `%s '%s'` instead of `%s %s => '%s'`"
17
+ MESSAGE = 'Use `%s` instead of `%s`'
18
18
 
19
19
  CASK_METHOD_NAMES = [:cask, :test_cask]
20
20
 
@@ -22,19 +22,26 @@ module RuboCop
22
22
  method, _args, _body = node.children
23
23
  _receiver, method_name, object = method.children
24
24
  return unless CASK_METHOD_NAMES.include?(method_name)
25
- return unless object.type == :hash
26
25
  check(method_name, object)
27
26
  end
28
27
 
29
28
  private
30
29
 
31
30
  def check(method_name, object)
31
+ return unless object.type == :hash
32
+ message = build_message(method_name, object)
33
+ add_offense(object, :expression, message)
34
+ end
35
+
36
+ def build_message(method_name, object)
32
37
  left, right = *object.children.first
33
- dsl_version_sym = left.children.first
34
38
  cask_token = right.children.first
35
- message = format(MESSAGE, method_name, cask_token, method_name,
36
- dsl_version_sym.inspect, cask_token)
37
- add_offense(object, :expression, message)
39
+ dsl_version_str = left.children.first.to_s
40
+ new_method_name =
41
+ dsl_version_str.include?('test') ? :test_cask : method_name
42
+ preferred_header = "#{new_method_name} '#{cask_token}'"
43
+ actual_header = "#{method_name} #{object.loc.expression.source}"
44
+ format(MESSAGE, preferred_header, actual_header)
38
45
  end
39
46
  end
40
47
  end
@@ -14,6 +14,19 @@ describe RuboCop::Cop::Cask::NoDslVersion do
14
14
  .to eq([":v1 => 'foo'"])
15
15
  end
16
16
 
17
+ it 'checks for dsl version with test in cask header' do
18
+ inspect_source(cop, [
19
+ "cask :v1test => 'foo' do",
20
+ 'end'
21
+ ])
22
+ expect(cop.offenses.size).to eq(1)
23
+ expect(cop.offenses.first.line).to eq(1)
24
+ expect(cop.messages)
25
+ .to eq(["Use `test_cask 'foo'` instead of `cask :v1test => 'foo'`"])
26
+ expect(cop.highlights)
27
+ .to eq([":v1test => 'foo'"])
28
+ end
29
+
17
30
  it 'ignores cask header with no dsl version' do
18
31
  inspect_source(cop, [
19
32
  "cask 'foo' do",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-cask
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hagins