rubocop-faker 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e905846c9989294b1dfd34c9ebf8224d319476103bed10f3aa939c2b242739b3
4
- data.tar.gz: 0d4e63a90bf719a39380830d716097f90acefeb63149bf2f3f870ad0aa82d45a
3
+ metadata.gz: 9411434bc51ae4bd5aeb3ec021d79472ac55c39d8fd96785d46094ada5380049
4
+ data.tar.gz: a53752635232f959e334ed106edbb0c4b7dcb3f76cc0958c39b2380971fb9388
5
5
  SHA512:
6
- metadata.gz: ed10d5471a325618fb0c8f5ce32e5c193a5e683b12e673f7bbb19e3c47870c34e79d6a1aa6748a5568963a4d94d1be063379fbba6036115a1707f0fcb404d4f4
7
- data.tar.gz: bdcbc64672f446a338a7848cf400618646fdcfcf573c786255feb6afbab999b8af38962b62c278e313668ffc65d3669194f285cd772f0fb8844e47c3c2f516b7
6
+ metadata.gz: e7c01bad74e1fb97f64e254d39858289ec5ba710460662d6e06e7e5baac4ff569c9a382ee24c426031489b3a291267c5b7229165f3483c342da274aacf282d02
7
+ data.tar.gz: 55ab7dad2875123dcdd9d5cd7b6257fc69b3ac11d1739ca91453ec53f7693d66a9a404d896394f15fb308f7c20f91241205e1025c883563a2dff8a61bf2dfa83
data/.circleci/config.yml CHANGED
@@ -24,20 +24,20 @@ workflows:
24
24
  build:
25
25
  jobs:
26
26
  - rake_default:
27
- name: Ruby 2.4
28
- image: circleci/ruby:2.4
27
+ name: Ruby 2.7
28
+ image: cimg/ruby:2.7
29
29
  - rake_default:
30
- name: Ruby 2.5
31
- image: circleci/ruby:2.5
30
+ name: Ruby 3.0
31
+ image: cimg/ruby:3.0
32
32
  - rake_default:
33
- name: Ruby 2.6
34
- image: circleci/ruby:2.6
33
+ name: Ruby 3.1
34
+ image: cimg/ruby:3.1
35
35
  - rake_default:
36
- name: Ruby 2.7
37
- image: circleci/ruby:2.7
36
+ name: Ruby 3.2
37
+ image: cimg/ruby:3.2
38
+ - rake_default:
39
+ name: Ruby 3.3
40
+ image: cimg/ruby:3.3
38
41
  - rake_default:
39
42
  name: Ruby HEAD
40
43
  image: rubocophq/circleci-ruby-snapshot:latest # Nightly snapshot build
41
- - rake_default:
42
- name: JRuby 9.2
43
- image: circleci/jruby:9.2
@@ -0,0 +1 @@
1
+ github: koic
data/.rubocop.yml CHANGED
@@ -2,13 +2,14 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  # This is the configuration used to check the rubocop source code.
4
4
 
5
- require:
6
- - rubocop/cop/internal_affairs
5
+ plugins:
6
+ - rubocop-internal_affairs
7
7
  - rubocop-performance
8
8
 
9
9
  AllCops:
10
10
  NewCops: enable
11
- TargetRubyVersion: 2.4
11
+ TargetRubyVersion: 2.7
12
+ SuggestExtensions: false
12
13
 
13
14
  Naming/PredicateName:
14
15
  # Method define macros for dynamically generated method.
@@ -83,3 +84,6 @@ Metrics/ModuleLength:
83
84
 
84
85
  Performance/ChainArrayAllocation:
85
86
  Enabled: false
87
+
88
+ InternalAffairs/UndefinedConfig:
89
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.3.0 (2025-02-18)
6
+
7
+ ### New features
8
+
9
+ * Pluginfy RuboCop Faker. ([@koic][])
10
+ * Support safe navigation operator for `Faker/DeprecatedArguments`. ([@koic][])
11
+
12
+ ## 1.2.0 (2024-10-22)
13
+
14
+ ### Bug fixes
15
+
16
+ * [#7](https://github.com/koic/rubocop-faker/issues/7): Suppress RuboCop's deprecation warning. ([@koic][])
17
+
18
+ ### Changes
19
+
20
+ * Drop support for Ruby 2.6 and lower. ([@koic][])
21
+
5
22
  ## 1.1.0 (2020-06-11)
6
23
 
7
24
  ### Bug fixes
data/Gemfile CHANGED
@@ -8,8 +8,8 @@ gemspec
8
8
 
9
9
  gem 'rake'
10
10
  gem 'rspec'
11
- gem 'rubocop', github: 'rubocop-hq/rubocop'
12
- gem 'rubocop-performance', '~> 1.5.0'
11
+ gem 'rubocop', github: 'rubocop/rubocop'
12
+ gem 'rubocop-performance', '~> 1.24.0'
13
13
  # Workaround for YARD 0.9.20 or lower.
14
14
  # It specifies `github` until the release that includes the following changes:
15
15
  # https://github.com/lsegal/yard/pull/1290
data/README.md CHANGED
@@ -48,15 +48,28 @@ This gem offers the only `Faker/DeprecatedArguments` cop. It is intended to conv
48
48
  Check positional argument style before Faker 2.
49
49
 
50
50
  ```console
51
- % rubocop --require rubocop-faker --only Faker/DeprecatedArguments
51
+ % rubocop --plugin rubocop-faker --only Faker/DeprecatedArguments
52
52
  ```
53
53
 
54
54
  Auto-correction to keyword argument style on Faker 2.
55
55
 
56
56
  ```console
57
- % rubocop --require rubocop-faker --only Faker/DeprecatedArguments --auto-correct
57
+ % rubocop --plugin rubocop-faker --only Faker/DeprecatedArguments --autocorrect
58
58
  ```
59
59
 
60
+ ### RuboCop configuration file
61
+
62
+ Add `rubocop-faker` to required extension.
63
+
64
+ ```yaml
65
+ # .rubocop.yml
66
+ plugins:
67
+ - rubocop-faker
68
+ ```
69
+
70
+ > [!NOTE]
71
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
72
+
60
73
  ## Contributing
61
74
 
62
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/koic/rubocop-faker.
@@ -3,7 +3,6 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Faker
6
- #
7
6
  # Checks that Faker arguments style is based on Faker 2.
8
7
  # Use keyword arguments instead of positional arguments.
9
8
  #
@@ -14,8 +13,9 @@ module RuboCop
14
13
  # # good
15
14
  # Avatar.image(slug: slug, size: size, format: format)
16
15
  #
17
- class DeprecatedArguments < Cop
16
+ class DeprecatedArguments < Base
18
17
  include RangeHelp
18
+ extend AutoCorrector
19
19
 
20
20
  MSG = 'Passing `%<arg>s` with the %<index>s argument of ' \
21
21
  '`%<class_name>s.%<method_name>s` is deprecated. ' \
@@ -45,22 +45,12 @@ module RuboCop
45
45
  add_offense_for_arguments(node, argument, message)
46
46
  end
47
47
  end
48
-
49
- def autocorrect(node)
50
- methods = argument_keywords[faker_class_name(node)]
51
- keywords = methods[node.method_name.to_s]
52
-
53
- kwargs = build_kwargs_style(node, keywords)
54
-
55
- lambda do |corrector|
56
- corrector.replace(arguments_range(node), kwargs)
57
- end
58
- end
48
+ alias on_csend on_send
59
49
 
60
50
  private
61
51
 
62
52
  def unique_generator_method?(node)
63
- node.method?(:unique) && node.arguments.size.zero?
53
+ node.method?(:unique) && node.arguments.empty?
64
54
  end
65
55
 
66
56
  def format_message(keyword:, arg:, index:, class_name:, method_name:)
@@ -82,10 +72,20 @@ module RuboCop
82
72
 
83
73
  def add_offense_for_arguments(node, argument, message)
84
74
  add_offense(
85
- node,
86
- location: argument.source_range,
75
+ argument,
87
76
  message: message
88
- )
77
+ ) do |corrector|
78
+ autocorrect(corrector, node)
79
+ end
80
+ end
81
+
82
+ def autocorrect(corrector, node)
83
+ methods = argument_keywords[faker_class_name(node)]
84
+ keywords = methods[node.method_name.to_s]
85
+
86
+ kwargs = build_kwargs_style(node, keywords)
87
+
88
+ corrector.replace(arguments_range(node), kwargs)
89
89
  end
90
90
 
91
91
  def build_kwargs_style(node, keywords)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module Faker
7
+ # A plugin that integrates RuboCop Faker with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: 'rubocop-faker',
12
+ version: VERSION,
13
+ homepage: 'https://github.com/koic/rubocop-faker',
14
+ description: 'A RuboCop extension for Faker.'
15
+ )
16
+ end
17
+
18
+ def supported?(context)
19
+ context.engine == :rubocop
20
+ end
21
+
22
+ def rules(_context)
23
+ LintRoller::Rules.new(
24
+ type: :path,
25
+ config_format: :rubocop,
26
+ value: Pathname.new(__dir__).join('../../../config/default.yml')
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Faker
5
- VERSION = '1.1.0'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
data/lib/rubocop/faker.rb CHANGED
@@ -1,12 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
- # RuboCop Faker project namespace
4
+ # RuboCop Faker project namespace.
5
5
  module Faker
6
- PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
7
- CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8
- CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
9
-
10
- private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
11
6
  end
12
7
  end
data/lib/rubocop-faker.rb CHANGED
@@ -4,8 +4,5 @@ require 'rubocop'
4
4
 
5
5
  require_relative 'rubocop/faker'
6
6
  require_relative 'rubocop/faker/version'
7
- require_relative 'rubocop/faker/inject'
8
-
9
- RuboCop::Faker::Inject.defaults!
10
-
7
+ require_relative 'rubocop/faker/plugin'
11
8
  require_relative 'rubocop/cop/faker_cops'
@@ -12,9 +12,13 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'A RuboCop extension for Faker.'
13
13
  spec.homepage = 'https://github.com/koic/rubocop-faker'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
16
16
 
17
- spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata = {
18
+ 'homepage_uri' => spec.homepage,
19
+ 'rubygems_mfa_required' => 'true',
20
+ 'default_lint_roller_plugin' => 'RuboCop::Faker::Plugin'
21
+ }
18
22
 
19
23
  # Specify which files should be added to the gem when it is released.
20
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -25,6 +29,7 @@ Gem::Specification.new do |spec|
25
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
30
  spec.require_paths = ['lib']
27
31
 
28
- spec.add_runtime_dependency 'faker', '>= 2.12.0'
29
- spec.add_runtime_dependency 'rubocop', '>= 0.82.0'
32
+ spec.add_dependency 'faker', '>= 2.12.0'
33
+ spec.add_dependency 'lint_roller', '~> 1.1'
34
+ spec.add_dependency 'rubocop', '>= 1.72.1'
30
35
  end
@@ -40,7 +40,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
40
40
  ]
41
41
  config = config.for_cop(cop)
42
42
  safe_auto_correct = config.fetch('SafeAutoCorrect', true)
43
- autocorrect = if cop.new.support_autocorrect?
43
+ autocorrect = if cop.support_autocorrect?
44
44
  "Yes #{'(Unsafe)' unless safe_auto_correct}"
45
45
  else
46
46
  'No'
@@ -52,7 +52,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
52
52
  config.fetch('VersionAdded', '-'),
53
53
  config.fetch('VersionChanged', '-')
54
54
  ]]
55
- to_table(header, content) + "\n"
55
+ "#{to_table(header, content)}\n"
56
56
  end
57
57
  # rubocop:enable Metrics/MethodLength
58
58
 
@@ -131,7 +131,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
131
131
  Array.new(header.size, '---').join(' | ')
132
132
  ]
133
133
  table.concat(content.map { |c| c.join(' | ') })
134
- table.join("\n") + "\n"
134
+ "#{table.join("\n")}\n"
135
135
  end
136
136
 
137
137
  def format_table_value(val)
@@ -175,7 +175,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
175
175
  file_name = "#{Dir.pwd}/manual/cops_#{department.downcase}.md"
176
176
  File.open(file_name, 'w') do |file|
177
177
  puts "* generated #{file_name}"
178
- file.write(content.strip + "\n")
178
+ file.write("#{content.strip}\n")
179
179
  end
180
180
  end
181
181
 
@@ -203,7 +203,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
203
203
  end
204
204
  return if selected_cops.empty?
205
205
 
206
- type_title = department[0].upcase + department[1..-1]
206
+ type_title = department[0].upcase + department[1..]
207
207
  filename = "cops_#{department.downcase}.md"
208
208
  content = +"#### Department [#{type_title}](#{filename})\n\n"
209
209
  selected_cops.each do |cop|
@@ -223,13 +223,11 @@ task generate_cops_documentation: :yard_for_generate_documentation do
223
223
 
224
224
  content << "\n<!-- END_COP_LIST -->"
225
225
 
226
- content = if original.empty?
227
- content
228
- else
229
- original.sub(
230
- /<!-- START_COP_LIST -->.+<!-- END_COP_LIST -->/m, content
231
- )
232
- end
226
+ unless original.empty?
227
+ content = original.sub(
228
+ /<!-- START_COP_LIST -->.+<!-- END_COP_LIST -->/m, content
229
+ )
230
+ end
233
231
  File.write(path, content)
234
232
  end
235
233
 
@@ -238,8 +236,7 @@ task generate_cops_documentation: :yard_for_generate_documentation do
238
236
  .departments
239
237
  .map(&:to_s)
240
238
  .sort
241
- .map { |department| table_of_content_for_department(cops, department) }
242
- .reject(&:nil?)
239
+ .filter_map { |department| table_of_content_for_department(cops, department) }
243
240
  .join("\n")
244
241
  end
245
242
 
@@ -252,13 +249,13 @@ task generate_cops_documentation: :yard_for_generate_documentation do
252
249
  sh('GIT_PAGER=cat git diff manual')
253
250
 
254
251
  warn 'The manual directory is out of sync. ' \
255
- 'Run `rake generate_cops_documentation` and commit the results.'
252
+ 'Run `rake generate_cops_documentation` and commit the results.'
256
253
  exit!
257
254
  end
258
255
  end
259
256
 
260
257
  def main
261
- cops = RuboCop::Cop::Cop.registry
258
+ cops = RuboCop::Cop::Registry.global
262
259
  config = RuboCop::ConfigLoader.load_file('config/default.yml')
263
260
 
264
261
  YARD::Registry.load!
@@ -282,7 +279,7 @@ task documentation_syntax_check: :yard_for_generate_documentation do
282
279
 
283
280
  ok = true
284
281
  YARD::Registry.load!
285
- cops = RuboCop::Cop::Cop.registry
282
+ cops = RuboCop::Cop::Registry.global
286
283
  cops.each do |cop|
287
284
  examples = YARD::Registry.all(:class).find do |code_object|
288
285
  next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
@@ -291,17 +288,15 @@ task documentation_syntax_check: :yard_for_generate_documentation do
291
288
  end
292
289
 
293
290
  examples.to_a.each do |example|
294
- begin
295
- buffer = Parser::Source::Buffer.new('<code>', 1)
296
- buffer.source = example.text
297
- parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
298
- parser.diagnostics.all_errors_are_fatal = true
299
- parser.parse(buffer)
300
- rescue Parser::SyntaxError => e
301
- path = example.object.file
302
- puts "#{path}: Syntax Error in an example. #{e}"
303
- ok = false
304
- end
291
+ buffer = Parser::Source::Buffer.new('<code>', 1)
292
+ buffer.source = example.text
293
+ parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
294
+ parser.diagnostics.all_errors_are_fatal = true
295
+ parser.parse(buffer)
296
+ rescue Parser::SyntaxError => e
297
+ path = example.object.file
298
+ puts "#{path}: Syntax Error in an example. #{e}"
299
+ ok = false
305
300
  end
306
301
  end
307
302
  abort unless ok
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-faker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi ITO
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2025-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faker
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: lint_roller
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 0.82.0
47
+ version: 1.72.1
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 0.82.0
54
+ version: 1.72.1
41
55
  description: A RuboCop extension for Faker.
42
56
  email:
43
57
  - koic.ito@gmail.com
@@ -46,6 +60,7 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - ".circleci/config.yml"
63
+ - ".github/FUNDING.yml"
49
64
  - ".gitignore"
50
65
  - ".rspec"
51
66
  - ".rubocop.yml"
@@ -62,7 +77,7 @@ files:
62
77
  - lib/rubocop/cop/faker/deprecated_arguments.rb
63
78
  - lib/rubocop/cop/faker_cops.rb
64
79
  - lib/rubocop/faker.rb
65
- - lib/rubocop/faker/inject.rb
80
+ - lib/rubocop/faker/plugin.rb
66
81
  - lib/rubocop/faker/version.rb
67
82
  - manual/cops.md
68
83
  - manual/cops_faker.md
@@ -73,7 +88,9 @@ licenses:
73
88
  - MIT
74
89
  metadata:
75
90
  homepage_uri: https://github.com/koic/rubocop-faker
76
- post_install_message:
91
+ rubygems_mfa_required: 'true'
92
+ default_lint_roller_plugin: RuboCop::Faker::Plugin
93
+ post_install_message:
77
94
  rdoc_options: []
78
95
  require_paths:
79
96
  - lib
@@ -81,15 +98,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
98
  requirements:
82
99
  - - ">="
83
100
  - !ruby/object:Gem::Version
84
- version: 2.4.0
101
+ version: 2.7.0
85
102
  required_rubygems_version: !ruby/object:Gem::Requirement
86
103
  requirements:
87
104
  - - ">="
88
105
  - !ruby/object:Gem::Version
89
106
  version: '0'
90
107
  requirements: []
91
- rubygems_version: 3.1.2
92
- signing_key:
108
+ rubygems_version: 3.1.6
109
+ signing_key:
93
110
  specification_version: 4
94
111
  summary: A RuboCop extension for Faker.
95
112
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Faker
5
- # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
- # bit of our configuration.
7
- module Inject
8
- def self.defaults!
9
- path = CONFIG_DEFAULT.to_s
10
- hash = ConfigLoader.send(:load_yaml_configuration, path)
11
- config = Config.new(hash, path)
12
- puts "configuration from #{path}" if ConfigLoader.debug?
13
- config = ConfigLoader.merge_with_default(config, path)
14
- ConfigLoader.instance_variable_set(:@default_configuration, config)
15
- end
16
- end
17
- end
18
- end