rubocop-brands_insurance 0.0.2.pre.rc.4 → 0.0.2.pre.rc.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0a31e7b878d8cb36894cdd1e93f6aa08defa73245c4cdb250adb9b0331576db
4
- data.tar.gz: 82a85cd60c35ae33e4dabd2722a74fb4c43ced895a791a452d76b870a1423f6c
3
+ metadata.gz: a2c30f388ac393017855ac647ce55cc32500677db42e4a1326a4c7fbe369944f
4
+ data.tar.gz: bb492e4da95e8c54da9371d2a4ed6f9fd0219e754211e0f71d3c8e6eafbbade1
5
5
  SHA512:
6
- metadata.gz: 9aff2fde024a978f66c774a8eec2e288734eebb4beacc3b20753beee77477eb82fddae6ed93867a0809f6202b35e95c757c554e2d18da4cdd4a662f4368b4b12
7
- data.tar.gz: 6dd36698038d0db7526372c20df0026e1e1d1e77e315fddeca384a7d5f8b63672f80a1e459aac42dce73da6c4254b9af56ef69c0a0d973c102461aa8af51edcd
6
+ metadata.gz: 6d33b942f577abed0010d3ed388d0e561a1e7d84b649fdd92063b7aa586af958a1252db56e38ed727ac43f10874b2bd751cd579085f9623d81cf5791d0fc6d5f
7
+ data.tar.gz: 2154fb919f9d708c69736ca616b751fe03e5cc68cb3f416123a02d123d2bbeb39974245c4382e09d3d8e121a6651a5548e955ef1d6e7fabadab62161100fca9b
data/LICENSE.txt CHANGED
@@ -1,5 +1,7 @@
1
1
  Copyright (c) 2012-23 Brands Insurance
2
2
 
3
+ Copyright for portions of project Rubocop are held by Bozhidar Batsov and other contributors, as part of project Rubocop.
4
+
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
5
7
  "Software"), to deal in the Software without restriction, including
data/config/default.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  BrandsInsurance/Style/DisallowedMethods:
2
2
  Description: 'Disallows the usage of `#abort` and `#tap` methods'
3
- Enabled: pending
3
+ Enabled: true
4
4
  VersionAdded: '<<next>>'
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
- # See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
5
3
  module RuboCop
6
4
  module BrandsInsurance
7
- # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
- # bit of our configuration.
9
5
  module Inject
6
+ # This was a generated method from https://github.com/rubocop/rubocop-extension-generator
7
+ #
10
8
  def self.defaults!
11
9
  path = CONFIG_DEFAULT.to_s
12
10
  hash = ConfigLoader.__send__(:load_yaml_configuration, path)
13
11
  config = Config.new(hash, path).tap(&:make_excludes_absolute)
12
+
14
13
  puts("configuration from #{path}") if ConfigLoader.debug?
14
+
15
15
  config = ConfigLoader.merge_with_default(config, path)
16
+
16
17
  ConfigLoader.instance_variable_set(:@default_configuration, config)
17
18
  end
18
19
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module BrandsInsurance
5
- VERSION = '0.0.2-rc.4'
5
+ VERSION = '0.0.2-rc.5'
6
6
  end
7
7
  end
@@ -5,11 +5,12 @@ require 'yaml'
5
5
 
6
6
  module RuboCop
7
7
  module BrandsInsurance
8
- class Error < StandardError; end
9
- # Your code goes here...
10
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
8
+ class Error < StandardError
9
+ end
10
+
11
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
11
12
  CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
12
- CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
13
+ CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
13
14
 
14
15
  private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
15
16
  end
@@ -6,7 +6,7 @@ module RuboCop
6
6
  class Generator
7
7
  class CopReadmeInjector < DeptReadmeInjector
8
8
  TEMPLATE =
9
- '* xref:./%<cop_folder>s/README.adoc[``%<department>s/%<cop>s``]'
9
+ '* xref:./%{cop_folder}/README.adoc[``%{department}/%{cop}``]'
10
10
 
11
11
  # :nodoc:
12
12
  def initialize(badge:, **kwargs)
@@ -17,8 +17,10 @@ module RuboCop
17
17
 
18
18
  private
19
19
 
20
+ # @return [String]
20
21
  attr_reader :cop
21
22
 
23
+ # @see super
22
24
  def new_readme_entry
23
25
  format(TEMPLATE, {
24
26
  department_folder: snake_case(department),
@@ -28,6 +30,7 @@ module RuboCop
28
30
  })
29
31
  end
30
32
 
33
+ # @see super
31
34
  def line_is_good?(line)
32
35
  return true if super
33
36
 
@@ -37,6 +40,7 @@ module RuboCop
37
40
  department == matches[:department] && cop < matches[:cop]
38
41
  end
39
42
 
43
+ # @see super
40
44
  def target_regex
41
45
  %r{\* xref:\./docs/cops/[a-z_]+/[a-z_]+/README\.adoc\[``(?<department>[a-zA-Z_]+)/(?<cop>[a-zA-Z_]+)``\]}
42
46
  end
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module BrandsInsurance
6
6
  class Generator
7
7
  class DeptReadmeInjector
8
- TEMPLATE = '* xref:./docs/cops/%<department_folder>s/README.adoc[``%<department>s``]'
8
+ TEMPLATE = '* xref:./docs/cops/%{department_folder}/README.adoc[``%{department}``]'
9
9
 
10
10
  # :nodoc:
11
11
  def initialize(readme_file_path:, badge:, department:)
@@ -15,13 +15,19 @@ module RuboCop
15
15
  @output = output
16
16
  end
17
17
 
18
- # :nodoc:
19
- def inject
18
+ # Performs the actual string injection into the file
19
+ # modified version of `inject` from RuboCop::Cop::Generator::ConfigurationInjector
20
+ # Named `inject_string` becuase rubocop thought when called it was `Array#inject`
21
+ #
22
+ # @return [void]
23
+ #
24
+ def inject_string
20
25
  target_line = find_target_line
26
+
21
27
  if target_line
22
28
  readme_entries.insert(target_line, "#{new_readme_entry}\n")
23
29
  else
24
- readme_entries.push("#{new_readme_entry}")
30
+ readme_entries.push(new_readme_entry)
25
31
  end
26
32
 
27
33
  File.write(readme_file_path, readme_entries.join(''))
@@ -31,12 +37,27 @@ module RuboCop
31
37
 
32
38
  private
33
39
 
34
- attr_reader :readme_file_path, :badge, :department, :output
40
+ # @return [String]
41
+ attr_reader :readme_file_path
42
+ # @return [RuboCop::Cop::Badge]
43
+ attr_reader :badge
44
+ # @return [String]
45
+ attr_reader :department
46
+ # @return [*] Default $stdout
47
+ attr_reader :output
35
48
 
49
+ # Lines in <department>/README.adoc
50
+ #
51
+ # @return [Array<String>]
52
+ #
36
53
  def readme_entries
37
54
  @readme_entries ||= File.readlines(readme_file_path)
38
55
  end
39
56
 
57
+ # Modified version from Rubocop::Cop::Generator::ConfigurationInjector
58
+ #
59
+ # @return [String]
60
+ #
40
61
  def new_readme_entry
41
62
  format(TEMPLATE, {
42
63
  department_folder: snake_case(department),
@@ -44,6 +65,10 @@ module RuboCop
44
65
  })
45
66
  end
46
67
 
68
+ # Modified version from Rubocop::Cop::Generator::ConfigurationInjector
69
+ #
70
+ # @return [Integer, Nil]
71
+ #
47
72
  def find_target_line
48
73
  readme_entries.find.with_index do |line, index|
49
74
  return index if line_is_good?(line)
@@ -52,6 +77,10 @@ module RuboCop
52
77
  return nil
53
78
  end
54
79
 
80
+ # Determines if the given line is the same type we're trying to add and if it's alphabetically before
81
+ #
82
+ # @return [Boolean]
83
+ #
55
84
  def line_is_good?(line)
56
85
  matches = line.match(target_regex)
57
86
  return false if matches.nil?
@@ -59,10 +88,18 @@ module RuboCop
59
88
  department < line.match(target_regex)[:department]
60
89
  end
61
90
 
91
+ # Regex to look for in the readme
92
+ #
93
+ # @return [Regexp]
94
+ #
62
95
  def target_regex
63
96
  %r{\* xref:\./docs/cops/[a-z_]+/README\.adoc\[``(?<department>[a-zA-Z_]+)``\]}
64
97
  end
65
98
 
99
+ # Copied from Rubocop::Cop::Generator
100
+ #
101
+ # @return [String]
102
+ #
66
103
  def snake_case(camel_case_string)
67
104
  camel_case_string
68
105
  .gsub('RSpec', 'Rspec')
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative './generator/dept_readme_injector'
4
+
4
5
  require_relative './generator/cop_readme_injector'
5
6
 
6
7
  module RuboCop
@@ -53,8 +54,8 @@ module RuboCop
53
54
 
54
55
  module RuboCop
55
56
  module Cop
56
- module %<department>s
57
- class %<cop_name>s < Base
57
+ module %{department}
58
+ class %{cop_name} < Base
58
59
  # TODO: Implement the cop in here.
59
60
  #
60
61
  # In many cases, you can use a node matcher for matching node pattern.
@@ -82,12 +83,10 @@ module RuboCop
82
83
  end
83
84
  end
84
85
  RUBY
85
- README_ADDED_MESSAGE =
86
- '[modify] A link for the %<dept_vs_cop>s has been added into ' \
87
- '%<readme_file_path>s.'
86
+ README_ADDED_MESSAGE = '[modify] A link for the %{dept_vs_cop} has been added into %{readme_file_path}.'
88
87
 
89
88
  DEPT_README_TEMPLATE = <<~ADOC
90
- = %<department>s
89
+ = %{department}
91
90
 
92
91
  Describe the department here
93
92
 
@@ -95,7 +94,7 @@ module RuboCop
95
94
 
96
95
  ADOC
97
96
  COP_README_TEMPLATE = <<~ADOC
98
- = ``%<department>s/%<cop_name>s``
97
+ = ``%{department}/%{cop_name}``
99
98
 
100
99
  == Description
101
100
 
@@ -128,6 +127,7 @@ module RuboCop
128
127
  https://github.com/BrandsInsurance/expert-chainsaw/issues
129
128
  ADOC
130
129
 
130
+ # :nodoc:
131
131
  def initialize(name, output: $stdout)
132
132
  name = ['BrandsInsurance', name].join('/') unless name.start_with?('BrandsInsurance/')
133
133
 
@@ -157,16 +157,31 @@ module RuboCop
157
157
  @base_gen.respond_to?(method_name, include_private)
158
158
  end
159
159
 
160
+ # Creates the department readme if it doesn't exist
161
+ # Modified version of `wirte_source` from RuboCop::Cop::Generator
162
+ #
163
+ # @return [void]
164
+ #
160
165
  def write_dept_readme
161
- return if File.exists?(dept_docs_path)
166
+ return if File.exist?(dept_docs_path)
162
167
 
163
168
  write_unless_file_exists(dept_docs_path, generated_dept_docs)
164
169
  end
165
170
 
171
+ # Creates the cop readme if it doesn't exist
172
+ # Modified version of `wirte_source` from RuboCop::Cop::Generator
173
+ #
174
+ # @return [void]
175
+ #
166
176
  def write_cop_readme
167
177
  write_unless_file_exists(docs_path, generated_cop_docs)
168
178
  end
169
179
 
180
+ # Injects the, possibly new, department readme link into the base readme
181
+ # Modified version of `inject_config` from RuboCop::Cop::Generator
182
+ #
183
+ # @return [void]
184
+ #
170
185
  def inject_dept_readme(readme_file_path: 'README.adoc')
171
186
  # Add this dept to base readme if not already there
172
187
  injector = DeptReadmeInjector.new(
@@ -175,11 +190,16 @@ module RuboCop
175
190
  department: department
176
191
  )
177
192
 
178
- injector.inject do
193
+ injector.inject_string do
179
194
  output.puts(format(README_ADDED_MESSAGE, readme_file_path: readme_file_path, dept_vs_cop: 'department'))
180
195
  end
181
196
  end
182
197
 
198
+ # Injects the new cop readme link into the department readme
199
+ # Modified version of `inject_config` from RuboCop::Cop::Generator
200
+ #
201
+ # @return [void]
202
+ #
183
203
  def inject_cop_readme(readme_file_path: dept_docs_path)
184
204
  # Add this cop to the dept readme
185
205
  injector = CopReadmeInjector.new(
@@ -188,25 +208,41 @@ module RuboCop
188
208
  department: department
189
209
  )
190
210
 
191
- injector.inject do
211
+ injector.inject_string do
192
212
  output.puts(format(README_ADDED_MESSAGE, readme_file_path: readme_file_path, dept_vs_cop: 'cop'))
193
213
  end
194
214
  end
195
215
 
196
216
  private
197
217
 
218
+ # The rubocop department without the Brands prefix
219
+ #
220
+ # @return [String]
221
+ #
198
222
  def department
199
223
  badge.department_name.gsub('BrandsInsurance/', '')
200
224
  end
201
225
 
226
+ # Modified version of `generated_source` from Rubocop::Cop::Generator
227
+ #
228
+ # @return [String]
229
+ #
202
230
  def generated_dept_docs
203
231
  generate_readme(DEPT_README_TEMPLATE)
204
232
  end
205
233
 
234
+ # Modified version of `generated_source` from Rubocop::Cop::Generator
235
+ #
236
+ # @return [String]
237
+ #
206
238
  def generated_cop_docs
207
239
  generate_readme(COP_README_TEMPLATE)
208
240
  end
209
241
 
242
+ # Modified version from Rubocop::Cop::Generator
243
+ #
244
+ # @return [String]
245
+ #
210
246
  def generate_readme(template)
211
247
  format(template, {
212
248
  department: department,
@@ -215,6 +251,10 @@ module RuboCop
215
251
  })
216
252
  end
217
253
 
254
+ # Path to <department>/README.adoc
255
+ #
256
+ # @return [String]
257
+ #
218
258
  def dept_docs_path
219
259
  File.join(
220
260
  'docs',
@@ -224,12 +264,16 @@ module RuboCop
224
264
  )
225
265
  end
226
266
 
267
+ # Path to <department>/<cop>/README.adoc
268
+ #
269
+ # @return [String]
270
+ #
227
271
  def docs_path
228
272
  File.join(
229
273
  'docs',
230
274
  'cops',
231
275
  snake_case(department),
232
- "#{snake_case(badge.cop_name.to_s)}",
276
+ snake_case(badge.cop_name.to_s),
233
277
  'README.adoc'
234
278
  )
235
279
  end
@@ -4,28 +4,6 @@ module RuboCop
4
4
  module Cop
5
5
  module BrandsInsurance
6
6
  module Style
7
- # @example EnforcedStyle: foo
8
- # # Description of the `foo` style.
9
- #
10
- # # bad
11
- # abort
12
- #
13
- # # bad
14
- # abort(args)
15
- #
16
- # # bad
17
- # tap {}
18
- #
19
- # # bad
20
- # tap do
21
- # end
22
- #
23
- # # good
24
- # raise
25
- #
26
- # # good
27
- # raise(args)
28
- #
29
7
  class DisallowedMethods < RuboCop::Cop::Base
30
8
  # In many cases, you can use a node matcher for matching node pattern.
31
9
  # See https://github.com/rubocop/rubocop-ast/blob/master/lib/rubocop/ast/node_pattern.rb
@@ -34,7 +12,7 @@ module RuboCop
34
12
  MESSAGES = {
35
13
  abort: 'Use `#raise` instead of `#abort`.',
36
14
  tap: 'Do not use `#tap`'
37
- }
15
+ }.freeze
38
16
 
39
17
  # `on_send` will only be called if the method name is in this list
40
18
  RESTRICT_ON_SEND = %i[abort tap].freeze
@@ -49,7 +27,10 @@ module RuboCop
49
27
  (send nil? :tap ...)
50
28
  PATTERN
51
29
 
52
- # :nodoc:
30
+ # The main logic method of the cop
31
+ #
32
+ # @return [void]
33
+ #
53
34
  def on_send(node)
54
35
  message =
55
36
  if using_abort?(node)
@@ -3,9 +3,9 @@
3
3
  require 'rubocop'
4
4
 
5
5
  require_relative 'rubocop/brands_insurance'
6
- require_relative 'rubocop/cop/brands_insurance/generator'
7
6
  require_relative 'rubocop/brands_insurance/inject'
8
7
  require_relative 'rubocop/brands_insurance/version'
8
+ require_relative 'rubocop/cop/brands_insurance/generator'
9
9
 
10
10
  RuboCop::BrandsInsurance::Inject.defaults!
11
11
 
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: 0.0.2.pre.rc.4
4
+ version: 0.0.2.pre.rc.5
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-03-01 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop