boxt_rubocop 0.0.46 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/Rakefile +23 -5
- data/VERSION +1 -1
- data/lib/boxt_rubocop.rb +9 -13
- data/lib/rubocop/boxt/inject.rb +20 -0
- data/lib/rubocop/boxt/version.rb +7 -0
- data/lib/rubocop/boxt.rb +14 -0
- data/lib/rubocop/cop/boxt/api_path_format.rb +55 -0
- data/lib/rubocop/cop/boxt_cops.rb +3 -0
- metadata +7 -4
- data/default.yml +0 -60
- data/lib/boxt_rubocop/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 341e8b143a6ca39495d4ecb8f4ac3b4abb9e2035407202d8692fafd01ea32f2b
|
4
|
+
data.tar.gz: 41f53ec76d4e3f54adde9d56aaf4b04bc07c67cf35a0174f01479bbaa2473094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
1
|
+
1.0.0
|
data/lib/boxt_rubocop.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def root
|
13
|
-
Pathname.new(File.dirname(__dir__))
|
14
|
-
end
|
15
|
-
end
|
3
|
+
require "rubocop"
|
4
|
+
|
5
|
+
require_relative "rubocop/boxt"
|
6
|
+
require_relative "rubocop/boxt/version"
|
7
|
+
require_relative "rubocop/boxt/inject"
|
8
|
+
|
9
|
+
RuboCop::Boxt::Inject.defaults!
|
10
|
+
|
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
|
data/lib/rubocop/boxt.rb
ADDED
@@ -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
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Boxt
|
6
|
+
# Clients expect to interface with our API using kebab-case.
|
7
|
+
#
|
8
|
+
# This cop ensures that our API paths are formatted using the correct case.
|
9
|
+
#
|
10
|
+
# Underscores are acceptable in path variables (e.g. "/path/:path_id/update")
|
11
|
+
#
|
12
|
+
# API style guide: https://github.com/boxt/boxt-docs/blob/main/coding-styles/api.md#camel-cased-endpoints
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# # bad
|
16
|
+
# post "/admin/orders/:order_id/contact_details/update"
|
17
|
+
# get "/installation_days"
|
18
|
+
# namespace "password_resets"
|
19
|
+
# namespace :password_resets
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# post "/admin/orders/:order_id/contact-details/update"
|
23
|
+
# get "/installation-days"
|
24
|
+
# namespace "password-resets"
|
25
|
+
#
|
26
|
+
class ApiPathFormat < Base
|
27
|
+
def_node_matcher :path_defining_method_with_string_path, <<~PATTERN
|
28
|
+
(send nil? {:post | :get | :namespace} (:str $_))
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def_node_matcher :namespace_with_symbol, <<~PATTERN
|
32
|
+
(send nil? :namespace (:sym $_))
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
MSG = "Use kebab-case for the API path"
|
36
|
+
|
37
|
+
def on_send(node)
|
38
|
+
path_defining_method_with_string_path(node) do |path|
|
39
|
+
add_offense(node) if path_name_does_not_follow_kebab_case?(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace_with_symbol(node) do |path|
|
43
|
+
add_offense(node) if path.to_s.include?("_")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def path_name_does_not_follow_kebab_case?(path)
|
50
|
+
path.split("/").any? { |split| !split.start_with?(":") && split.include?("_") }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
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
|
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-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -105,9 +105,12 @@ files:
|
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
107
107
|
- VERSION
|
108
|
-
- default.yml
|
109
108
|
- lib/boxt_rubocop.rb
|
110
|
-
- lib/
|
109
|
+
- lib/rubocop/boxt.rb
|
110
|
+
- lib/rubocop/boxt/inject.rb
|
111
|
+
- lib/rubocop/boxt/version.rb
|
112
|
+
- lib/rubocop/cop/boxt/api_path_format.rb
|
113
|
+
- lib/rubocop/cop/boxt_cops.rb
|
111
114
|
- rails.yml
|
112
115
|
- rspec.yml
|
113
116
|
homepage: https://github.com/boxt/boxt_rubocop
|
data/default.yml
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- "**/*/schema.rb"
|
4
|
-
- Gemfile.lock
|
5
|
-
- node_modules/**/*
|
6
|
-
- tmp/**/*
|
7
|
-
- vendor/**/*
|
8
|
-
NewCops: enable
|
9
|
-
|
10
|
-
Layout/ClassStructure:
|
11
|
-
Enabled: true
|
12
|
-
|
13
|
-
Layout/LineLength:
|
14
|
-
Exclude:
|
15
|
-
- config/routes.rb
|
16
|
-
- config/routes/*
|
17
|
-
Max: 120
|
18
|
-
|
19
|
-
Metrics/AbcSize:
|
20
|
-
Exclude:
|
21
|
-
- db/migrate/**/*
|
22
|
-
|
23
|
-
Metrics/BlockLength:
|
24
|
-
CountAsOne: ["array", "hash"]
|
25
|
-
Exclude:
|
26
|
-
- "*.gemspec"
|
27
|
-
- Gemfile
|
28
|
-
- config/environments/*
|
29
|
-
- config/routes.rb
|
30
|
-
- config/routes/*
|
31
|
-
- db/migrate/**/*
|
32
|
-
- lib/tasks/**/*
|
33
|
-
- spec/**/*
|
34
|
-
- test/**/*
|
35
|
-
|
36
|
-
Metrics/ClassLength:
|
37
|
-
CountAsOne: ["array", "hash"]
|
38
|
-
Exclude:
|
39
|
-
- db/migrate/**/*
|
40
|
-
- spec/**/*
|
41
|
-
- test/**/*
|
42
|
-
|
43
|
-
Metrics/MethodLength:
|
44
|
-
CountAsOne: ["array", "heredoc", "hash"]
|
45
|
-
Exclude:
|
46
|
-
- db/migrate/**/*
|
47
|
-
- spec/**/*
|
48
|
-
- test/**/*
|
49
|
-
|
50
|
-
Metrics/ModuleLength:
|
51
|
-
CountAsOne: ["array", "hash"]
|
52
|
-
|
53
|
-
Style/Documentation:
|
54
|
-
Enabled: false
|
55
|
-
|
56
|
-
Style/DoubleNegation:
|
57
|
-
Enabled: false
|
58
|
-
|
59
|
-
Style/StringLiterals:
|
60
|
-
EnforcedStyle: double_quotes
|