rubocop-airbnb 1.0.0 → 1.3.0

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.
@@ -3,6 +3,6 @@
3
3
  module RuboCop
4
4
  module Airbnb
5
5
  # Version information for the the Airbnb RuboCop plugin.
6
- VERSION = '1.0.0'.freeze
6
+ VERSION = '1.3.0'.freeze
7
7
  end
8
8
  end
@@ -0,0 +1,19 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Airbnb
4
+ # Cop to tackle prevent unless statements with multiple conditions
5
+ # https://github.com/airbnb/ruby#unless-with-multiple-conditions
6
+ class SimpleUnless < Cop
7
+ MSG = 'Unless usage is okay when there is only one conditional'.freeze
8
+
9
+ def_node_matcher :multiple_conditionals?, '(if ({and or :^} ...) ...)'
10
+
11
+ def on_if(node)
12
+ return unless node.unless?
13
+
14
+ add_offense(node) if multiple_conditionals?(node)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  'Gemfile',
27
27
  ]
28
28
 
29
- spec.add_dependency('rubocop', '0.52.1')
29
+ spec.add_dependency('rubocop', '0.54.0')
30
30
  spec.add_dependency('rubocop-rspec', '1.22.1')
31
31
  spec.add_development_dependency('rspec', '~> 3.5')
32
32
  end
@@ -0,0 +1,36 @@
1
+ describe RuboCop::Cop::Airbnb::SimpleUnless do
2
+ subject(:cop) { described_class.new }
3
+
4
+ it 'rejects unless with multiple conditionals' do
5
+ source = [
6
+ 'unless boolean_condition || another_method',
7
+ ' return true',
8
+ 'end',
9
+ ].join("\n")
10
+
11
+ inspect_source(source)
12
+ expect(cop.offenses.size).to eq(1)
13
+ end
14
+
15
+ it 'allows if with multiple conditionals' do
16
+ source = [
17
+ 'if boolean_condition || another_method',
18
+ ' return true',
19
+ 'end',
20
+ ].join("\n")
21
+
22
+ inspect_source(source)
23
+ expect(cop.offenses).to be_empty
24
+ end
25
+
26
+ it 'allows with modifier if operator conditional' do
27
+ source = [
28
+ 'unless boolean_condition',
29
+ ' return true',
30
+ 'end',
31
+ ].join("\n")
32
+
33
+ inspect_source(source)
34
+ expect(cop.offenses).to be_empty
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-airbnb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbnb Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.52.1
19
+ version: 0.54.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.52.1
26
+ version: 0.54.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +101,7 @@ files:
101
101
  - lib/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace.rb
102
102
  - lib/rubocop/cop/airbnb/rspec_environment_modification.rb
103
103
  - lib/rubocop/cop/airbnb/simple_modifier_conditional.rb
104
+ - lib/rubocop/cop/airbnb/simple_unless.rb
104
105
  - lib/rubocop/cop/airbnb/spec_constant_assignment.rb
105
106
  - lib/rubocop/cop/airbnb/unsafe_yaml_marshal.rb
106
107
  - rubocop-airbnb.gemspec
@@ -120,6 +121,7 @@ files:
120
121
  - spec/rubocop/cop/airbnb/rspec_describe_or_context_under_namespace_spec.rb
121
122
  - spec/rubocop/cop/airbnb/rspec_environment_modification_spec.rb
122
123
  - spec/rubocop/cop/airbnb/simple_modifier_conditional_spec.rb
124
+ - spec/rubocop/cop/airbnb/simple_unless_spec.rb
123
125
  - spec/rubocop/cop/airbnb/spec_constant_assignment_spec.rb
124
126
  - spec/rubocop/cop/airbnb/unsafe_yaml_marshal_spec.rb
125
127
  - spec/spec_helper.rb
@@ -143,8 +145,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
145
  version: '0'
144
146
  requirements: []
145
147
  rubyforge_project:
146
- rubygems_version: 2.4.5.1
148
+ rubygems_version: 2.2.5
147
149
  signing_key:
148
150
  specification_version: 4
149
151
  summary: Custom code style checking for Airbnb.
150
152
  test_files: []
153
+ has_rdoc: