From bfc936016f9618c3a37a5b1bef71e86c2a85c984 Mon Sep 17 00:00:00 2001 From: Jerome Dalbert Date: Sat, 25 Jan 2025 11:24:48 -0800 Subject: [PATCH] Move mixins to obsession namespace to avoid conflicts --- lib/rubocop/cop/mixin/helpers.rb | 31 ----------------- .../cop/{ => obsession}/mixin/files/verbs.txt | 0 lib/rubocop/cop/obsession/mixin/helpers.rb | 33 +++++++++++++++++++ lib/rubocop/obsession.rb | 2 +- 4 files changed, 34 insertions(+), 32 deletions(-) delete mode 100644 lib/rubocop/cop/mixin/helpers.rb rename lib/rubocop/cop/{ => obsession}/mixin/files/verbs.txt (100%) create mode 100644 lib/rubocop/cop/obsession/mixin/helpers.rb diff --git a/lib/rubocop/cop/mixin/helpers.rb b/lib/rubocop/cop/mixin/helpers.rb deleted file mode 100644 index 58a6ae1..0000000 --- a/lib/rubocop/cop/mixin/helpers.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module Helpers - def rails_callback?(callback) - return true if callback == 'validate' - - callback.match?( - / - ^(before|after|around) - _.* - (action|validation|create|update|save|destroy|commit|rollback)$ - /x - ) - end - - def verb?(string) - short_string = string[2..] if string.start_with?('re') - - verbs.include?(string) || verbs.include?(short_string) - end - - private - - def verbs - @@verbs ||= File.read("#{__dir__}/files/verbs.txt").split - end - end - end -end diff --git a/lib/rubocop/cop/mixin/files/verbs.txt b/lib/rubocop/cop/obsession/mixin/files/verbs.txt similarity index 100% rename from lib/rubocop/cop/mixin/files/verbs.txt rename to lib/rubocop/cop/obsession/mixin/files/verbs.txt diff --git a/lib/rubocop/cop/obsession/mixin/helpers.rb b/lib/rubocop/cop/obsession/mixin/helpers.rb new file mode 100644 index 0000000..f07d6aa --- /dev/null +++ b/lib/rubocop/cop/obsession/mixin/helpers.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Obsession + module Helpers + def rails_callback?(callback) + return true if callback == 'validate' + + callback.match?( + / + ^(before|after|around) + _.* + (action|validation|create|update|save|destroy|commit|rollback)$ + /x + ) + end + + def verb?(string) + short_string = string[2..] if string.start_with?('re') + + verbs.include?(string) || verbs.include?(short_string) + end + + private + + def verbs + @@verbs ||= File.read("#{__dir__}/files/verbs.txt").split + end + end + end + end +end diff --git a/lib/rubocop/obsession.rb b/lib/rubocop/obsession.rb index 944227a..eca58db 100644 --- a/lib/rubocop/obsession.rb +++ b/lib/rubocop/obsession.rb @@ -3,7 +3,7 @@ require 'active_support/core_ext/string/inflections' require 'rubocop' -require_relative 'cop/mixin/helpers' +require_relative 'cop/obsession/mixin/helpers' Dir["#{__dir__}/cop/obsession/**/*.rb"].sort.each { |file| require file } require_relative 'obsession/version'