rubocop-config-captive 1.5.0 → 1.6.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: daad52b9ec57ffb696430f0f7b9a1c797b841afb97c64e86bd8610730fdaecaf
4
- data.tar.gz: 82d299623bea48f72e8b71111309d051c829782b2f5b5648b3e5f49b3e67c780
3
+ metadata.gz: b5756c218562b8bb428e080131872a1d86d05631ab0356b2a22b36411733732c
4
+ data.tar.gz: 70e0e42455ef3fa6dd8f69fd2192f4961cc9d8eebab8d60a10b68b96a359379d
5
5
  SHA512:
6
- metadata.gz: 2727c1c5c3f2d413e832167b303bb77ecb495a2c65e0fc82147a19882c511fa5235005f471c085f92e9204140b69a7c48e0ad14bbcd4289e1e746e3ab8f2839c
7
- data.tar.gz: 0cb908ed58c39398e9bfa1c2f2b49e7ab7ffd96ec5c78518722db0afc992505ad1185064503f97cbe76e9fca604678ee7214bb32ae795f21071724e13b99c0a4
6
+ metadata.gz: 020a795f4efc08e561f4c280bc2c1016b08d1d3819e11c5f9a17971aa6ada85dd96a768aa4875ddf3056dcc1fb63afb8e904416918ef29c16efb19f0bd696000
7
+ data.tar.gz: c968e241425d6ab95fd76b22d7c3edcf49dda21760ca7c9dbff05ee89e3d8db25ba85b2b79a343ca4b88a31d0b000d4d850eef53300f34aabb5e01c05a0b014d
data/Gemfile CHANGED
@@ -5,9 +5,9 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- gem 'yard', '~> 0.9.34'
8
+ gem "yard", "~> 0.9.34"
9
9
  end
10
10
 
11
11
  group :test do
12
- gem 'pry', '0.14.2'
12
+ gem "pry", "0.14.2"
13
13
  end
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Captive Rubocop config
2
2
 
3
3
  [![License][license-image]][license-url]
4
+ [![Gem Version](https://img.shields.io/gem/v/rubocop-config-captive.svg)](https://rubygems.org/gems/rubocop-config-captive)
4
5
 
5
6
  > Rubocop shared configurations for projects
6
7
 
@@ -4,6 +4,7 @@ require:
4
4
  - ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
5
5
  - ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
6
6
  - ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
7
+ - ../lib/rubocop/cop/captive/rails/no_email_from_controller.rb
7
8
  - ../lib/rubocop/cop/captive/string_where_in_scope.rb
8
9
  - ../lib/rubocop/cop/captive/no_app_env.rb
9
10
 
@@ -35,6 +36,12 @@ Captive/RSpec/SpecifyBeforeParameter:
35
36
  Include:
36
37
  - 'spec/**/*'
37
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
+
38
45
  # other
39
46
  Captive/StringWhereInScope:
40
47
  Description: 'The `where` method should be used in a scope in a model.'
@@ -43,3 +43,8 @@ Layout/MultilineMethodParameterLineBreaks:
43
43
  Layout/LineLength:
44
44
  # Disable LineLength on comments
45
45
  AllowedPatterns: ['^(\s*#)']
46
+ Exclude:
47
+ - 'spec/**/*.rb'
48
+ - 'test/**/*.rb'
49
+ - '**/*_spec.rb'
50
+ - '**/*_test.rb'
@@ -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
@@ -1,6 +1,6 @@
1
1
  # Straight up ripped from the custom Rspec rubocop
2
2
  # https://github.com/nevir/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
3
- require 'yaml'
3
+ require "yaml"
4
4
 
5
5
  module RuboCop
6
6
  module Captive
@@ -3,6 +3,6 @@
3
3
  module RuboCop
4
4
  module Captive
5
5
  # Version information for the the Airbnb RuboCop plugin.
6
- VERSION = '1.5.0'
6
+ VERSION = "1.6.0"
7
7
  end
8
8
  end
@@ -1,14 +1,14 @@
1
- require 'pathname'
2
- require 'psych'
1
+ require "pathname"
2
+ require "psych"
3
3
 
4
- Dir.glob(File.expand_path('cop/**/*.rb', File.dirname(__FILE__))).map(&method(:require))
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('config', 'default.yml').freeze
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 == 'activeadmin'
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?('activeadmin_addons')
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
@@ -27,7 +27,7 @@ module RuboCop
27
27
  class SpecifyBeforeParameter < RuboCop::Cop::Base
28
28
  extend AutoCorrector
29
29
 
30
- MSG = 'Specify the parameter in `before` blocks. Example : before(:each) or before(:all)'
30
+ MSG = "Specify the parameter in `before` blocks. Example : before(:each) or before(:all)"
31
31
 
32
32
  def_node_matcher :before_block?, <<~PATTERN
33
33
  (block
@@ -53,7 +53,7 @@ module RuboCop
53
53
 
54
54
  def add_parameter(node)
55
55
  source = node.loc.expression.source
56
- source.insert(source.index('before') + 6, '(:each)')
56
+ source.insert(source.index("before") + 6, "(:each)")
57
57
  end
58
58
  end
59
59
  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 = 'The `where` method should be used in a scope in a model.'
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 == 'devise'
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?('devise-i18n')
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 'rubocop'
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 == 'kaminari'
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?('kaminari-i18n')
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 'rubocop'
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 == 'rails'
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?('rails-i18n')
34
+ Gem.loaded_specs.keys.include?("rails-i18n")
35
35
  end
36
36
  end
37
37
  end
@@ -1,14 +1,14 @@
1
- require 'pathname'
2
- require 'yaml'
1
+ require "pathname"
2
+ require "yaml"
3
3
 
4
4
  # Load original rubocop gem
5
- require 'rubocop'
5
+ require "rubocop"
6
6
 
7
- require 'rubocop-performance'
8
- require 'rubocop-rails'
7
+ require "rubocop-performance"
8
+ require "rubocop-rails"
9
9
 
10
- require 'rubocop/captive'
11
- require 'rubocop/captive/inject'
12
- require 'rubocop/captive/version'
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('../lib', __FILE__)
4
- require 'rubocop/captive/version'
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 = 'rubocop-config-captive'
7
+ gem.name = "rubocop-config-captive"
8
8
  gem.version = RuboCop::Captive::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'
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
- '{config,lib}/**/*',
19
- '*.md',
20
- '*.gemspec',
21
- 'Gemfile',
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('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')
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.5.0
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-06-27 00:00:00.000000000 Z
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,7 @@ 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
172
173
  - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
173
174
  - lib/rubocop/cop/captive/string_where_in_scope.rb
174
175
  - lib/rubocop/cop/captive/translation/devise_i18n_presence.rb