rubocop-mirego 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 092aa7b1f465b752fe8c6416f871767fb643f3ac
4
+ data.tar.gz: b836c8a3674b77bf3be615b4cb4016ff13c7900b
5
+ SHA512:
6
+ metadata.gz: e2f3a991ac5820e2a8a46fe545337688bc7f53099fd596584da84a736dc3e83c22493c686701c96948aba823d652e0b1732e3409443db120161ddc5a86aa7fe3
7
+ data.tar.gz: faf7cfb1f81200f7b2d24b12af3e121d5fef1b9b7e4d9ec2ea8d864cffb5592b1797a3b7428ed47b67aa30e8b1a413324fddc2149f653b0173ba37d32dee7b4e
data/.rubocop.yml ADDED
@@ -0,0 +1,72 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.1
5
+
6
+ Documentation:
7
+ Enabled: false
8
+
9
+ Encoding:
10
+ Enabled: false
11
+
12
+ LineLength:
13
+ Max: 200
14
+
15
+ AccessModifierIndentation:
16
+ EnforcedStyle: outdent
17
+
18
+ IfUnlessModifier:
19
+ Enabled: false
20
+
21
+ CaseIndentation:
22
+ IndentWhenRelativeTo: end
23
+ IndentOneStep: true
24
+
25
+ MethodLength:
26
+ CountComments: false
27
+ Max: 20
28
+
29
+ SignalException:
30
+ Enabled: false
31
+
32
+ ColonMethodCall:
33
+ Enabled: false
34
+
35
+ AsciiComments:
36
+ Enabled: false
37
+
38
+ RegexpLiteral:
39
+ Enabled: false
40
+
41
+ AssignmentInCondition:
42
+ Enabled: false
43
+
44
+ ParameterLists:
45
+ CountKeywordArgs: false
46
+
47
+ SingleLineBlockParams:
48
+ Methods:
49
+ - reduce:
50
+ - memo
51
+ - item
52
+
53
+ MethodCalledOnDoEndBlock:
54
+ Enabled: true
55
+
56
+ Metrics/AbcSize:
57
+ Enabled: false
58
+
59
+ Style/CollectionMethods:
60
+ Enabled: true
61
+
62
+ Style/SymbolArray:
63
+ Enabled: true
64
+
65
+ Style/ExtraSpacing:
66
+ Enabled: true
67
+
68
+ RSpec/DescribedClass:
69
+ Enabled: false
70
+
71
+ Style/FileName:
72
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ # Use Travis container-based infrastructure
2
+ sudo: false
3
+
4
+ # Ruby baby!
5
+ language: 'ruby'
6
+
7
+ # Only build on our Ruby version
8
+ rvm:
9
+ - '2.3.0'
10
+
11
+ script:
12
+ - 'echo "Checking code style" && bundle exec phare'
13
+ - 'echo "Running tests" && bundle exec rspec'
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-mirego (0.0.2)
5
+ rubocop (= 0.39.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.2.0)
11
+ diff-lcs (1.2.5)
12
+ parser (2.3.0.7)
13
+ ast (~> 2.2)
14
+ phare (0.7.1)
15
+ powerpack (0.1.1)
16
+ rainbow (2.1.0)
17
+ rspec (3.4.0)
18
+ rspec-core (~> 3.4.0)
19
+ rspec-expectations (~> 3.4.0)
20
+ rspec-mocks (~> 3.4.0)
21
+ rspec-core (3.4.4)
22
+ rspec-support (~> 3.4.0)
23
+ rspec-expectations (3.4.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.4.0)
26
+ rspec-mocks (3.4.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-support (3.4.1)
30
+ rubocop (0.39.0)
31
+ parser (>= 2.3.0.7, < 3.0)
32
+ powerpack (~> 0.1)
33
+ rainbow (>= 1.99.1, < 3.0)
34
+ ruby-progressbar (~> 1.7)
35
+ unicode-display_width (~> 1.0, >= 1.0.1)
36
+ rubocop-rspec (1.4.1)
37
+ rubocop (= 0.39.0)
38
+ ruby-progressbar (1.7.5)
39
+ unicode-display_width (1.0.3)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.3)
46
+ phare (~> 0.7)
47
+ rspec (~> 3.4)
48
+ rubocop-mirego!
49
+ rubocop-rspec (~> 1.4, >= 1.4.1)
50
+
51
+ BUNDLED WITH
52
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1 @@
1
+ ## Rubocop-mirego
@@ -0,0 +1,5 @@
1
+ Mirego/ReceiveCounts:
2
+ Enabled: true
3
+
4
+ Mirego/ExplicitReturnValue:
5
+ Enabled: true
@@ -0,0 +1,9 @@
1
+ require 'rubocop'
2
+
3
+ require 'rubocop/mirego/version'
4
+ require 'rubocop/mirego/inject'
5
+
6
+ RuboCop::Mirego::Inject.defaults!
7
+
8
+ require 'rubocop/cop/mirego/receive_counts'
9
+ require 'rubocop/cop/mirego/explicit_return_value'
@@ -0,0 +1,42 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Mirego
4
+ class ExplicitReturnValue < Cop
5
+ MESSAGE = 'Always specify a value with `return`'.freeze
6
+
7
+ def on_def(node)
8
+ _, _, body = *node
9
+ check(node: body)
10
+ end
11
+
12
+ def on_defs(node)
13
+ _, _, _, body = *node
14
+ check(node: body)
15
+ end
16
+
17
+ protected
18
+
19
+ def check(node:)
20
+ expressions = *node
21
+ return nil unless node
22
+
23
+ if return_node_type(node: node)
24
+ check_return_node(node: node, children: node.children)
25
+ elsif expressions.last && return_node_type(node: expressions.last)
26
+ check_return_node(node: node, children: expressions.last.to_a)
27
+ end
28
+ end
29
+
30
+ def check_return_node(node:, children:)
31
+ return nil unless children.empty?
32
+
33
+ add_offense(node, :expression, MESSAGE)
34
+ end
35
+
36
+ def return_node_type(node:)
37
+ node.respond_to?(:type) && node.type == :return
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,38 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Mirego
4
+ class ReceiveCounts < Cop
5
+ MESSAGE = 'Always specify a receive count with `receive`'.freeze
6
+ RECEIVE_COUNTS_METHODS = %i(once twice exactly at_least at_most).freeze
7
+
8
+ def on_send(node)
9
+ receiver, method_name, *args = *node
10
+ return nil unless method_name == :to
11
+ return nil if receiver.nil? || receiver.to_a[1] != :expect
12
+
13
+ methods_name = recursive_methods_name(nodes: args)
14
+ return nil unless methods_name.include? :receive
15
+ return nil unless (methods_name & RECEIVE_COUNTS_METHODS).empty?
16
+
17
+ add_offense(node, :expression, MESSAGE)
18
+ end
19
+
20
+ protected
21
+
22
+ def recursive_methods_name(nodes:)
23
+ methods_name = []
24
+ nodes.each do |node|
25
+ methods_name << node.children[1]
26
+
27
+ until node.children[0].nil?
28
+ node = node.children[0]
29
+ methods_name << node.children[1]
30
+ end
31
+ end
32
+
33
+ methods_name
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ module RuboCop
3
+ module Mirego
4
+ module Inject
5
+ DEFAULT_FILE = File.expand_path('../../../../config/default.yml', __FILE__).freeze
6
+
7
+ def self.defaults!
8
+ path = File.absolute_path(DEFAULT_FILE)
9
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
10
+ config = Config.new(hash, path)
11
+ config = ConfigLoader.merge_with_default(config, path)
12
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module Mirego
3
+ VERSION = '0.0.3'.freeze
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubocop/mirego/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubocop-mirego'
8
+ spec.version = RuboCop::Mirego::VERSION
9
+ spec.authors = ['Jean-François Chaput']
10
+ spec.email = ['jfchaput@mirego.com']
11
+ spec.description = 'Custom cops for Mirego.'
12
+ spec.summary = spec.description
13
+ spec.homepage = 'https://github.com/mirego/rubocop-mirego'
14
+ spec.license = 'BSD 3-Clause'
15
+
16
+ spec.files = `git ls-files`.split($RS)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'rubocop', '0.39.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rspec', '~> 3.4'
25
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.4', '>= 1.4.1'
26
+ spec.add_development_dependency 'phare', '~> 0.7'
27
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Mirego::ExplicitReturnValue do
4
+ let(:cop) { RuboCop::Cop::Mirego::ExplicitReturnValue.new }
5
+
6
+ before { inspect_source(cop, source) }
7
+
8
+ describe 'with a return with a value' do
9
+ let(:source) { 'def test; return nil; end' }
10
+
11
+ it { expect(cop.offenses.size).to eql(0) }
12
+ end
13
+
14
+ describe 'with a return with a value with a conditional' do
15
+ let(:source) { 'def test; return nil unless bool; end' }
16
+
17
+ it { expect(cop.offenses.size).to eql(0) }
18
+ end
19
+
20
+ describe 'with a return missing a value' do
21
+ let(:source) { 'def test; return; end' }
22
+
23
+ specify do
24
+ expect(cop.offenses.size).to eql(1)
25
+ expect(cop.offenses.first.cop_name).to eql('Mirego/ExplicitReturnValue')
26
+ end
27
+ end
28
+
29
+ describe 'with a return missing a value with a conditional' do
30
+ let(:source) { 'def test; return unless bool; end' }
31
+
32
+ specify do
33
+ expect(cop.offenses.size).to eql(1)
34
+ expect(cop.offenses.first.cop_name).to eql('Mirego/ExplicitReturnValue')
35
+ end
36
+ end
37
+
38
+ describe 'with a implicit return' do
39
+ let(:source) { 'def test; test; end' }
40
+
41
+ it { expect(cop.offenses.size).to eql(0) }
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Mirego::ReceiveCounts do
4
+ let(:cop) { RuboCop::Cop::Mirego::ReceiveCounts.new }
5
+
6
+ before { inspect_source(cop, source) }
7
+
8
+ describe 'with a receive having a count' do
9
+ let(:source) { 'expect(object).to receive(:test).once' }
10
+
11
+ it { expect(cop.offenses.size).to eql(0) }
12
+ end
13
+
14
+ describe 'with an allow' do
15
+ let(:source) { 'allow(object).to receive(:test)' }
16
+
17
+ it { expect(cop.offenses.size).to eql(0) }
18
+ end
19
+
20
+ describe 'with a receive missing a count' do
21
+ let(:source) { 'expect(object).to receive(:test)' }
22
+
23
+ specify do
24
+ expect(cop.offenses.size).to eql(1)
25
+ expect(cop.offenses.first.cop_name).to eql('Mirego/ReceiveCounts')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubocop'
2
+
3
+ rubocop_path = Bundler.rubygems.find_name('rubocop').first.full_gem_path
4
+ require "#{rubocop_path}/spec/support/cop_helper"
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'rubocop-mirego'
9
+
10
+ RSpec.configure do |config|
11
+ # Disable `should` syntax
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+
16
+ # Run specs in random order to surface order dependencies
17
+ config.order = 'random'
18
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-mirego
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Jean-François Chaput
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.39.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.39.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.4.1
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.4'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.4.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: phare
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.7'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.7'
89
+ description: Custom cops for Mirego.
90
+ email:
91
+ - jfchaput@mirego.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".rubocop.yml"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - Gemfile.lock
100
+ - README.md
101
+ - config/default.yml
102
+ - lib/rubocop-mirego.rb
103
+ - lib/rubocop/cop/mirego/explicit_return_value.rb
104
+ - lib/rubocop/cop/mirego/receive_counts.rb
105
+ - lib/rubocop/mirego/inject.rb
106
+ - lib/rubocop/mirego/version.rb
107
+ - rubocop-mirego.gemspec
108
+ - spec/rubocop/cop/mirego/explicit_return_value_spec.rb
109
+ - spec/rubocop/cop/mirego/receive_counts_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/mirego/rubocop-mirego
112
+ licenses:
113
+ - BSD 3-Clause
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Custom cops for Mirego.
135
+ test_files:
136
+ - spec/rubocop/cop/mirego/explicit_return_value_spec.rb
137
+ - spec/rubocop/cop/mirego/receive_counts_spec.rb
138
+ - spec/spec_helper.rb