boxt_rubocop 0.0.47 → 1.0.0

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: 341e8b143a6ca39495d4ecb8f4ac3b4abb9e2035407202d8692fafd01ea32f2b
4
+ data.tar.gz: 41f53ec76d4e3f54adde9d56aaf4b04bc07c67cf35a0174f01479bbaa2473094
5
5
  SHA512:
6
- metadata.gz: ffc8ad1b40e20af26e8075a98e8bea4dec62c049d7bf2fe5af26df988748a710ebcd4ca121ad698a95a2b61e0c312161296c8a500fc1e2a75c4ad9f4e8047ebc
7
- data.tar.gz: 87b2a5ef84b0c422310df7b798b7a436b130869f80ff4588ec649c3808b22c18cac971bfc4e67b81a0286a8f827397bfbb3034aee947c06b47996c23ea675dc8
6
+ metadata.gz: d5b071c38cc59d28d142aef6b24869a1d1e3a2dfbb02d1ab65faa3a7ad6eeed31b7bea037f600cdd3a6a7dc89b91f5816cd1abd9548920b94e3c13a7773a0aeb
7
+ data.tar.gz: 433ef4aced8b97690fb92a2a2346d40c944ad56caaf8304f547d40900f731ba8edb625055bc2e0d49e8ae96af73354e1604a063c2b390c3f4b778cd67e131bf7
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.0
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.0
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,12 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - VERSION
108
- - default.yml
109
108
  - lib/boxt_rubocop.rb
110
- - lib/boxt_rubocop/version.rb
109
+ - lib/rubocop/boxt.rb
110
+ - lib/rubocop/boxt/inject.rb
111
+ - lib/rubocop/boxt/version.rb
111
112
  - lib/rubocop/cop/boxt/api_path_format.rb
113
+ - lib/rubocop/cop/boxt_cops.rb
112
114
  - rails.yml
113
115
  - rspec.yml
114
116
  homepage: https://github.com/boxt/boxt_rubocop
data/default.yml DELETED
@@ -1,63 +0,0 @@
1
- require:
2
- - ./lib/rubocop/cop/boxt/api_path_format.rb
3
-
4
- AllCops:
5
- Exclude:
6
- - "**/*/schema.rb"
7
- - Gemfile.lock
8
- - node_modules/**/*
9
- - tmp/**/*
10
- - vendor/**/*
11
- NewCops: enable
12
-
13
- Layout/ClassStructure:
14
- Enabled: true
15
-
16
- Layout/LineLength:
17
- Exclude:
18
- - config/routes.rb
19
- - config/routes/*
20
- Max: 120
21
-
22
- Metrics/AbcSize:
23
- Exclude:
24
- - db/migrate/**/*
25
-
26
- Metrics/BlockLength:
27
- CountAsOne: ["array", "hash"]
28
- Exclude:
29
- - "*.gemspec"
30
- - Gemfile
31
- - config/environments/*
32
- - config/routes.rb
33
- - config/routes/*
34
- - db/migrate/**/*
35
- - lib/tasks/**/*
36
- - spec/**/*
37
- - test/**/*
38
-
39
- Metrics/ClassLength:
40
- CountAsOne: ["array", "hash"]
41
- Exclude:
42
- - db/migrate/**/*
43
- - spec/**/*
44
- - test/**/*
45
-
46
- Metrics/MethodLength:
47
- CountAsOne: ["array", "heredoc", "hash"]
48
- Exclude:
49
- - db/migrate/**/*
50
- - spec/**/*
51
- - test/**/*
52
-
53
- Metrics/ModuleLength:
54
- CountAsOne: ["array", "hash"]
55
-
56
- Style/Documentation:
57
- Enabled: false
58
-
59
- Style/DoubleNegation:
60
- Enabled: false
61
-
62
- Style/StringLiterals:
63
- EnforcedStyle: double_quotes
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BoxtRubocop
4
- VERSION = File.read("VERSION").split("\n").first
5
- end