gl_rubocop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2722762e37718da016ff909dc1386f835f5fdb8f20ce44ecd8114a7980191152
4
+ data.tar.gz: cadaf9bcbb5b045cab2a678cd5d5c9154ab513ed9931ed403e4e9478adf5c756
5
+ SHA512:
6
+ metadata.gz: 98cf48d132aaf848c6d5308cac9f9b30f185860fb191441a94f3c147d8de720369acc1ef2524d9551a2e1706ae456ff8295fbdaed03c1a23c95d3eda3305b57b
7
+ data.tar.gz: 35dc30bbd8620cf814683a0512b8e6c8f2edb3862d221a3cfe0d891e7895d60589d4378f01752b6fe97b5017be91b4c98f39bda04e1160c4f8f2a991575a9b2f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Give Lively
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # gl_rubocop
2
+ A shareable configuration of rules we use at Give Lively to lint our Ruby code.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gl_rubocop/version'
4
+
5
+ NON_GEM_FILES = ['Gemfile', 'Gemfile.lock', 'Guardfile', 'bin/lint'].freeze
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gl_rubocop'
9
+ spec.version = GLRubocop::VERSION
10
+ spec.authors = ['Give Lively']
11
+
12
+ spec.summary = "A shareable configuration of Give Lively's rubocop rules."
13
+ spec.homepage = 'https://github.com/givelively/gl_rubocop'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.1'
16
+
17
+ spec.extra_rdoc_files = ['README.md']
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = %w[gl_rubocop.gemspec README.md LICENSE] +
22
+ `git ls-files | grep -E '^(lib)'`.split("\n")
23
+
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'rubocop', '~> 1.62.0'
29
+ spec.add_dependency 'rubocop-magic_numbers'
30
+ spec.add_dependency 'rubocop-performance'
31
+ spec.add_dependency 'rubocop-rails'
32
+ spec.add_dependency 'rubocop-rake'
33
+ spec.add_dependency 'rubocop-rspec', '~> 2.25'
34
+
35
+ spec.metadata['rubygems_mfa_required'] = 'true'
36
+ end
@@ -0,0 +1,23 @@
1
+ module GLRubocop
2
+ module GLCops
3
+ # This cop ensures that controller callbacks are named methods, not inline blocks.
4
+ #
5
+ # Good:
6
+ # before_action :set_user
7
+ #
8
+ # Bad:
9
+ # before_action { do_something }
10
+ # before_action -> { do_something }
11
+ class CallbackMethodNames < RuboCop::Cop::Cop
12
+ CALLBACKS = %i[before_action after_action around_action].freeze
13
+
14
+ def on_send(node)
15
+ return unless CALLBACKS.include?(node.method_name)
16
+
17
+ error_message = 'Use a named method for controller callbacks instead of an inline block.'
18
+
19
+ add_offense(node, message: error_message) if node.parent&.block_type?
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module GLRubocop
2
+ module GLCops
3
+ class InteractorInheritsFromInteractorBase < RuboCop::Cop::Cop
4
+ def on_class(klass)
5
+ return unless klass.instance_of?(RuboCop::AST::ClassNode)
6
+ return unless klass.parent_class.nil?
7
+
8
+ add_offense(klass)
9
+ end
10
+
11
+ MSG = 'Interactor should inherit from InteractorBase'.freeze
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module GLRubocop
2
+ module GLCops
3
+ class PreventErbFiles < RuboCop::Cop::Cop
4
+ MSG = 'File name should not end with .erb'.freeze
5
+
6
+ def investigate(processed_source)
7
+ file_path = processed_source.buffer.name
8
+ return unless File.extname(file_path) == '.erb'
9
+
10
+ range = processed_source.buffer.source_range
11
+ add_offense(nil, location: range, message: MSG)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module GLRubocop
2
+ module GLCops
3
+ class SidekiqInheritsFromSidekiqJob < RuboCop::Cop::Cop
4
+ def on_class(klass)
5
+ return unless klass.instance_of?(RuboCop::AST::ClassNode)
6
+ return if klass.parent_class.present? || klass.identifier.short_name == :SidekiqJob
7
+
8
+ add_offense(klass)
9
+ end
10
+
11
+ MSG = 'All Sidekiq workers and jobs should inherit from SidekiqJob'.freeze
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module GLRubocop
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/gl_rubocop.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubocop'
2
+
3
+ module GLRubocop
4
+ PROJECT_ROOT = File.expand_path('../', __dir__)
5
+ CONFIG_DEFAULT = File.join(PROJECT_ROOT, '.rubocop.yml')
6
+
7
+ # Register your custom RuboCop config
8
+ RuboCop::ConfigLoader.default_configuration = RuboCop::ConfigLoader.merge_with_default(
9
+ RuboCop::ConfigLoader.load_file(CONFIG_DEFAULT),
10
+ CONFIG_DEFAULT
11
+ )
12
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gl_rubocop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Give Lively
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.62.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.62.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-magic_numbers
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-performance
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.25'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.25'
97
+ description:
98
+ email:
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ files:
104
+ - LICENSE
105
+ - README.md
106
+ - gl_rubocop.gemspec
107
+ - lib/gl_rubocop.rb
108
+ - lib/gl_rubocop/gl_cops/callback_method_names.rb
109
+ - lib/gl_rubocop/gl_cops/interactor_inherits_from_interactor_base.rb
110
+ - lib/gl_rubocop/gl_cops/prevent_erb_files.rb
111
+ - lib/gl_rubocop/gl_cops/sidekiq_inherits_from_sidekiq_job.rb
112
+ - lib/gl_rubocop/version.rb
113
+ homepage: https://github.com/givelively/gl_rubocop
114
+ licenses:
115
+ - MIT
116
+ metadata:
117
+ rubygems_mfa_required: 'true'
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '3.1'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.3.27
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: A shareable configuration of Give Lively's rubocop rules.
137
+ test_files: []