rubocop-cask 0.0.0 → 0.0.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7bfd4f036ef39c44b9eb7b4674f42f9b01914c8
|
4
|
+
data.tar.gz: 22211aefd4d93daeb700fcdbb2b1749b539cbc5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff1dfab7f15095c227549f4dc54d44c1cab1c398b64767c070c01e38d60b46f65f4c5233ae1a101111428a1e1bcfc436f8c18f1a2f43c9aa60c976a73134689
|
7
|
+
data.tar.gz: 5807adcf506a9da06929422184d3d831665abf94d5f532d0c11d801f86718812b78f54cb7023af5d7f8ccdae348ff452ddd65892def4bfa64ee3f703a824266a
|
data/lib/rubocop/cask/version.rb
CHANGED
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# ...
|
15
15
|
# end
|
16
16
|
class NoDslVersion < Cop
|
17
|
-
MESSAGE =
|
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
|
-
|
36
|
-
|
37
|
-
|
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",
|