-
Notifications
You must be signed in to change notification settings - Fork 161
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 #78 from github/render_local_literal_keys
Enforce local keys being literals
- Loading branch information
Showing
5 changed files
with
223 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
# | ||
require "rubocop" | ||
|
||
module RuboCop | ||
module Cop | ||
module GitHub | ||
module RenderLiteralHelpers | ||
extend NodePattern::Macros | ||
|
||
def_node_matcher :literal?, <<-PATTERN | ||
({str sym true false nil?} ...) | ||
PATTERN | ||
|
||
def_node_matcher :render?, <<-PATTERN | ||
(send nil? {:render :render_to_string} ...) | ||
PATTERN | ||
|
||
def_node_matcher :render_literal?, <<-PATTERN | ||
(send nil? {:render :render_to_string} ({str sym} $_) $...) | ||
PATTERN | ||
|
||
def_node_matcher :render_inst?, <<-PATTERN | ||
(send nil? {:render :render_to_string} (send _ :new ...) ...) | ||
PATTERN | ||
|
||
def_node_matcher :render_with_options?, <<-PATTERN | ||
(send nil? {:render :render_to_string} (hash $...) ...) | ||
PATTERN | ||
|
||
def_node_matcher :render_view_component_instance?, <<-PATTERN | ||
(send nil? {:render :render_to_string} (send _ :new ...) ...) | ||
PATTERN | ||
|
||
def_node_matcher :render_view_component_collection?, <<-PATTERN | ||
(send nil? {:render :render_to_string} (send _ :with_collection ...) ...) | ||
PATTERN | ||
|
||
def_node_matcher :locals_key?, <<-PATTERN | ||
(pair (sym :locals) $_) | ||
PATTERN | ||
|
||
def hash_with_literal_keys?(hash) | ||
hash.pairs.all? { |pair| literal?(pair.key) } | ||
end | ||
|
||
def render_view_component?(node) | ||
render_view_component_instance?(node) || | ||
render_view_component_collection?(node) | ||
end | ||
end | ||
end | ||
end | ||
end |
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