rubocop-brands_insurance 1.3.0.pre.rc.2 → 1.4.0.pre.rc.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
  SHA256:
3
- metadata.gz: 73d970e26f5615762329168e39d4e03ca54f6249565919ff2922110380d3cee5
4
- data.tar.gz: 6782129fbbede885e3438fa2b38d9888c0cba31dd32c0e0a82389529e862ff7c
3
+ metadata.gz: f71b8941f86c6189771d5c9bfcc81f4744e9fb821d45d5ba3c93c5a0fd195320
4
+ data.tar.gz: 8032dc595911c74d1d4296d0123918c98e60cb273fd4aa0d1654602526363936
5
5
  SHA512:
6
- metadata.gz: f52e5fcd8e1ad529fb5d6f269c4404f6d063e71740a39109da17611d01722c54f47154c6253d62d378a084d88c90846e10eef835b398cb20f85d60b7d9fad29f
7
- data.tar.gz: daa29de6ad55a7d75d2f2c3e2fbbf5e06ca983fbcae25ee944e54f6e0a39b72bf148527255cc70079e600f7127277f8a70f5935c44a536d868cf090de362b715
6
+ metadata.gz: f9a13ac68f7eead1d4186767b1fef7c6e8eaae15beb823a1344acb33bc7a969ef4bf3c8b05665e3fc3291b32f749293237539163d7f8eafc13e4a78f346faed7
7
+ data.tar.gz: 58be8bafe667d21c2b9be721a6102fe9fabe16ec8b03633d430385366bb37b4b1dabbb73c552d1f5197affe9f5cbc637b3aefa4a30739f27f640d7431ec898a8
data/README.adoc CHANGED
@@ -35,6 +35,7 @@ BrandsInsurance/Style/DisallowedMethods:
35
35
 
36
36
  == Departments
37
37
 
38
+ * xref:./docs/cops/layout/README.adoc[``Layout``]
38
39
  * xref:./docs/cops/style/README.adoc[``Style``]
39
40
 
40
41
  == Contributing
data/config/default.yml CHANGED
@@ -1,3 +1,10 @@
1
+ BrandsInsurance/Layout/MultilineArrayLineBreaks:
2
+ Description: 'Fork of base Layout/MultilineArrayLineBreaks rule'
3
+ Enabled: true
4
+ VersionAdded: '1.3.0'
5
+ AllowMultilineFinalElement: true
6
+ AllowPercentArray: true
7
+
1
8
  BrandsInsurance/Style/DisallowedMethods:
2
9
  Description: 'Disallows the usage of `#abort` and `#tap` methods'
3
10
  Enabled: true
@@ -0,0 +1,7 @@
1
+ = Layout
2
+
3
+ Layout cops check for stylistic whitespace in your code
4
+
5
+ == Cops
6
+
7
+ * xref:./multiline_array_line_breaks/README.adoc[``Layout/MultilineArrayLineBreaks``]
@@ -0,0 +1,44 @@
1
+ = ``Layout/MultilineArrayLineBreaks``
2
+
3
+ == Description
4
+
5
+ Extends the built-in link:https://docs.rubocop.org/rubocop/1.49/cops_layout.html#layoutmultilinearraylinebreaks[``Layout/MultilineArrayLineBreaks``]
6
+ and adds the ``AllowPercentArray`` option
7
+
8
+ == Examples
9
+
10
+ [source,ruby]
11
+ ----
12
+ # bad
13
+ %w[
14
+ 1
15
+ 2
16
+ 3
17
+ 4
18
+ ]
19
+
20
+ # good
21
+ %w[
22
+ 1 2
23
+ 3 4
24
+ ]
25
+ ----
26
+
27
+ == Configurable Attributes
28
+
29
+ |===
30
+ |Name |Default value |Configurable values
31
+
32
+ |AllowMultilineFinalElement
33
+ |false
34
+ |Boolean
35
+
36
+ |AllowPercentArray
37
+ |false
38
+ |Boolean
39
+
40
+ |===
41
+
42
+ == References
43
+
44
+ https://github.com/BrandsInsurance/expert-chainsaw/issues/1032
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module BrandsInsurance
5
- VERSION = '1.3.0-rc.2'
5
+ VERSION = '1.4.0-rc.1'
6
6
  end
7
7
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module BrandsInsurance
6
+ module Layout
7
+ class MultilineArrayLineBreaks < Base
8
+ include RuboCop::Cop::MultilineElementLineBreaks
9
+ # extend RuboCop::Cop::AutoCorrector
10
+
11
+ # `RuboCop::Cop::AutoCorrector` must be extended but it only has this method returning `true`
12
+ #
13
+ # @return [Boolean]
14
+ #
15
+ def support_autocorrect?
16
+ false
17
+ end
18
+
19
+ MESSAGE = 'Each item in a multi-line array must start on a separate line.'
20
+ # MSG is needed for `check_line_breaks`
21
+ MSG = MESSAGE
22
+
23
+ def on_array(node)
24
+ return if allowed_percent_array?(node)
25
+
26
+ check_line_breaks(node, node.children, ignore_last: ignore_last_element?)
27
+ end
28
+
29
+ private
30
+
31
+ # Check conig option
32
+ #
33
+ # @return [Boolean]
34
+ #
35
+ def ignore_last_element?
36
+ cop_config.fetch('AllowMultilineFinalElement', false)
37
+ end
38
+
39
+ # Check conig option
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def allowed_percent_array?(node)
44
+ cop_config.fetch('AllowPercentArray', false) && node.percent_literal?
45
+ end
46
+
47
+ # Copied from rubocop's source
48
+ def check_line_breaks(_node, children, ignore_last: false)
49
+ return if all_on_same_line?(children, ignore_last: ignore_last)
50
+
51
+ last_seen_line = -1
52
+ children.each do |child|
53
+ if last_seen_line >= child.first_line
54
+ add_offense(child, message: MESSAGE)
55
+ else
56
+ last_seen_line = child.last_line
57
+ end
58
+ end
59
+ end
60
+
61
+ # Copied from rubocop's source
62
+ def all_on_same_line?(nodes, ignore_last: false)
63
+ return true if nodes.empty?
64
+
65
+ return same_line?(nodes.first, nodes.last) if ignore_last
66
+
67
+ nodes.first.first_line == nodes.last.last_line
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'brands_insurance/style/disallowed_methods'
4
+ require_relative 'brands_insurance/layout/multiline_array_line_breaks'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-brands_insurance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre.rc.2
4
+ version: 1.4.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-03 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -35,6 +35,8 @@ files:
35
35
  - LICENSE.txt
36
36
  - README.adoc
37
37
  - config/default.yml
38
+ - docs/cops/layout/README.adoc
39
+ - docs/cops/layout/multiline_array_line_breaks/README.adoc
38
40
  - docs/cops/style/README.adoc
39
41
  - docs/cops/style/disallowed_methods/README.adoc
40
42
  - lib/rubocop-brands_insurance.rb
@@ -44,6 +46,7 @@ files:
44
46
  - lib/rubocop/cop/brands_insurance/generator.rb
45
47
  - lib/rubocop/cop/brands_insurance/generator/cop_readme_injector.rb
46
48
  - lib/rubocop/cop/brands_insurance/generator/dept_readme_injector.rb
49
+ - lib/rubocop/cop/brands_insurance/layout/multiline_array_line_breaks.rb
47
50
  - lib/rubocop/cop/brands_insurance/style/disallowed_methods.rb
48
51
  - lib/rubocop/cop/brands_insurance_cops.rb
49
52
  homepage: https://github.com/BrandsInsurance/expert-chainsaw/