rubocop-cask 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +4 -0
- data/lib/rubocop/cask/version.rb +1 -1
- data/lib/rubocop/cop/cask/homepage_matches_url.rb +112 -0
- data/lib/rubocop/cop/cask/no_dsl_version.rb +1 -1
- data/lib/rubocop/cop/cask/stanza_grouping.rb +2 -2
- data/lib/rubocop/cop/cask/stanza_order.rb +1 -1
- data/lib/rubocop-cask.rb +1 -0
- data/spec/rubocop/cop/cask/homepage_matches_url_spec.rb +118 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c70b535a7f7a0aade9f2fb33eec5a52c6ed63c
|
4
|
+
data.tar.gz: 67f22d2efeaa1e20df95f9737c50234d7c929501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34d53b4881babc3d66f6cabc6da513f9cf04fa46651ff6ef0e2e9ac3221abaec1145c1dbfa2c5820c46da891db63b1bb1a35be3a7629c8d3855034517671b412
|
7
|
+
data.tar.gz: d65f6a09b2ed8aaa99755a8f5a8bed5e117fa85ac0af9be6e494b13e77bca39add26b21b74e36dc6b89d8264a0aeb87d10708ed014a47aec502011385c81b540
|
data/config/default.yml
CHANGED
@@ -6,6 +6,10 @@ Cask/NoDslVersion:
|
|
6
6
|
Description: 'Do not use the deprecated DSL version syntax in your cask header.'
|
7
7
|
Enabled: true
|
8
8
|
|
9
|
+
Cask/HomepageMatchesUrl:
|
10
|
+
Description: 'Ensure that the homepage and url match, otherwise add a comment. More info at https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/url.md#when-url-and-homepage-hostnames-differ-add-a-comment'
|
11
|
+
Enabled: true
|
12
|
+
|
9
13
|
Cask/StanzaGrouping:
|
10
14
|
Description: 'Ensure that cask stanzas are grouped correctly. More info at https://github.com/caskroom/homebrew-cask/blob/master/CONTRIBUTING.md#stanza-order'
|
11
15
|
Enabled: true
|
data/lib/rubocop/cask/version.rb
CHANGED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Cask
|
6
|
+
# This cop checks that a cask's homepage matches the download url,
|
7
|
+
# or if it doesn't, checks if a comment in the form
|
8
|
+
# `# example.com was verified as official when first introduced to the cask`
|
9
|
+
# is present.
|
10
|
+
class HomepageMatchesUrl < Cop
|
11
|
+
extend Forwardable
|
12
|
+
include CaskHelp
|
13
|
+
|
14
|
+
MSG_NO_MATCH = '`%s` does not match `%s`'.freeze
|
15
|
+
|
16
|
+
MSG_MISSING = '`%s` does not match `%s`, a comment in the form of ' \
|
17
|
+
'`# example.com was verified as official when first ' \
|
18
|
+
'introduced to the cask` has to be added above the ' \
|
19
|
+
'`url` stanza'.freeze
|
20
|
+
|
21
|
+
MSG_UNNECESSARY = '`%s` matches `%s`, the comment above the `url` ' \
|
22
|
+
'stanza is unnecessary'.freeze
|
23
|
+
|
24
|
+
def on_cask(cask_block)
|
25
|
+
@cask_block = cask_block
|
26
|
+
add_offenses
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :cask_block
|
32
|
+
def_delegators :cask_block, :cask_node, :toplevel_stanzas,
|
33
|
+
:sorted_toplevel_stanzas
|
34
|
+
|
35
|
+
def add_offenses
|
36
|
+
toplevel_stanzas.select(&:url?).each do |url|
|
37
|
+
if url_match_homepage?(url)
|
38
|
+
next unless comment?(url)
|
39
|
+
add_offense_unnecessary_comment(url)
|
40
|
+
elsif !comment?(url)
|
41
|
+
add_offense_missing_comment(url)
|
42
|
+
elsif !comment_matches_url?(url)
|
43
|
+
add_offense_no_match(url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_offense_missing_comment(stanza)
|
49
|
+
range = stanza.source_range
|
50
|
+
add_offense(range, range, format(MSG_MISSING, url(stanza), homepage))
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_offense_unnecessary_comment(stanza)
|
54
|
+
comment = comment(stanza).loc.expression
|
55
|
+
add_offense(comment,
|
56
|
+
comment,
|
57
|
+
format(MSG_UNNECESSARY, url(stanza), homepage))
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_offense_no_match(stanza)
|
61
|
+
comment = comment(stanza).loc.expression
|
62
|
+
add_offense(comment,
|
63
|
+
comment,
|
64
|
+
format(MSG_NO_MATCH, url_from_comment(stanza), url(stanza)))
|
65
|
+
end
|
66
|
+
|
67
|
+
def comment?(stanza)
|
68
|
+
!stanza.comments.empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
def comment(stanza)
|
72
|
+
stanza.comments.last
|
73
|
+
end
|
74
|
+
|
75
|
+
def url_from_comment(stanza)
|
76
|
+
comment(stanza).text
|
77
|
+
.sub(/.*# ([^ ]*) was verified as official when first introduced to the cask$/, '\1')
|
78
|
+
end
|
79
|
+
|
80
|
+
def comment_matches_url?(stanza)
|
81
|
+
url(stanza).include?(url_from_comment(stanza))
|
82
|
+
end
|
83
|
+
|
84
|
+
def strip_http(url)
|
85
|
+
url.sub(%r{^.*://(?=www\.)?}, '')
|
86
|
+
end
|
87
|
+
|
88
|
+
def extract_stanza(stanza)
|
89
|
+
stanza.source
|
90
|
+
.sub(/#{stanza.stanza_name} \'(.*)\'/, '\1')
|
91
|
+
.sub(/#{stanza.stanza_name} \"(.*)\"/, '\1')
|
92
|
+
end
|
93
|
+
|
94
|
+
def domain(url)
|
95
|
+
strip_http(url).gsub(%r{^([^/]+).*}, '\1')
|
96
|
+
end
|
97
|
+
|
98
|
+
def url_match_homepage?(url)
|
99
|
+
url(url).include?(homepage)
|
100
|
+
end
|
101
|
+
|
102
|
+
def url(stanza)
|
103
|
+
domain(extract_stanza(stanza))
|
104
|
+
end
|
105
|
+
|
106
|
+
def homepage
|
107
|
+
url(toplevel_stanzas.find(&:homepage?))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -11,10 +11,10 @@ module RuboCop
|
|
11
11
|
include CaskHelp
|
12
12
|
|
13
13
|
MISSING_LINE_MSG = 'stanza groups should be separated by a single ' \
|
14
|
-
'empty line'
|
14
|
+
'empty line'.freeze
|
15
15
|
|
16
16
|
EXTRA_LINE_MSG = 'stanzas within the same group should have no lines ' \
|
17
|
-
'between them'
|
17
|
+
'between them'.freeze
|
18
18
|
|
19
19
|
def on_cask(cask_block)
|
20
20
|
@cask_block = cask_block
|
data/lib/rubocop-cask.rb
CHANGED
@@ -12,6 +12,7 @@ require 'rubocop/cask/inject'
|
|
12
12
|
RuboCop::Cask::Inject.defaults!
|
13
13
|
|
14
14
|
require 'rubocop/cop/cask/mixin/cask_help'
|
15
|
+
require 'rubocop/cop/cask/homepage_matches_url'
|
15
16
|
require 'rubocop/cop/cask/no_dsl_version'
|
16
17
|
require 'rubocop/cop/cask/stanza_order'
|
17
18
|
require 'rubocop/cop/cask/stanza_grouping'
|
@@ -0,0 +1,118 @@
|
|
1
|
+
describe RuboCop::Cop::Cask::HomepageMatchesUrl do
|
2
|
+
include CopSharedExamples
|
3
|
+
|
4
|
+
subject(:cop) { described_class.new }
|
5
|
+
let(:missing_line_msg) do
|
6
|
+
'stanza groups should be separated by a single empty line'
|
7
|
+
end
|
8
|
+
let(:extra_line_msg) do
|
9
|
+
'stanzas within the same group should have no lines between them'
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when the url matches the homepage' do
|
13
|
+
context 'and there is no comment' do
|
14
|
+
let(:source) do
|
15
|
+
<<-CASK.undent
|
16
|
+
cask 'foo' do
|
17
|
+
url 'https://foo.example.com/foo.zip'
|
18
|
+
homepage 'https://foo.example.com'
|
19
|
+
end
|
20
|
+
CASK
|
21
|
+
end
|
22
|
+
|
23
|
+
include_examples 'does not report any offenses'
|
24
|
+
end
|
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
|
+
}]
|
46
|
+
end
|
47
|
+
|
48
|
+
include_examples 'reports offenses'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
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
|
55
|
+
let(:source) do
|
56
|
+
<<-CASK.undent
|
57
|
+
cask 'foo' do
|
58
|
+
# example.com was verified as official when first introduced to the cask
|
59
|
+
url 'https://example.com/foo.zip'
|
60
|
+
homepage 'https://foo.example.com'
|
61
|
+
end
|
62
|
+
CASK
|
63
|
+
end
|
64
|
+
|
65
|
+
include_examples 'does not report any offenses'
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'which does not match the url' do
|
69
|
+
let(:source) do
|
70
|
+
<<-CASK.undent
|
71
|
+
cask 'foo' do
|
72
|
+
# example.org was verified as official when first introduced to the cask
|
73
|
+
url 'https://example.com/foo.zip'
|
74
|
+
homepage 'https://foo.example.com'
|
75
|
+
end
|
76
|
+
CASK
|
77
|
+
end
|
78
|
+
let(:expected_offenses) do
|
79
|
+
[{
|
80
|
+
message: '`example.org` does not match `example.com`',
|
81
|
+
severity: :convention,
|
82
|
+
line: 2,
|
83
|
+
column: 2,
|
84
|
+
source: '# example.org was verified as official when ' \
|
85
|
+
'first introduced to the cask'
|
86
|
+
}]
|
87
|
+
end
|
88
|
+
|
89
|
+
include_examples 'reports offenses'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'but the comment is missing' do
|
94
|
+
let(:source) do
|
95
|
+
<<-CASK.undent
|
96
|
+
cask 'foo' do
|
97
|
+
url 'https://example.com/foo.zip'
|
98
|
+
homepage 'https://foo.example.com'
|
99
|
+
end
|
100
|
+
CASK
|
101
|
+
end
|
102
|
+
let(:expected_offenses) do
|
103
|
+
[{
|
104
|
+
message: '`example.com` does not match `foo.example.com`, a ' \
|
105
|
+
'comment in the form of `# example.com was verified as ' \
|
106
|
+
'official when first introduced to the cask` has to be ' \
|
107
|
+
'added above the `url` stanza',
|
108
|
+
severity: :convention,
|
109
|
+
line: 2,
|
110
|
+
column: 2,
|
111
|
+
source: "url 'https://example.com/foo.zip'"
|
112
|
+
}]
|
113
|
+
end
|
114
|
+
|
115
|
+
include_examples 'reports offenses'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
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.
|
4
|
+
version: 0.8.0
|
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-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -61,11 +61,13 @@ files:
|
|
61
61
|
- lib/rubocop/cask/extend/string.rb
|
62
62
|
- lib/rubocop/cask/inject.rb
|
63
63
|
- lib/rubocop/cask/version.rb
|
64
|
+
- lib/rubocop/cop/cask/homepage_matches_url.rb
|
64
65
|
- lib/rubocop/cop/cask/mixin/cask_help.rb
|
65
66
|
- lib/rubocop/cop/cask/no_dsl_version.rb
|
66
67
|
- lib/rubocop/cop/cask/stanza_grouping.rb
|
67
68
|
- lib/rubocop/cop/cask/stanza_order.rb
|
68
69
|
- spec/project_spec.rb
|
70
|
+
- spec/rubocop/cop/cask/homepage_matches_url_spec.rb
|
69
71
|
- spec/rubocop/cop/cask/no_dsl_version_spec.rb
|
70
72
|
- spec/rubocop/cop/cask/stanza_grouping_spec.rb
|
71
73
|
- spec/rubocop/cop/cask/stanza_order_spec.rb
|
@@ -97,6 +99,7 @@ specification_version: 4
|
|
97
99
|
summary: Code style checking for Homebrew-Cask files
|
98
100
|
test_files:
|
99
101
|
- spec/project_spec.rb
|
102
|
+
- spec/rubocop/cop/cask/homepage_matches_url_spec.rb
|
100
103
|
- spec/rubocop/cop/cask/no_dsl_version_spec.rb
|
101
104
|
- spec/rubocop/cop/cask/stanza_grouping_spec.rb
|
102
105
|
- spec/rubocop/cop/cask/stanza_order_spec.rb
|