Skip to content

Commit

Permalink
Pluginfy RuboCop Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ngan committed Feb 26, 2025
1 parent 005a485 commit c7039e5
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 50 deletions.
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: .
specs:
rubocop-sorbet (0.8.9)
rubocop (>= 1)
rubocop-sorbet (0.9.0)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)

GEM
remote: https://rubygems.org/
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,33 @@ You need to tell RuboCop to load the Sorbet extension. There are three ways to d
Put this into your `.rubocop.yml`:

```yaml
require: rubocop-sorbet
plugins: rubocop-sorbet
```
Alternatively, use the following array notation when specifying multiple extensions:
```yaml
require:
- rubocop-other-extension
plugins:
- rubocop-sorbet
- rubocop-other-extension
```
Now you can run `rubocop` and it will automatically load the RuboCop Sorbet 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-sorbet
rubocop --plugin rubocop-sorbet
```

### Rake task

```ruby
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-sorbet'
task.plugins << 'rubocop-sorbet'
end
```

Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop-sorbet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

require_relative "rubocop/sorbet"
require_relative "rubocop/sorbet/version"
require_relative "rubocop/sorbet/inject"

RuboCop::Sorbet::Inject.defaults!
require_relative "rubocop/sorbet/plugin"

require_relative "rubocop/cop/sorbet_cops"
8 changes: 0 additions & 8 deletions lib/rubocop/sorbet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@
module RuboCop
module Sorbet
class Error < StandardError; end

PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze

private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)

::RuboCop::ConfigObsoletion.files << PROJECT_ROOT.join("config", "obsoletion.yml")
end
end
30 changes: 0 additions & 30 deletions lib/rubocop/sorbet/inject.rb

This file was deleted.

31 changes: 31 additions & 0 deletions lib/rubocop/sorbet/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 Sorbet
# A plugin that integrates RuboCop Sorbet with RuboCop's plugin system.
class Plugin < LintRoller::Plugin
def about
LintRoller::About.new(
name: 'rubocop-sorbet',
version: Version::STRING,
homepage: 'https://github.com/Shopify/rubocop-sorbet',
description: 'A collection of Rubocop rules for Sorbet.'
)
end

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

def rules(_context)
project_root = Pathname.new(__dir__).join('../../..')

ConfigObsoletion.files << project_root.join('config', 'obsoletion.yml')

LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join('config', 'default.yml'))
end
end
end
end
2 changes: 1 addition & 1 deletion lib/rubocop/sorbet/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module RuboCop
module Sorbet
VERSION = "0.8.9"
VERSION = "0.9.0"
end
end
4 changes: 3 additions & 1 deletion rubocop-sorbet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/shopify/rubocop-sorbet"
spec.metadata["default_lint_roller_plugin"] = "RuboCop::Sorbet::Plugin"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -27,5 +28,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency("rubocop", ">= 1")
spec.add_runtime_dependency("rubocop", ">= 1.72.1")
spec.add_runtime_dependency("lint_roller", "~> 1.1")
end

0 comments on commit c7039e5

Please sign in to comment.