Skip to content

Commit

Permalink
Feature/APPEALS-44512-Zeitwerk-auto-transition (#1738) (#1739)
Browse files Browse the repository at this point in the history
* Update Caseflow-Commons for Zeitwerk

* Remove classic loading, added Zeitwerk loading options

* Added to_prepare's - Solves DW on autoloading initialized constants

* Added Zeitwerk initializer file

* Refactored bgs_errors.rb and bgs.rb

* Remove require statements

* Added Fakes and TestAuthStrategy modules

* Readded accidental require deletion

* Removed plural from CurrentUserLoadTests

* Refactored for One File One Constant

* Added Zeitwerk Rspec test

* Fix Rubocop setup - removed incorrect include setup

* Added custom Rubocop - Top Level Constatns Per File

* Rename and moved Zeitwerk spec for Caseflow parity

* Fixed custom cop spec file structure

* Zeitwerk spec comments addressed

* Refactored for Caseflow parity

* Renamed for consistency

* Safety require

* Safety require and to_prepare for BGS

* Added autoload/eagerload section

* Renamed for consistency

* Readded require so to_prepare could be removed

* Added rubocop_todo for temp ignore linter errors

* Required changes for .rubocop.yml to work

* Updated Rubocop todo with proper generation

* Unecessary ShellCommand removed

* Ignored TestAuthStrategy in autoloading - unneeded

* Update .rubocop.yml



* Update app/services/external_api/vbms_service.rb



* Add #{root} to config/application.rb



* Cosmetic Update config/initializers/shoryuken.rb



* Cosmetic Update config/initializers/shoryuken.rb



* Cosmetic Update config/initializers/shoryuken.rb



* Cosmetic Update lib/fakes/test_auth_strategy.rb



* Added after_initialize to prevent multiple subscribers on relead

* Added before_initialize so Error class is loaded before anything else

* ✏️ Fix typo in filename

* 🚚 Move spec file to proper location

* ♻️ Lexically order filters in .simplecov

* 🔧 Filter `lib/efolder/migration.rb` from simplecov coverage

* ⬆️ Update `caseflow-commons` dependecy

---------

Co-authored-by: AKeyframe <[email protected]>
Co-authored-by: Jeremy Croteau <[email protected]>
Co-authored-by: Jeremy Croteau <[email protected]>
  • Loading branch information
4 people authored Nov 14, 2024
1 parent c337074 commit f9a5b63
Show file tree
Hide file tree
Showing 28 changed files with 802 additions and 152 deletions.
17 changes: 13 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
inherit_from: .rubocop_todo.yml

require:
- .rubocop/custom_cop/top_level_constants_per_file.rb

AllCops:
TargetRubyVersion: 2.5
TargetRailsVersion: 5.1
Include:
- '**/config.ru'
- '**/Rakefile'
- '**/*.rake'
Exclude:
- 'bin/**/*'
- 'db/**/*'
Expand Down Expand Up @@ -62,3 +63,11 @@ Style/TrailingCommaInArrayLiteral:

Style/TrailingCommaInHashLiteral:
Enabled: false

CustomCop/TopLevelConstantsPerFile:
Enabled: true
Include:
- 'app/**/*'
- 'lib/**/*'
Exclude:
- '**/*[^.rb]' # exclude non-.rb files (ex: .rake files)
28 changes: 28 additions & 0 deletions .rubocop/custom_cop/top_level_constants_per_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module RuboCop
module CustomCop
class TopLevelConstantsPerFile < RuboCop::Cop::Cop
MSG = "Multiple top-level constants detected in one file. The autoloader expects one top-level constant per file."

def investigate(processed_source)
return unless processed_source

# If more than one top-level constant in the file, add offense on the second one
if top_level_constant_nodes.size > 1
add_offense(top_level_constant_nodes[1], message: MSG)
end
end

private

def top_level_constant_nodes
@top_level_constant_nodes ||=
processed_source.ast.each_node(:class, :module).select { |node| top_level_constant?(node) }
end

def top_level_constant?(node)
# node is not nested within a class or module node?
node.ancestors.none? { |ancestor| ancestor.class_type? || ancestor.module_type? }
end
end
end
end
Loading

0 comments on commit f9a5b63

Please sign in to comment.