rubocop-cask 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require 'rubocop'
2
2
 
3
- rubocop_path = File.join(File.dirname(__FILE__), '../vendor/rubocop')
3
+ project_path = File.join(File.dirname(__FILE__), '..')
4
+ rubocop_path = File.join(project_path, 'vendor/rubocop')
4
5
  unless File.directory?(rubocop_path)
5
6
  fail "Can't run specs without a local RuboCop checkout. Look in the README."
6
7
  end
7
8
  Dir["#{rubocop_path}/spec/support/**/*.rb"].each { |f| require f }
9
+ Dir["#{project_path}/spec/support/**/*.rb"].each { |f| require f }
8
10
 
9
11
  RSpec.configure do |config|
10
12
  config.order = :random
@@ -0,0 +1,33 @@
1
+ module CopSharedExamples
2
+ shared_examples 'does not report any offenses' do
3
+ it 'does not report any offenses' do
4
+ inspect_source(cop, source)
5
+ expect(cop.offenses).to be_empty
6
+ end
7
+ end
8
+
9
+ shared_examples 'reports offenses' do
10
+ it 'reports offenses' do
11
+ inspect_source(cop, source)
12
+ expect(cop.offenses.size).to eq(expected_offenses.size)
13
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
14
+ expect_offense(expected, actual)
15
+ end
16
+ end
17
+ end
18
+
19
+ shared_examples 'autocorrects offenses' do
20
+ it 'autocorrects offenses' do
21
+ new_source = autocorrect_source(cop, source)
22
+ expect(new_source).to eq(Array(correct_source).join("\n"))
23
+ end
24
+ end
25
+
26
+ def expect_offense(expected, actual)
27
+ expect(actual.message).to eq(expected[:message])
28
+ expect(actual.severity).to eq(expected[:severity])
29
+ expect(actual.line).to eq(expected[:line])
30
+ expect(actual.column).to eq(expected[:column])
31
+ expect(actual.location.source).to eq(expected[:source])
32
+ end
33
+ 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.1.0
4
+ version: 0.2.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: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2016-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,16 +39,24 @@ files:
39
39
  - README.md
40
40
  - config/default.yml
41
41
  - lib/rubocop-cask.rb
42
- - lib/rubocop/cask/cask_block.rb
43
- - lib/rubocop/cask/cask_header.rb
42
+ - lib/rubocop/cask/ast/cask_block.rb
43
+ - lib/rubocop/cask/ast/cask_header.rb
44
+ - lib/rubocop/cask/ast/stanza.rb
44
45
  - lib/rubocop/cask/cask_help.rb
46
+ - lib/rubocop/cask/constants.rb
47
+ - lib/rubocop/cask/extend/astrolabe/node.rb
48
+ - lib/rubocop/cask/extend/string.rb
45
49
  - lib/rubocop/cask/inject.rb
46
- - lib/rubocop/cask/node_help.rb
47
50
  - lib/rubocop/cask/version.rb
48
51
  - lib/rubocop/cop/cask/no_dsl_version.rb
52
+ - lib/rubocop/cop/cask/stanza_grouping.rb
53
+ - lib/rubocop/cop/cask/stanza_order.rb
49
54
  - spec/project_spec.rb
50
55
  - spec/rubocop/cop/cask/no_dsl_version_spec.rb
56
+ - spec/rubocop/cop/cask/stanza_grouping_spec.rb
57
+ - spec/rubocop/cop/cask/stanza_order_spec.rb
51
58
  - spec/spec_helper.rb
59
+ - spec/support/cop_shared_examples.rb
52
60
  homepage: https://github.com/caskroom/rubocop-cask
53
61
  licenses:
54
62
  - MIT
@@ -76,4 +84,7 @@ summary: Code style checking for Homebrew-Cask files
76
84
  test_files:
77
85
  - spec/project_spec.rb
78
86
  - spec/rubocop/cop/cask/no_dsl_version_spec.rb
87
+ - spec/rubocop/cop/cask/stanza_grouping_spec.rb
88
+ - spec/rubocop/cop/cask/stanza_order_spec.rb
79
89
  - spec/spec_helper.rb
90
+ - spec/support/cop_shared_examples.rb
@@ -1,20 +0,0 @@
1
- module RuboCop
2
- module Cask
3
- # This class wraps the AST block node that represents the entire cask
4
- # definition. It includes various helper methods to aid cops in their
5
- # analysis.
6
- class CaskBlock
7
- include CaskHelp
8
-
9
- attr_reader :block_node
10
-
11
- def initialize(block_node)
12
- @block_node = block_node
13
- end
14
-
15
- def header
16
- @header ||= CaskHeader.new(method_node(block_node))
17
- end
18
- end
19
- end
20
- end
@@ -1,59 +0,0 @@
1
- module RuboCop
2
- module Cask
3
- # This class wraps the AST method node that represents the cask header. It
4
- # includes various helper methods to aid cops in their analysis.
5
- class CaskHeader
6
- include CaskHelp
7
-
8
- attr_reader :method_node
9
-
10
- def initialize(method_node)
11
- @method_node = method_node
12
- end
13
-
14
- def dsl_version?
15
- hash_node
16
- end
17
-
18
- def test_cask?
19
- header_method_name == :test_cask || dsl_version.to_s.include?('test')
20
- end
21
-
22
- def header_str
23
- @header_str ||= source_range.source
24
- end
25
-
26
- def source_range
27
- @source_range ||= method_node.loc.expression
28
- end
29
-
30
- def preferred_header_str
31
- "#{preferred_header_method_name} '#{cask_token}'"
32
- end
33
-
34
- def preferred_header_method_name
35
- test_cask? ? :test_cask : :cask
36
- end
37
-
38
- def header_method_name
39
- @header_method_name ||= method_name(method_node)
40
- end
41
-
42
- def dsl_version
43
- @dsl_version ||= key_node(pair_node).children.first
44
- end
45
-
46
- def cask_token
47
- @cask_token ||= value_node(pair_node).children.first
48
- end
49
-
50
- def hash_node
51
- @hash_node ||= hash_children(method_node).first
52
- end
53
-
54
- def pair_node
55
- @pair_node ||= pair_children(hash_node).first
56
- end
57
- end
58
- end
59
- end
@@ -1,81 +0,0 @@
1
- module RuboCop
2
- module Cask
3
- # Helpers for traversing AST nodes
4
- module NodeHelp
5
- def root_node
6
- processed_source.ast
7
- end
8
-
9
- def node?(node, type: nil)
10
- return unless node.is_a?(Parser::AST::Node)
11
- type ? node.type == type : true
12
- end
13
-
14
- def method?(node)
15
- node?(node, type: :send)
16
- end
17
-
18
- def block?(node)
19
- node?(node, type: :block)
20
- end
21
-
22
- def hash?(node)
23
- node?(node, type: :hash)
24
- end
25
-
26
- def pair?(node)
27
- node?(node, type: :pair)
28
- end
29
-
30
- def node_children(node, type: nil)
31
- node.children.select { |e| node?(e, type: type) }
32
- end
33
-
34
- def method_children(node)
35
- node_children(node, type: :send)
36
- end
37
-
38
- def block_children(node)
39
- node_children(node, type: :block)
40
- end
41
-
42
- def hash_children(node)
43
- node_children(node, type: :hash)
44
- end
45
-
46
- def pair_children(node)
47
- node_children(node, type: :pair)
48
- end
49
-
50
- def method_node(block_node)
51
- fail 'Not a block node' unless block?(block_node)
52
- method_node, _args, _body = *block_node
53
- method_node
54
- end
55
-
56
- def method_name(method_node)
57
- fail 'Not a send node' unless method?(method_node)
58
- _receiver, method_name, *_method_args = *method_node
59
- method_name
60
- end
61
-
62
- def method_args(method_node)
63
- fail 'Not a send node' unless method?(method_node)
64
- _receiver, _method_name, *method_args = *method_node
65
- method_args
66
- end
67
-
68
- def key_node(pair_node)
69
- fail 'Not a pair node' unless pair?(pair_node)
70
- key_node, _value_node = *pair_node
71
- key_node
72
- end
73
-
74
- def value_node(pair_node)
75
- fail 'Not a pair node' unless pair?(pair_node)
76
- _key_node, value_node = *pair_node
77
- value_node
78
- end
79
- end
80
- end
81
- end