-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[N/A] Convert gem to be a rubocop extension (#119)
Updates the gem to follow the conventions in https://github.com/rubocop/rubocop-extension-generator which is used to generate all of the rubocop gems we use (`rubocop-rspec`, `rubocop-rails`, `rubocop-performance`, etc). Converting the gem to a rubocop extension allows us to use the `boxt_rubocop` rubocop config by simply requiring it as we do other rubocop gems: ```yml require: - boxt_rubocop ``` It also has the added benefit of having proper support for custom cops. This means that we can now create custom cops without having to worry about manually disabling them in every project we don't want to use them in. I have left the `rails.yml` and `rspec.yml` configs as separate files that can be imported individually using `inherit_gem`: ```yml inherit_gem: boxt_rubocop: - rails.yml - rspec.yml ``` If we decide that any of these configs should be enabled by default we can simply move them in to `config/default.yml`.
- Loading branch information
1 parent
7b1992b
commit b1a09a4
Showing
16 changed files
with
145 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
inherit_from: | ||
- default.yml | ||
|
||
require: | ||
- boxt_rubocop | ||
- rubocop-performance | ||
- rubocop-rake | ||
- rubocop-rails | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |t| | ||
t.pattern = Dir.glob("spec/**/*_spec.rb") | ||
end | ||
|
||
desc "Map rake test to rake spec" | ||
task test: :spec | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
spec.pattern = FileList["spec/**/*_spec.rb"] | ||
end | ||
|
||
desc "Generate a new cop with a template" | ||
task :new_cop, [:cop] => :environment do |_task, args| | ||
require "rubocop" | ||
|
||
cop_name = args.fetch(:cop) do | ||
warn "usage: bundle exec rake 'new_cop[Boxt/Name]'" | ||
exit! | ||
end | ||
|
||
generator = RuboCop::Cop::Generator.new(cop_name) | ||
|
||
generator.write_source | ||
generator.write_spec | ||
generator.inject_require(root_file_path: "lib/rubocop/cop/boxt_cops.rb") | ||
generator.inject_config(config_file_path: "config/default.yml") | ||
|
||
puts generator.todo | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "boxt_rubocop/version" | ||
require "rubocop" | ||
|
||
# Require all custom cops defined in rubocop/cop/**/*.rb | ||
Dir[File.join(__dir__, "rubocop", "cop", "**", "*.rb")].sort.each { |file| require file } | ||
require_relative "rubocop/boxt" | ||
require_relative "rubocop/boxt/version" | ||
require_relative "rubocop/boxt/inject" | ||
|
||
module BoxtRubocop | ||
module_function | ||
RuboCop::Boxt::Inject.defaults! | ||
|
||
## | ||
# Provide a root path helper for the gem root dir | ||
# | ||
# Returns Pathname | ||
def root | ||
Pathname.new(File.dirname(__dir__)) | ||
end | ||
end | ||
require_relative "rubocop/cop/boxt_cops" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "boxt/version" | ||
|
||
module RuboCop | ||
module Boxt | ||
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) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb | ||
# See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md | ||
module RuboCop | ||
module Boxt | ||
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a | ||
# bit of our configuration. | ||
module Inject | ||
def self.defaults! | ||
path = CONFIG_DEFAULT.to_s | ||
hash = ConfigLoader.send(:load_yaml_configuration, path) | ||
config = Config.new(hash, path).tap(&:make_excludes_absolute) | ||
Rails.logger.debug { "configuration from #{path}" } if ConfigLoader.debug? | ||
config = ConfigLoader.merge_with_default(config, path) | ||
ConfigLoader.instance_variable_set(:@default_configuration, config) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Boxt | ||
VERSION = File.read(File.join(File.dirname(__FILE__), "../../../VERSION")).split("\n").first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "boxt/api_path_format" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Boxt do | ||
let(:current_version) { File.read("VERSION").split("\n").first } | ||
|
||
it "has a version number" do | ||
expect(RuboCop::Boxt::VERSION).not_to be_nil | ||
end | ||
|
||
it "is set from the VERSION file" do | ||
expect(RuboCop::Boxt::VERSION).to eq(current_version) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters