-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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 #18367 from Homebrew/skip-sorbet-assignments
Exclude sorbet assignments from Style/MutableConstant cop
- Loading branch information
Showing
12 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
45 changes: 45 additions & 0 deletions
45
Library/Homebrew/rubocops/extend/mutable_constant_exclude_unfreezable.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,45 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require "rubocop/cop/style/mutable_constant" | ||
|
||
module RuboCop | ||
module Cop | ||
module Sorbet | ||
# TODO: delete this file when https://github.com/Shopify/rubocop-sorbet/pull/256 is available | ||
module MutableConstantExcludeUnfreezable | ||
class << self | ||
sig { params(base: RuboCop::AST::NodePattern::Macros).void } | ||
def prepended(base) | ||
base.def_node_matcher(:t_let, <<~PATTERN) | ||
(send (const nil? :T) :let $_constant _type) | ||
PATTERN | ||
|
||
base.def_node_matcher(:t_type_alias?, <<~PATTERN) | ||
(block (send (const {nil? cbase} :T) :type_alias ...) ...) | ||
PATTERN | ||
|
||
base.def_node_matcher(:type_member?, <<~PATTERN) | ||
(block (send nil? :type_member ...) ...) | ||
PATTERN | ||
end | ||
end | ||
|
||
sig { params(value: RuboCop::AST::Node).void } | ||
def on_assignment(value) | ||
T.unsafe(self).t_let(value) do |constant| | ||
value = T.let(constant, RuboCop::AST::Node) | ||
end | ||
return if T.unsafe(self).t_type_alias?(value) | ||
return if T.unsafe(self).type_member?(value) | ||
|
||
super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
RuboCop::Cop::Style::MutableConstant.prepend( | ||
RuboCop::Cop::Sorbet::MutableConstantExcludeUnfreezable, | ||
) |
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
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
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