boxt_rubocop 0.0.47 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 231009180ee1b9b0868430b15b773ca50a8101ffb8a66a1398e5b1bb78f366fb
4
- data.tar.gz: bdc82cf8a6f8bf3a928c088bd260b22bafbc4ed26db8e2a43b4b6fef3acbadde
3
+ metadata.gz: 1744a7d3b5eec56f26ffb86af39b0bf4ff4178a59f9480f4129fcbccbff30c0e
4
+ data.tar.gz: d0a3ab0c0b3946e9800c3b254c856a24d960e521f6f70e21296c57fd602855b3
5
5
  SHA512:
6
- metadata.gz: ffc8ad1b40e20af26e8075a98e8bea4dec62c049d7bf2fe5af26df988748a710ebcd4ca121ad698a95a2b61e0c312161296c8a500fc1e2a75c4ad9f4e8047ebc
7
- data.tar.gz: 87b2a5ef84b0c422310df7b798b7a436b130869f80ff4588ec649c3808b22c18cac971bfc4e67b81a0286a8f827397bfbb3034aee947c06b47996c23ea675dc8
6
+ metadata.gz: 3790f37f11cb18067d2e9419ec525d35b04938f47422529fd6be992962cd90e5309d55ad727b8a9e364a95d26831ed797dd24f647e35bbc30eac61a478402433
7
+ data.tar.gz: 52c2d7a75751ea244e9f89687fbcc83a69e47171e8f922ce364d7b4059ed36fc4379d81f105efd400dc8611a68f00a42b38f54752eee11deb8bbf388f8f85bbf
data/README.md CHANGED
@@ -28,16 +28,37 @@ bundle
28
28
 
29
29
  ## Usage
30
30
 
31
- Add a `.rubocop.yml` file to the root of your project with the following settings:
31
+ Put this into your .rubocop.yml.
32
+
33
+ ```yml
34
+ require:
35
+ - boxt_rubocop
36
+ ```
37
+
38
+ To enable additional configuration for `rubocop-rails` and `rubocop-rspec`, add the following to your .rubocop.yml:
32
39
 
33
40
  ```yml
34
41
  inherit_gem:
35
42
  boxt_rubocop:
36
- - default.yml # use default cops
37
43
  - rails.yml # use Rails cops - see Additional Extensions/Cops
38
44
  - rspec.yml # use rspec cops - see Additional Extensions/Cops
39
45
  ```
40
46
 
47
+ ## Creating new custom cops
48
+
49
+ Use the rake task new_cop to generate a cop template:
50
+
51
+ ```sh
52
+ $ bundle exec rake 'new_cop[Boxt/Name]'
53
+ [create] lib/rubocop/cop/boxt/name.rb
54
+ [create] spec/rubocop/cop/boxt/name_spec.rb
55
+ [modify] lib/rubocop/cop/boxt_cops.rb - `require_relative 'boxt/name'` was injected.
56
+ [modify] A configuration for the cop is added into config/default.yml.
57
+
58
+ ```
59
+
60
+ Documentation on creating a new cop can be found [here](https://docs.rubocop.org/rubocop/1.56/development.html#create-a-new-cop).
61
+
41
62
  ### NewCops
42
63
 
43
64
  `NewCops` is enabled by default.
data/Rakefile CHANGED
@@ -1,12 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rake/testtask"
5
4
  require "rspec/core/rake_task"
6
5
 
7
- RSpec::Core::RakeTask.new(:spec) do |t|
8
- t.pattern = Dir.glob("spec/**/*_spec.rb")
9
- end
10
-
11
6
  desc "Map rake test to rake spec"
12
7
  task test: :spec
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList["spec/**/*_spec.rb"]
11
+ end
12
+
13
+ desc "Generate a new cop with a template"
14
+ task :new_cop, [:cop] => :environment do |_task, args|
15
+ require "rubocop"
16
+
17
+ cop_name = args.fetch(:cop) do
18
+ warn "usage: bundle exec rake 'new_cop[Boxt/Name]'"
19
+ exit!
20
+ end
21
+
22
+ generator = RuboCop::Cop::Generator.new(cop_name)
23
+
24
+ generator.write_source
25
+ generator.write_spec
26
+ generator.inject_require(root_file_path: "lib/rubocop/cop/boxt_cops.rb")
27
+ generator.inject_config(config_file_path: "config/default.yml")
28
+
29
+ puts generator.todo
30
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.47
1
+ 1.0.1
@@ -1,6 +1,3 @@
1
- require:
2
- - ./lib/rubocop/cop/boxt/api_path_format.rb
3
-
4
1
  AllCops:
5
2
  Exclude:
6
3
  - "**/*/schema.rb"
@@ -10,6 +7,10 @@ AllCops:
10
7
  - vendor/**/*
11
8
  NewCops: enable
12
9
 
10
+ Boxt/ApiPathFormat:
11
+ Description: 'Ensure that the API path uses kebab case'
12
+ Enabled: false
13
+
13
14
  Layout/ClassStructure:
14
15
  Enabled: true
15
16
 
data/lib/boxt_rubocop.rb CHANGED
@@ -1,18 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "boxt_rubocop/version"
3
+ require "rubocop"
4
4
 
5
- # Require all custom cops defined in rubocop/cop/**/*.rb
6
- Dir[File.join(__dir__, "rubocop", "cop", "**", "*.rb")].sort.each { |file| require file }
5
+ require_relative "rubocop/boxt"
6
+ require_relative "rubocop/boxt/version"
7
+ require_relative "rubocop/boxt/inject"
7
8
 
8
- module BoxtRubocop
9
- module_function
9
+ RuboCop::Boxt::Inject.defaults!
10
10
 
11
- ##
12
- # Provide a root path helper for the gem root dir
13
- #
14
- # Returns Pathname
15
- def root
16
- Pathname.new(File.dirname(__dir__))
17
- end
18
- end
11
+ require_relative "rubocop/cop/boxt_cops"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
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
+ module RuboCop
6
+ module Boxt
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ Rails.logger.debug { "configuration from #{path}" } if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Boxt
5
+ VERSION = File.read(File.join(File.dirname(__FILE__), "../../../VERSION")).split("\n").first
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "boxt/version"
4
+
5
+ module RuboCop
6
+ module Boxt
7
+ class Error < StandardError; end
8
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
9
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
10
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
11
+
12
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
13
+ end
14
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rubocop"
4
-
5
3
  module RuboCop
6
4
  module Cop
7
5
  module Boxt
@@ -25,7 +23,7 @@ module RuboCop
25
23
  # get "/installation-days"
26
24
  # namespace "password-resets"
27
25
  #
28
- class ApiPathFormat < ::RuboCop::Cop::Base
26
+ class ApiPathFormat < Base
29
27
  def_node_matcher :path_defining_method_with_string_path, <<~PATTERN
30
28
  (send nil? {:post | :get | :namespace} (:str $_))
31
29
  PATTERN
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "boxt/api_path_format"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxt_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.47
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boxt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-26 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -105,10 +105,13 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - VERSION
108
- - default.yml
108
+ - config/default.yml
109
109
  - lib/boxt_rubocop.rb
110
- - lib/boxt_rubocop/version.rb
110
+ - lib/rubocop/boxt.rb
111
+ - lib/rubocop/boxt/inject.rb
112
+ - lib/rubocop/boxt/version.rb
111
113
  - lib/rubocop/cop/boxt/api_path_format.rb
114
+ - lib/rubocop/cop/boxt_cops.rb
112
115
  - rails.yml
113
116
  - rspec.yml
114
117
  homepage: https://github.com/boxt/boxt_rubocop
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BoxtRubocop
4
- VERSION = File.read("VERSION").split("\n").first
5
- end