-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from Shopify/uk-refine-mutable-constant
Refine `Style/MutableConstant` to process `T.let` expressions.
- Loading branch information
Showing
4 changed files
with
665 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
lib/rubocop/cop/sorbet/mutable_constant_sorbet_aware_behaviour.rb
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rubocop/cop/style/mutable_constant" | ||
|
||
module RuboCop | ||
module Cop | ||
module Sorbet | ||
module MutableConstantSorbetAwareBehaviour | ||
def self.prepended(base) | ||
base.def_node_matcher(:t_let, <<~PATTERN) | ||
(send (const nil? :T) :let $_constant _type) | ||
PATTERN | ||
end | ||
|
||
def on_assignment(value) | ||
t_let(value) do |constant| | ||
value = constant | ||
end | ||
|
||
super(value) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
RuboCop::Cop::Style::MutableConstant.prepend( | ||
RuboCop::Cop::Sorbet::MutableConstantSorbetAwareBehaviour | ||
) |
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
Oops, something went wrong.