Skip to content

Commit

Permalink
Merge pull request #329 from koic/pluginfy_with_lint_roller
Browse files Browse the repository at this point in the history
Pluginfy RuboCop Minitest
  • Loading branch information
koic authored Feb 15, 2025
2 parents 0bff3d5 + c0d3155 commit 26040f4
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
run: |
sed -e "/gem 'rubocop', github: 'rubocop\/rubocop'/d" -i Gemfile
cat << EOF > Gemfile.local
gem 'rubocop', '1.61.0' # Specify the oldest supported RuboCop version
gem 'rubocop', '1.72.0' # Specify the oldest supported RuboCop version
EOF
- name: set up Ruby
uses: ruby/setup-ruby@v1
Expand Down
8 changes: 5 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# This is the configuration used to check the rubocop source code.

inherit_from: .rubocop_todo.yml

# This is the configuration used to check the rubocop source code.
plugins:
- rubocop-internal_affairs
- rubocop-minitest

require:
- rubocop/cop/internal_affairs
- rubocop-performance
- rubocop-minitest

AllCops:
NewCops: enable
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@ ways to do this:
Put this into your `.rubocop.yml`.

```yaml
require: rubocop-minitest
plugins: rubocop-minitest
```
Alternatively, use the following array notation when specifying multiple extensions.
```yaml
require:
plugins:
- rubocop-other-extension
- rubocop-minitest
```
Now you can run `rubocop` and it will automatically load the RuboCop Minitest
cops together with the standard cops.

> [!NOTE]
> The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.

### Command line

```sh
$ rubocop --require rubocop-minitest
$ rubocop --plugin rubocop-minitest
```

### Rake task
Expand All @@ -56,7 +59,7 @@ $ rubocop --require rubocop-minitest
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-minitest'
task.plugins << 'rubocop-minitest'
end
```

Expand Down
1 change: 1 addition & 0 deletions changelog/new_pluginfy_with_lint_roller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#329](https://github.com/rubocop/rubocop-minitest/pull/329): Pluginfy RuboCop Performance. ([@koic][])
8 changes: 5 additions & 3 deletions docs/modules/ROOT/pages/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@ Put this into your `.rubocop.yml`.

[source,yaml]
----
require: rubocop-minitest
plugins: rubocop-minitest
----

Now you can run `rubocop` and it will automatically load the RuboCop Minitest
cops together with the standard cops.

NOTE: The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.

== Command line

[source,sh]
----
$ rubocop --require rubocop-minitest
$ rubocop --plugin rubocop-minitest
----

== Rake task

[source,ruby]
----
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-minitest'
task.plugins << 'rubocop-minitest'
end
----
5 changes: 1 addition & 4 deletions lib/rubocop-minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

require_relative 'rubocop/minitest'
require_relative 'rubocop/minitest/version'
require_relative 'rubocop/minitest/inject'

RuboCop::Minitest::Inject.defaults!

require_relative 'rubocop/minitest/plugin'
require_relative 'rubocop/cop/minitest_cops'
6 changes: 1 addition & 5 deletions lib/rubocop/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# frozen_string_literal: true

module RuboCop
# RuboCop minitest project namespace
# RuboCop minitest project namespace.
module Minitest
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze

private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
end
end
17 changes: 0 additions & 17 deletions lib/rubocop/minitest/inject.rb

This file was deleted.

31 changes: 31 additions & 0 deletions lib/rubocop/minitest/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'lint_roller'

module RuboCop
module Minitest
# A plugin that integrates RuboCop Minitest with RuboCop's plugin system.
class Plugin < LintRoller::Plugin
def about
LintRoller::About.new(
name: 'rubocop-minitest',
version: Version::STRING,
homepage: 'https://github.com/rubocop/rubocop-minitest',
description: 'Automatic Minitest code style checking tool.'
)
end

def supported?(context)
context.engine == :rubocop
end

def rules(_context)
LintRoller::Rules.new(
type: :path,
config_format: :rubocop,
value: Pathname.new(__dir__).join('../../../config/default.yml')
)
end
end
end
end
4 changes: 3 additions & 1 deletion rubocop-minitest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Gem::Specification.new do |spec|
'source_code_uri' => 'https://github.com/rubocop/rubocop-minitest',
'documentation_uri' => "https://docs.rubocop.org/rubocop-minitest/#{RuboCop::Minitest::Version.document_version}",
'bug_tracker_uri' => 'https://github.com/rubocop/rubocop-minitest/issues',
'rubygems_mfa_required' => 'true'
'rubygems_mfa_required' => 'true',
'default_lint_roller_plugin' => 'RuboCop::Minitest::Plugin'
}

spec.files = Dir['LICENSE.txt', 'README.md', 'config/**/*', 'lib/**/*']
Expand All @@ -32,6 +33,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'lint_roller', '~> 1.1'
spec.add_dependency 'rubocop', '>= 1.61', '< 2.0'
spec.add_dependency 'rubocop-ast', '>= 1.38.0', '< 2.0'
end
2 changes: 1 addition & 1 deletion tasks/cops_documentation.rake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ task update_cops_documentation: :yard_for_generate_documentation do

# NOTE: Update `<<next>>` version for docs/modules/ROOT/pages/cops_minitest.adoc
# when running release tasks.
RuboCop::Minitest::Inject.defaults!
RuboCop::ConfigLoader.inject_defaults!("#{__dir__}/../config/default.yml")

CopsDocumentationGenerator.new(departments: deps).call
end
Expand Down
2 changes: 1 addition & 1 deletion test/rubocop/cop/minitest/global_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def style
private

def configure_enforced_style(style)
all_config = YAML.safe_load(RuboCop::Minitest.const_get(:CONFIG_DEFAULT).read).freeze
all_config = YAML.safe_load(File.read("#{__dir__}/../../../../config/default.yml")).freeze
cop_config = all_config['Minitest/GlobalExpectations']
cop_config = cop_config.merge('EnforcedStyle' => style)
all_config = all_config.merge('Minitest/GlobalExpectations' => cop_config)
Expand Down

0 comments on commit 26040f4

Please sign in to comment.