rubocop-cask 0.8.0 → 0.8.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: 20c70b535a7f7a0aade9f2fb33eec5a52c6ed63c
4
- data.tar.gz: 67f22d2efeaa1e20df95f9737c50234d7c929501
3
+ metadata.gz: 02c2b2529f1fade3ca9a1cb469bd93a3045691a6
4
+ data.tar.gz: d917f20d41ec9a706310409cff6c845e0931b94c
5
5
  SHA512:
6
- metadata.gz: 34d53b4881babc3d66f6cabc6da513f9cf04fa46651ff6ef0e2e9ac3221abaec1145c1dbfa2c5820c46da891db63b1bb1a35be3a7629c8d3855034517671b412
7
- data.tar.gz: d65f6a09b2ed8aaa99755a8f5a8bed5e117fa85ac0af9be6e494b13e77bca39add26b21b74e36dc6b89d8264a0aeb87d10708ed014a47aec502011385c81b540
6
+ metadata.gz: eb0f81dcea7c2f56ffa6817fa4dac7f5ae698391f7dadbd465f4c3ba9bb9621017bebe43f2f60287727b424bfc95c6373e97eccd287a1a410d1934b238da7f6c
7
+ data.tar.gz: 603af6daa35201369ac47f03f8a89ca32dd24fe6576bd5e3738c75a4e701bf6c741e5f10471a8b85a2becc16d59183a027431d2228f7317bfd0f6f32a64730a0
@@ -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.8.0'.freeze
7
+ STRING = '0.8.1'.freeze
8
8
 
9
9
  def self.gem_version
10
10
  Gem::Version.new(STRING)
@@ -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
- '`# example.com was verified as official when first ' \
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
- add_offense(range, range, format(MSG_MISSING, url(stanza), homepage))
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, url(stanza), homepage))
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), url(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
- url(stanza).include?(url_from_comment(stanza))
83
+ full_url(stanza).include?(url_from_comment(stanza))
82
84
  end
83
85
 
84
- def strip_http(url)
85
- url.sub(%r{^.*://(?=www\.)?}, '')
86
+ def strip_url_scheme(url)
87
+ url.sub(%r{^.*://(www\.)?}, '')
86
88
  end
87
89
 
88
- def extract_stanza(stanza)
89
- stanza.source
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 domain(url)
95
- strip_http(url).gsub(%r{^([^/]+).*}, '\1')
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?(url)
99
- url(url).include?(homepage)
100
+ def url_match_homepage?(stanza)
101
+ PublicSuffix.domain(domain(stanza)) == homepage
100
102
  end
101
103
 
102
- def url(stanza)
103
- domain(extract_stanza(stanza))
104
+ def full_url(stanza)
105
+ strip_url_scheme(extract_url(stanza))
104
106
  end
105
107
 
106
108
  def homepage
107
- url(toplevel_stanzas.find(&:homepage?))
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 'but there is a comment' do
27
- let(:source) do
28
- <<-CASK.undent
29
- cask 'foo' do
30
- # foo.example.com was verified as official when first introduced to the cask
31
- url 'https://foo.example.com/foo.zip'
32
- homepage 'https://foo.example.com'
33
- end
34
- CASK
35
- end
36
- let(:expected_offenses) do
37
- [{
38
- message: '`foo.example.com` matches `foo.example.com`, ' \
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
- include_examples 'reports offenses'
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
- context 'when the url does not match the homepage' do
53
- context 'and there is a comment' do
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
- # example.com was verified as official when first introduced to the cask
62
+ # this is just a comment with information
59
63
  url 'https://example.com/foo.zip'
60
- homepage 'https://foo.example.com'
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.org was verified as official when first introduced to the cask
73
- url 'https://example.com/foo.zip'
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.org` does not match `example.com`',
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.org was verified as official when ' \
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://foo.example.com'
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 `foo.example.com`, a ' \
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.0
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-03 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop