Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AlecK/APPEALS-44512 - Zeitwerk Autoloader Transition #1700

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
318f3f8
Update Caseflow-Commons for Zeitwerk
AKeyframe Sep 15, 2024
e5e9f77
Remove classic loading, added Zeitwerk loading options
AKeyframe Sep 15, 2024
338296c
Added to_prepare's - Solves DW on autoloading initialized constants
AKeyframe Sep 15, 2024
8b528de
Added Zeitwerk initializer file
AKeyframe Sep 15, 2024
c5ec70a
Refactored bgs_errors.rb and bgs.rb
AKeyframe Sep 15, 2024
6f0bc3b
Remove require statements
AKeyframe Sep 15, 2024
ee67171
Added Fakes and TestAuthStrategy modules
AKeyframe Sep 15, 2024
55fec76
Readded accidental require deletion
AKeyframe Sep 15, 2024
88bd620
Removed plural from CurrentUserLoadTests
AKeyframe Sep 15, 2024
1dbf945
Refactored for One File One Constant
AKeyframe Sep 15, 2024
0d0ef99
Added Zeitwerk Rspec test
AKeyframe Sep 15, 2024
f6a6f04
Fix Rubocop setup - removed incorrect include setup
AKeyframe Sep 16, 2024
1f30a5b
Added custom Rubocop - Top Level Constatns Per File
AKeyframe Sep 16, 2024
8a77e40
Rename and moved Zeitwerk spec for Caseflow parity
AKeyframe Sep 16, 2024
9aad07d
Fixed custom cop spec file structure
AKeyframe Sep 17, 2024
e27397e
Zeitwerk spec comments addressed
AKeyframe Sep 17, 2024
2249193
Refactored for Caseflow parity
AKeyframe Sep 17, 2024
340f746
Renamed for consistency
AKeyframe Sep 17, 2024
2bb3570
Safety require
AKeyframe Sep 17, 2024
f9af83d
Safety require and to_prepare for BGS
AKeyframe Sep 17, 2024
199919a
Added autoload/eagerload section
AKeyframe Sep 17, 2024
221a60b
Renamed for consistency
AKeyframe Sep 18, 2024
c40d33c
Readded require so to_prepare could be removed
AKeyframe Sep 18, 2024
1aa5282
Added rubocop_todo for temp ignore linter errors
AKeyframe Oct 4, 2024
2d73add
Required changes for .rubocop.yml to work
AKeyframe Oct 4, 2024
8dd5c92
Updated Rubocop todo with proper generation
AKeyframe Oct 5, 2024
c78dd40
Unecessary ShellCommand removed
AKeyframe Oct 5, 2024
1d5360d
Ignored TestAuthStrategy in autoloading - unneeded
AKeyframe Oct 5, 2024
3041562
Update .rubocop.yml
AKeyframe Oct 9, 2024
0a50198
Update app/services/external_api/vbms_service.rb
AKeyframe Oct 9, 2024
bb0e5d7
Add #{root} to config/application.rb
AKeyframe Oct 9, 2024
d59cc58
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
b9a5fcf
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
44812fe
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
0c24397
Cosmetic Update lib/fakes/test_auth_strategy.rb
AKeyframe Oct 9, 2024
24edae5
Added after_initialize to prevent multiple subscribers on relead
AKeyframe Oct 9, 2024
26af539
Added before_initialize so Error class is loaded before anything else
AKeyframe Oct 9, 2024
bcae1a0
✏️ Fix typo in filename
jcroteau Oct 9, 2024
7ea79db
🚚 Move spec file to proper location
jcroteau Oct 9, 2024
b27bdd7
♻️ Lexically order filters in .simplecov
jcroteau Oct 15, 2024
4749ca7
🔧 Filter `lib/efolder/migration.rb` from simplecov coverage
jcroteau Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading