-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
inherit_from: .rubocop_todo.yml | ||
require: | ||
- rubocop-rails | ||
- ./lib/rubocop/init_autoloader | ||
|
||
AllCops: | ||
TargetRubyVersion: 3.3.0 | ||
Exclude: | ||
- "spec/**/*.rb" | ||
- "db/**/*" | ||
- "config/**/*" | ||
- "bin/**/*" | ||
################### | ||
# Custom Cops # | ||
################### | ||
Custom/PrivateMethodStyle: | ||
Enabled: true | ||
################### | ||
# End Custom Cops # | ||
################### | ||
Layout/IndentationWidth: | ||
Enabled: true | ||
Width: 2 | ||
Lint/UnusedMethodArgument: | ||
AutoCorrect: false | ||
Metrics/AbcSize: | ||
Exclude: | ||
- "lib/mixins/**/*" | ||
Metrics/CyclomaticComplexity: | ||
Exclude: | ||
- "lib/rubocop/cop/custom/*.rb" | ||
Metrics/MethodLength: | ||
Exclude: | ||
- "lib/rubocop/cop/custom/*.rb" | ||
- "lib/mixins/**/*" | ||
Metrics/PerceivedComplexity: | ||
Exclude: | ||
- "lib/rubocop/cop/custom/*.rb" | ||
Style/AccessModifierDeclarations: | ||
EnforcedStyle: inline | ||
Style/Documentation: | ||
Enabled: false | ||
Style/Lambda: | ||
EnforcedStyle: literal | ||
Style/RedundantArgument: | ||
AutoCorrect: false | ||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module ApplicationCable | ||
class Channel < ActionCable::Channel::Base | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationController < ActionController::API | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationRecord < ActiveRecord::Base | ||
primary_abstract_class | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
# typed: false | ||
|
||
require "rubocop" | ||
|
||
module RuboCop | ||
module Cop | ||
module Custom | ||
# This cop enforces that private methods are defined using | ||
# `private def` for instance methods or | ||
# `private_class_method def self` for class methods. | ||
class PrivateMethodStyle < Base | ||
MSG_INSTANCE = "Use `private def` for instance methods." | ||
MSG_CLASS = "Use `private_class_method def self` for class methods." | ||
|
||
def on_def(node) | ||
method_name = node.children[0]&.to_s | ||
|
||
return unless class_method_definition?(node) | ||
|
||
Rails.logger.debug "Checking method: #{method_name}" | ||
add_offense(node, message: MSG_CLASS) | ||
end | ||
|
||
private def class_method_definition?(node) | ||
node.defs_type? && node.children[0]&.to_s == "self.use_collection" | ||
end | ||
|
||
private def instance_method?(node) | ||
return false unless node.def_type? | ||
|
||
method_name, _args, _body = *node | ||
method_name.to_s.start_with?("def") && !node.singleton_method? | ||
end | ||
|
||
private def class_method?(node) | ||
return false unless node.defs_type? | ||
|
||
_scope, method_name, _args, _body = *node | ||
method_name.to_s.start_with?("self.") && !node.arguments? && !node.singleton_method? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
# Load all Ruby files in the custom directory | ||
Dir[File.join(__dir__, "**/*.rb")].each { |file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubocop/rake_task" | ||
|
||
RuboCop::RakeTask.new do |task| | ||
task.requires << "rubocop-rails" | ||
end |