rubocop-config-captive 1.4.2 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +1 -0
- data/config/rubocop-captive.yml +14 -0
- data/config/rubocop-layout.yml +5 -0
- data/config/rubocop-style.yml +9 -0
- data/lib/rubocop/captive/inject.rb +1 -1
- data/lib/rubocop/captive/version.rb +1 -1
- data/lib/rubocop/captive.rb +4 -4
- data/lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb +2 -2
- data/lib/rubocop/cop/captive/rails/no_email_from_controller.rb +39 -0
- data/lib/rubocop/cop/captive/rspec/specify_before_parameter.rb +62 -0
- data/lib/rubocop/cop/captive/string_where_in_scope.rb +1 -1
- data/lib/rubocop/cop/captive/translation/devise_i18n_presence.rb +2 -2
- data/lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb +3 -3
- data/lib/rubocop/cop/captive/translation/rails_i18n_presence.rb +3 -3
- data/lib/rubocop-captive.rb +8 -8
- data/rubocop-config-captive.gemspec +22 -22
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5756c218562b8bb428e080131872a1d86d05631ab0356b2a22b36411733732c
|
4
|
+
data.tar.gz: 70e0e42455ef3fa6dd8f69fd2192f4961cc9d8eebab8d60a10b68b96a359379d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 020a795f4efc08e561f4c280bc2c1016b08d1d3819e11c5f9a17971aa6ada85dd96a768aa4875ddf3056dcc1fb63afb8e904416918ef29c16efb19f0bd696000
|
7
|
+
data.tar.gz: c968e241425d6ab95fd76b22d7c3edcf49dda21760ca7c9dbff05ee89e3d8db25ba85b2b79a343ca4b88a31d0b000d4d850eef53300f34aabb5e01c05a0b014d
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/config/rubocop-captive.yml
CHANGED
@@ -3,6 +3,8 @@ require:
|
|
3
3
|
- ../lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
|
4
4
|
- ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
|
5
5
|
- ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
|
6
|
+
- ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
7
|
+
- ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
|
6
8
|
- ../lib/rubocop/cop/captive/string_where_in_scope.rb
|
7
9
|
- ../lib/rubocop/cop/captive/no_app_env.rb
|
8
10
|
|
@@ -28,6 +30,18 @@ Captive/Translation/KaminariI18nPresence:
|
|
28
30
|
Include:
|
29
31
|
- 'Gemfile'
|
30
32
|
|
33
|
+
# RSpec
|
34
|
+
Captive/RSpec/SpecifyBeforeParameter:
|
35
|
+
Description: 'Specify the parameter in `before` blocks. Example : before(:each) or before(:all)'
|
36
|
+
Include:
|
37
|
+
- 'spec/**/*'
|
38
|
+
|
39
|
+
# Rails
|
40
|
+
Captive/Rails/NoEmailFromController:
|
41
|
+
Description: "Do not send emails from controllers. Because it doesn't follow the MVC standard"
|
42
|
+
Include:
|
43
|
+
- 'app/controllers/**/*'
|
44
|
+
|
31
45
|
# other
|
32
46
|
Captive/StringWhereInScope:
|
33
47
|
Description: 'The `where` method should be used in a scope in a model.'
|
data/config/rubocop-layout.yml
CHANGED
data/config/rubocop-style.yml
CHANGED
@@ -1,3 +1,12 @@
|
|
1
1
|
inherit_from:
|
2
2
|
# @see https://github.com/airbnb/ruby/blob/main/rubocop-airbnb/config/rubocop-style.yml
|
3
3
|
- ./__private__/rubocop-style.yml
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
ConsistentQuotesInMultiline: false
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
data/lib/rubocop/captive.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "psych"
|
3
3
|
|
4
|
-
Dir.glob(File.expand_path(
|
4
|
+
Dir.glob(File.expand_path("cop/**/*.rb", File.dirname(__FILE__))).map(&method(:require))
|
5
5
|
|
6
6
|
module RuboCop
|
7
7
|
# RuboCop Captive project namespace
|
8
8
|
module Captive
|
9
9
|
PROJECT_ROOT =
|
10
10
|
Pathname.new(__FILE__).parent.parent.parent.expand_path.freeze
|
11
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join(
|
11
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
|
12
12
|
CONFIG = Psych.safe_load(CONFIG_DEFAULT.read).freeze
|
13
13
|
|
14
14
|
private_constant(*constants(false))
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
return unless node.command?(:gem)
|
22
22
|
|
23
23
|
gem_name = node.arguments[0]&.value
|
24
|
-
return unless gem_name ==
|
24
|
+
return unless gem_name == "activeadmin"
|
25
25
|
|
26
26
|
add_offense(node, message: MSG) unless activeadmin_addons_present?
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def activeadmin_addons_present?
|
32
|
-
Gem.loaded_specs.keys.include?(
|
32
|
+
Gem.loaded_specs.keys.include?("activeadmin_addons")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Captive
|
6
|
+
module Rails
|
7
|
+
# This cop checks for email delivery methods in controllers.
|
8
|
+
# Sending email in controllers is not allowed in order to follow the MVC standard
|
9
|
+
# An email must be sent from a Model
|
10
|
+
class NoEmailFromController < Base
|
11
|
+
MSG = "Do not send emails from controllers. Because it doesn't follow the MVC standard"
|
12
|
+
|
13
|
+
def_node_search :email_delivery?, <<~PATTERN
|
14
|
+
(send _ {:deliver_now :deliver_later})
|
15
|
+
PATTERN
|
16
|
+
|
17
|
+
def on_send(node)
|
18
|
+
return unless email_delivery?(node)
|
19
|
+
|
20
|
+
controller_class = find_controller_class(node)
|
21
|
+
return unless controller_class
|
22
|
+
|
23
|
+
add_offense(node, message: MSG)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def find_controller_class(node)
|
29
|
+
node.ancestors.find do |ancestor|
|
30
|
+
ancestor.is_a?(Parser::AST::Node) &&
|
31
|
+
ancestor.type == :class &&
|
32
|
+
ancestor.children[0].const_type?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Captive
|
6
|
+
module RSpec
|
7
|
+
# This cop enforces specifying the parameter in RSpec `before` blocks.
|
8
|
+
#
|
9
|
+
# The cops was created because many people didn't know that `before`
|
10
|
+
# method has default parameter value : `:each`
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # bad
|
14
|
+
# before do
|
15
|
+
# ...
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# before(:each) do
|
20
|
+
# ...
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# before(:all) do
|
24
|
+
# ...
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
class SpecifyBeforeParameter < RuboCop::Cop::Base
|
28
|
+
extend AutoCorrector
|
29
|
+
|
30
|
+
MSG = "Specify the parameter in `before` blocks. Example : before(:each) or before(:all)"
|
31
|
+
|
32
|
+
def_node_matcher :before_block?, <<~PATTERN
|
33
|
+
(block
|
34
|
+
(send nil? :before ...)
|
35
|
+
...
|
36
|
+
)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def_node_search :before_without_parameter?, <<~PATTERN
|
40
|
+
(send nil? :before)
|
41
|
+
PATTERN
|
42
|
+
|
43
|
+
def on_block(node)
|
44
|
+
return unless before_block?(node)
|
45
|
+
return unless before_without_parameter?(node)
|
46
|
+
|
47
|
+
add_offense(node, message: MSG) do |corrector|
|
48
|
+
corrector.replace(node.loc.expression, add_parameter(node))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def add_parameter(node)
|
55
|
+
source = node.loc.expression.source
|
56
|
+
source.insert(source.index("before") + 6, "(:each)")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -18,7 +18,7 @@ module RuboCop
|
|
18
18
|
#
|
19
19
|
# scope :date_after, ->(date) { where('date > ?', date) }
|
20
20
|
class StringWhereInScope < RuboCop::Cop::Cop
|
21
|
-
MSG =
|
21
|
+
MSG = "The `where` method should be used in a scope in a model."
|
22
22
|
|
23
23
|
def_node_matcher :where_with_string?, <<~PATTERN
|
24
24
|
(send _ :where (str _) ...)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
return unless node.command?(:gem)
|
22
22
|
|
23
23
|
gem_name = node.arguments[0]&.value
|
24
|
-
return unless gem_name ==
|
24
|
+
return unless gem_name == "devise"
|
25
25
|
|
26
26
|
add_offense(node, message: MSG) unless devise_i18n_present?
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module RuboCop
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def devise_i18n_present?
|
32
|
-
Gem.loaded_specs.keys.include?(
|
32
|
+
Gem.loaded_specs.keys.include?("devise-i18n")
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rubocop"
|
4
4
|
|
5
5
|
module RuboCop
|
6
6
|
module Cop
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
return unless node.command?(:gem)
|
24
24
|
|
25
25
|
gem_name = node.arguments[0]&.value
|
26
|
-
return unless gem_name ==
|
26
|
+
return unless gem_name == "kaminari"
|
27
27
|
|
28
28
|
add_offense(node, message: MSG) unless kaminari_i18n_present?
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def kaminari_i18n_present?
|
34
|
-
Gem.loaded_specs.keys.include?(
|
34
|
+
Gem.loaded_specs.keys.include?("kaminari-i18n")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rubocop"
|
4
4
|
|
5
5
|
module RuboCop
|
6
6
|
module Cop
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
return unless node.command?(:gem)
|
24
24
|
|
25
25
|
gem_name = node.arguments[0]&.value
|
26
|
-
return unless gem_name ==
|
26
|
+
return unless gem_name == "rails"
|
27
27
|
|
28
28
|
add_offense(node, message: MSG) unless rails_i18n_present?
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def rails_i18n_present?
|
34
|
-
Gem.loaded_specs.keys.include?(
|
34
|
+
Gem.loaded_specs.keys.include?("rails-i18n")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/rubocop-captive.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "pathname"
|
2
|
+
require "yaml"
|
3
3
|
|
4
4
|
# Load original rubocop gem
|
5
|
-
require
|
5
|
+
require "rubocop"
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "rubocop-performance"
|
8
|
+
require "rubocop-rails"
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "rubocop/captive"
|
11
|
+
require "rubocop/captive/inject"
|
12
|
+
require "rubocop/captive/version"
|
13
13
|
|
14
14
|
RuboCop::Captive::Inject.defaults!
|
@@ -1,37 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.expand_path(
|
4
|
-
require
|
3
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
4
|
+
require "rubocop/captive/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = "rubocop-config-captive"
|
8
8
|
gem.version = RuboCop::Captive::VERSION
|
9
|
-
gem.summary =
|
10
|
-
gem.description =
|
11
|
-
gem.authors = [
|
12
|
-
gem.email = [
|
13
|
-
gem.homepage =
|
14
|
-
gem.license =
|
15
|
-
gem.required_ruby_version =
|
9
|
+
gem.summary = "Shared rubocop configurations"
|
10
|
+
gem.description = "Shared rubocop configuration for Captive projects"
|
11
|
+
gem.authors = ["Captive", "Julien Polo", "Clément Prod'homme"]
|
12
|
+
gem.email = ["julien.polo@captive.fr"]
|
13
|
+
gem.homepage = "https://github.com/Captive-Studio/rubocop-config"
|
14
|
+
gem.license = "MIT"
|
15
|
+
gem.required_ruby_version = ">= 2.6"
|
16
16
|
|
17
17
|
gem.files = Dir[
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
"{config,lib}/**/*",
|
19
|
+
"*.md",
|
20
|
+
"*.gemspec",
|
21
|
+
"Gemfile",
|
22
22
|
]
|
23
23
|
|
24
24
|
# It is not clear what the level of support is provided by Airbnb
|
25
25
|
# ⚠️ Instead of depending on rubocop-airbnb we copy sources
|
26
26
|
#
|
27
27
|
# gem.add_dependency('rubocop-airbnb', '~> 4.0.0')
|
28
|
-
gem.add_dependency(
|
29
|
-
gem.add_dependency(
|
30
|
-
gem.add_dependency(
|
31
|
-
gem.add_dependency(
|
32
|
-
gem.add_dependency(
|
33
|
-
gem.add_dependency(
|
34
|
-
gem.add_dependency(
|
35
|
-
gem.add_development_dependency(
|
28
|
+
gem.add_dependency("rubocop", "~> 1.51.0")
|
29
|
+
gem.add_dependency("rubocop-performance", "~> 1.17.1 ")
|
30
|
+
gem.add_dependency("rubocop-rake", "~> 0.6.0")
|
31
|
+
gem.add_dependency("rubocop-rails", "~> 2.18.0")
|
32
|
+
gem.add_dependency("rubocop-rspec", "~> 2.22.0")
|
33
|
+
gem.add_dependency("rubocop-capybara", "~> 2.18.0")
|
34
|
+
gem.add_dependency("rubocop-factory_bot", "~> 2.23.1")
|
35
|
+
gem.add_development_dependency("rspec", "~> 3.12")
|
36
36
|
# gem.metadata['rubygems_mfa_required'] = 'true'
|
37
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-config-captive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captive
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-08-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -169,6 +169,8 @@ files:
|
|
169
169
|
- lib/rubocop/captive/version.rb
|
170
170
|
- lib/rubocop/cop/captive/active_admin/active_admin_addons_presence.rb
|
171
171
|
- lib/rubocop/cop/captive/no_app_env.rb
|
172
|
+
- lib/rubocop/cop/captive/rails/no_email_from_controller.rb
|
173
|
+
- lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
|
172
174
|
- lib/rubocop/cop/captive/string_where_in_scope.rb
|
173
175
|
- lib/rubocop/cop/captive/translation/devise_i18n_presence.rb
|
174
176
|
- lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
|