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 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5b274a0
Update Caseflow-Commons for Zeitwerk
AKeyframe Sep 15, 2024
4a66c1d
Remove classic loading, added Zeitwerk loading options
AKeyframe Sep 15, 2024
6918c9c
Added to_prepare's - Solves DW on autoloading initialized constants
AKeyframe Sep 15, 2024
6d481bf
Added Zeitwerk initializer file
AKeyframe Sep 15, 2024
9ffdb8b
Refactored bgs_errors.rb and bgs.rb
AKeyframe Sep 15, 2024
dbcc1ad
Remove require statements
AKeyframe Sep 15, 2024
87b603f
Added Fakes and TestAuthStrategy modules
AKeyframe Sep 15, 2024
9308c95
Readded accidental require deletion
AKeyframe Sep 15, 2024
9a6dac6
Removed plural from CurrentUserLoadTests
AKeyframe Sep 15, 2024
2167642
Refactored for One File One Constant
AKeyframe Sep 15, 2024
ed055b0
Added Zeitwerk Rspec test
AKeyframe Sep 15, 2024
b0d4858
Fix Rubocop setup - removed incorrect include setup
AKeyframe Sep 16, 2024
9d67b0d
Added custom Rubocop - Top Level Constatns Per File
AKeyframe Sep 16, 2024
ca196eb
Rename and moved Zeitwerk spec for Caseflow parity
AKeyframe Sep 16, 2024
75e874e
Fixed custom cop spec file structure
AKeyframe Sep 17, 2024
e11055a
Zeitwerk spec comments addressed
AKeyframe Sep 17, 2024
121b98e
Refactored for Caseflow parity
AKeyframe Sep 17, 2024
2004005
Renamed for consistency
AKeyframe Sep 17, 2024
6f7007d
Safety require
AKeyframe Sep 17, 2024
59c882b
Safety require and to_prepare for BGS
AKeyframe Sep 17, 2024
7b43bc1
Added autoload/eagerload section
AKeyframe Sep 17, 2024
9436ce1
Renamed for consistency
AKeyframe Sep 18, 2024
40caf03
Readded require so to_prepare could be removed
AKeyframe Sep 18, 2024
0a00c22
Added rubocop_todo for temp ignore linter errors
AKeyframe Oct 4, 2024
a9fbcb9
Required changes for .rubocop.yml to work
AKeyframe Oct 4, 2024
5feee96
Updated Rubocop todo with proper generation
AKeyframe Oct 5, 2024
f14a717
Unecessary ShellCommand removed
AKeyframe Oct 5, 2024
21b4bfa
Ignored TestAuthStrategy in autoloading - unneeded
AKeyframe Oct 5, 2024
40fbaec
Update .rubocop.yml
AKeyframe Oct 9, 2024
9647152
Update app/services/external_api/vbms_service.rb
AKeyframe Oct 9, 2024
fb22488
Add #{root} to config/application.rb
AKeyframe Oct 9, 2024
b6bdf9e
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
fb974e2
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
db93fa2
Cosmetic Update config/initializers/shoryuken.rb
AKeyframe Oct 9, 2024
1d9bd66
Cosmetic Update lib/fakes/test_auth_strategy.rb
AKeyframe Oct 9, 2024
f2f2d37
Added after_initialize to prevent multiple subscribers on relead
AKeyframe Oct 9, 2024
8847fb9
Added before_initialize so Error class is loaded before anything else
AKeyframe Oct 9, 2024
6f3d9c8
✏️ Fix typo in filename
jcroteau Oct 9, 2024
2593d26
🚚 Move spec file to proper location
jcroteau Oct 9, 2024
a7fe2f7
♻️ Lexically order filters in .simplecov
jcroteau Oct 15, 2024
816a735
🔧 Filter `lib/efolder/migration.rb` from simplecov coverage
jcroteau Oct 15, 2024
9f06bce
⬆️ Update `caseflow-commons` dependecy
jcroteau Oct 31, 2024
665bfc1
Testing git remote access
AKeyframe Dec 3, 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