rubocop-cask 0.8.0 → 0.8.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: 02c2b2529f1fade3ca9a1cb469bd93a3045691a6
|
4
|
+
data.tar.gz: d917f20d41ec9a706310409cff6c845e0931b94c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb0f81dcea7c2f56ffa6817fa4dac7f5ae698391f7dadbd465f4c3ba9bb9621017bebe43f2f60287727b424bfc95c6373e97eccd287a1a410d1934b238da7f6c
|
7
|
+
data.tar.gz: 603af6daa35201369ac47f03f8a89ca32dd24fe6576bd5e3738c75a4e701bf6c741e5f10471a8b85a2becc16d59183a027431d2228f7317bfd0f6f32a64730a0
|
data/lib/rubocop/cask/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'forwardable'
|
2
|
+
require 'public_suffix'
|
2
3
|
|
3
4
|
module RuboCop
|
4
5
|
module Cop
|
@@ -14,7 +15,7 @@ module RuboCop
|
|
14
15
|
MSG_NO_MATCH = '`%s` does not match `%s`'.freeze
|
15
16
|
|
16
17
|
MSG_MISSING = '`%s` does not match `%s`, a comment in the form of ' \
|
17
|
-
'`#
|
18
|
+
'`# %s was verified as official when first ' \
|
18
19
|
'introduced to the cask` has to be added above the ' \
|
19
20
|
'`url` stanza'.freeze
|
20
21
|
|
@@ -35,7 +36,7 @@ module RuboCop
|
|
35
36
|
def add_offenses
|
36
37
|
toplevel_stanzas.select(&:url?).each do |url|
|
37
38
|
if url_match_homepage?(url)
|
38
|
-
next unless comment?(url)
|
39
|
+
next unless comment?(url) && comment_matches_url?(url)
|
39
40
|
add_offense_unnecessary_comment(url)
|
40
41
|
elsif !comment?(url)
|
41
42
|
add_offense_missing_comment(url)
|
@@ -47,21 +48,22 @@ module RuboCop
|
|
47
48
|
|
48
49
|
def add_offense_missing_comment(stanza)
|
49
50
|
range = stanza.source_range
|
50
|
-
|
51
|
+
url_domain = domain(stanza)
|
52
|
+
add_offense(range, range, format(MSG_MISSING, url_domain, homepage, url_domain))
|
51
53
|
end
|
52
54
|
|
53
55
|
def add_offense_unnecessary_comment(stanza)
|
54
56
|
comment = comment(stanza).loc.expression
|
55
57
|
add_offense(comment,
|
56
58
|
comment,
|
57
|
-
format(MSG_UNNECESSARY,
|
59
|
+
format(MSG_UNNECESSARY, domain(stanza), homepage))
|
58
60
|
end
|
59
61
|
|
60
62
|
def add_offense_no_match(stanza)
|
61
63
|
comment = comment(stanza).loc.expression
|
62
64
|
add_offense(comment,
|
63
65
|
comment,
|
64
|
-
format(MSG_NO_MATCH, url_from_comment(stanza),
|
66
|
+
format(MSG_NO_MATCH, url_from_comment(stanza), full_url(stanza)))
|
65
67
|
end
|
66
68
|
|
67
69
|
def comment?(stanza)
|
@@ -78,33 +80,33 @@ module RuboCop
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def comment_matches_url?(stanza)
|
81
|
-
|
83
|
+
full_url(stanza).include?(url_from_comment(stanza))
|
82
84
|
end
|
83
85
|
|
84
|
-
def
|
85
|
-
url.sub(%r{^.*://(
|
86
|
+
def strip_url_scheme(url)
|
87
|
+
url.sub(%r{^.*://(www\.)?}, '')
|
86
88
|
end
|
87
89
|
|
88
|
-
def
|
89
|
-
stanza.
|
90
|
-
.sub(/#{stanza.stanza_name} \'(.*)\'/, '\1')
|
91
|
-
.sub(/#{stanza.stanza_name} \"(.*)\"/, '\1')
|
90
|
+
def domain(stanza)
|
91
|
+
strip_url_scheme(extract_url(stanza)).gsub(%r{^([^/]+).*}, '\1')
|
92
92
|
end
|
93
93
|
|
94
|
-
def
|
95
|
-
|
94
|
+
def extract_url(stanza)
|
95
|
+
string = stanza.stanza_node.children[2]
|
96
|
+
return string.str_content if string.str_type?
|
97
|
+
string.to_s.gsub(%r{.*"([a-z0-9]+\:\/\/[^"]+)".*}m, '\1')
|
96
98
|
end
|
97
99
|
|
98
|
-
def url_match_homepage?(
|
99
|
-
|
100
|
+
def url_match_homepage?(stanza)
|
101
|
+
PublicSuffix.domain(domain(stanza)) == homepage
|
100
102
|
end
|
101
103
|
|
102
|
-
def
|
103
|
-
|
104
|
+
def full_url(stanza)
|
105
|
+
strip_url_scheme(extract_url(stanza))
|
104
106
|
end
|
105
107
|
|
106
108
|
def homepage
|
107
|
-
|
109
|
+
PublicSuffix.domain(domain(toplevel_stanzas.find(&:homepage?)))
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
@@ -23,41 +23,45 @@ describe RuboCop::Cop::Cask::HomepageMatchesUrl do
|
|
23
23
|
include_examples 'does not report any offenses'
|
24
24
|
end
|
25
25
|
|
26
|
-
context '
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
'the comment above the `url` stanza is unnecessary',
|
40
|
-
severity: :convention,
|
41
|
-
line: 2,
|
42
|
-
column: 2,
|
43
|
-
source: '# foo.example.com was verified as official when ' \
|
44
|
-
'first introduced to the cask'
|
45
|
-
}]
|
26
|
+
context 'and the url stanza has a referrer' do
|
27
|
+
context 'and no interpolation' do
|
28
|
+
let(:source) do
|
29
|
+
<<-CASK.undent
|
30
|
+
cask 'foo' do
|
31
|
+
url 'https://foo.example.com/foo.zip',
|
32
|
+
referrer: 'https://example.com/foo/'
|
33
|
+
homepage 'https://foo.example.com'
|
34
|
+
end
|
35
|
+
CASK
|
36
|
+
end
|
37
|
+
|
38
|
+
include_examples 'does not report any offenses'
|
46
39
|
end
|
47
40
|
|
48
|
-
|
41
|
+
context 'and interpolation' do
|
42
|
+
let(:source) do
|
43
|
+
<<-CASK.undent
|
44
|
+
cask 'foo' do
|
45
|
+
version '1.8.0_72,8.13.0.5'
|
46
|
+
url "https://foo.example.com/foo-\#{version.after_comma}-\#{version.minor}.\#{version.patch}.\#{version.before_comma.sub(\%r{.*_}, '')}.zip",
|
47
|
+
referrer: 'https://example.com/foo/'
|
48
|
+
homepage 'https://foo.example.com'
|
49
|
+
end
|
50
|
+
CASK
|
51
|
+
end
|
52
|
+
|
53
|
+
include_examples 'does not report any offenses'
|
54
|
+
end
|
49
55
|
end
|
50
|
-
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
context 'which matches the url' do
|
57
|
+
context 'but there is a comment' do
|
58
|
+
context 'which does not match the url' do
|
55
59
|
let(:source) do
|
56
60
|
<<-CASK.undent
|
57
61
|
cask 'foo' do
|
58
|
-
#
|
62
|
+
# this is just a comment with information
|
59
63
|
url 'https://example.com/foo.zip'
|
60
|
-
homepage 'https://
|
64
|
+
homepage 'https://example.com'
|
61
65
|
end
|
62
66
|
CASK
|
63
67
|
end
|
@@ -65,23 +69,82 @@ describe RuboCop::Cop::Cask::HomepageMatchesUrl do
|
|
65
69
|
include_examples 'does not report any offenses'
|
66
70
|
end
|
67
71
|
|
72
|
+
context 'which matches the url' do
|
73
|
+
let(:source) do
|
74
|
+
<<-CASK.undent
|
75
|
+
cask 'foo' do
|
76
|
+
# foo.example.com was verified as official when first introduced to the cask
|
77
|
+
url 'https://foo.example.com/foo.zip'
|
78
|
+
homepage 'https://foo.example.com'
|
79
|
+
end
|
80
|
+
CASK
|
81
|
+
end
|
82
|
+
let(:expected_offenses) do
|
83
|
+
[{
|
84
|
+
message: '`foo.example.com` matches `example.com`, ' \
|
85
|
+
'the comment above the `url` stanza is unnecessary',
|
86
|
+
severity: :convention,
|
87
|
+
line: 2,
|
88
|
+
column: 2,
|
89
|
+
source: '# foo.example.com was verified as official when ' \
|
90
|
+
'first introduced to the cask'
|
91
|
+
}]
|
92
|
+
end
|
93
|
+
|
94
|
+
include_examples 'reports offenses'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when the url does not match the homepage' do
|
100
|
+
context 'and there is a comment' do
|
101
|
+
context 'which matches the url' do
|
102
|
+
context 'and does not have slashes' do
|
103
|
+
let(:source) do
|
104
|
+
<<-CASK.undent
|
105
|
+
cask 'foo' do
|
106
|
+
# example.com was verified as official when first introduced to the cask
|
107
|
+
url 'https://example.com/foo.zip'
|
108
|
+
homepage 'https://foo.example.org'
|
109
|
+
end
|
110
|
+
CASK
|
111
|
+
end
|
112
|
+
|
113
|
+
include_examples 'does not report any offenses'
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'and has slashes' do
|
117
|
+
let(:source) do
|
118
|
+
<<-CASK.undent
|
119
|
+
cask 'foo' do
|
120
|
+
# example.com/vendor/app was verified as official when first introduced to the cask
|
121
|
+
url 'https://downloads.example.com/vendor/app/foo.zip'
|
122
|
+
homepage 'https://vendor.example.org/app/'
|
123
|
+
end
|
124
|
+
CASK
|
125
|
+
end
|
126
|
+
|
127
|
+
include_examples 'does not report any offenses'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
68
131
|
context 'which does not match the url' do
|
69
132
|
let(:source) do
|
70
133
|
<<-CASK.undent
|
71
134
|
cask 'foo' do
|
72
|
-
# example.
|
73
|
-
url 'https://example.
|
135
|
+
# example.com was verified as official when first introduced to the cask
|
136
|
+
url 'https://example.org/foo.zip'
|
74
137
|
homepage 'https://foo.example.com'
|
75
138
|
end
|
76
139
|
CASK
|
77
140
|
end
|
78
141
|
let(:expected_offenses) do
|
79
142
|
[{
|
80
|
-
message: '`example.
|
143
|
+
message: '`example.com` does not match `example.org/foo.zip`',
|
81
144
|
severity: :convention,
|
82
145
|
line: 2,
|
83
146
|
column: 2,
|
84
|
-
source: '# example.
|
147
|
+
source: '# example.com was verified as official when ' \
|
85
148
|
'first introduced to the cask'
|
86
149
|
}]
|
87
150
|
end
|
@@ -95,13 +158,13 @@ describe RuboCop::Cop::Cask::HomepageMatchesUrl do
|
|
95
158
|
<<-CASK.undent
|
96
159
|
cask 'foo' do
|
97
160
|
url 'https://example.com/foo.zip'
|
98
|
-
homepage 'https://
|
161
|
+
homepage 'https://example.org'
|
99
162
|
end
|
100
163
|
CASK
|
101
164
|
end
|
102
165
|
let(:expected_offenses) do
|
103
166
|
[{
|
104
|
-
message: '`example.com` does not match `
|
167
|
+
message: '`example.com` does not match `example.org`, a ' \
|
105
168
|
'comment in the form of `# example.com was verified as ' \
|
106
169
|
'official when first introduced to the cask` has to be ' \
|
107
170
|
'added above the `url` stanza',
|
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.8.
|
4
|
+
version: 0.8.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-07-
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|