erb_lint 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/erb_lint/linters/strict_locals.rb +50 -0
- data/lib/erb_lint/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0eabdfa71b2841fc684663a79233451981e21fcffb175c3ae7a1e0bd8afdc8e4
|
4
|
+
data.tar.gz: c609b033d3354e27c938ef1972b1ac16c654b1900115bb4f6d6595c384d1cfb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3686f39426c32119e8a725b8320143b31c48f98969bb6f0135827c5ff7c260d5674cfad5190c2bc75111fd5a76d881e47d7aa18b6b48f3f903f698719601623
|
7
|
+
data.tar.gz: 727473a64473dad0adb3912bc7f7b7e5c84d51c60374f72e93f380d378635848a240e8f1f3f16ec8f88874290e5e16821e8445b882c09cec4c78081db9eb2bda
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ERBLint
|
4
|
+
module Linters
|
5
|
+
# Enforces the use of strict locals in Rails view partial templates.
|
6
|
+
class StrictLocals < Linter
|
7
|
+
include LinterRegistry
|
8
|
+
|
9
|
+
STRICT_LOCALS_REGEX = /\s+locals:\s+\((.*)\)/
|
10
|
+
|
11
|
+
def initialize(file_loader, config)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(processed_source)
|
16
|
+
return unless processed_source.filename.match?(%r{(\A|.*/)_[^/\s]*\.html\.erb\z})
|
17
|
+
|
18
|
+
file_content = processed_source.file_content
|
19
|
+
return if file_content.empty?
|
20
|
+
|
21
|
+
strict_locals_node = processed_source.ast.descendants(:erb).find do |erb_node|
|
22
|
+
indicator_node, _, code_node, _ = *erb_node
|
23
|
+
|
24
|
+
indicator_node_str = indicator_node&.deconstruct&.last
|
25
|
+
next unless indicator_node_str == "#"
|
26
|
+
|
27
|
+
code_node_str = code_node&.deconstruct&.last
|
28
|
+
|
29
|
+
code_node_str.match(STRICT_LOCALS_REGEX)
|
30
|
+
end
|
31
|
+
|
32
|
+
unless strict_locals_node
|
33
|
+
add_offense(
|
34
|
+
processed_source.to_source_range(0...processed_source.file_content.size),
|
35
|
+
<<~EOF.chomp,
|
36
|
+
Missing strict locals declaration.
|
37
|
+
Add <%# locals: () %> at the top of the file to enforce strict locals.
|
38
|
+
EOF
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def autocorrect(_processed_source, offense)
|
44
|
+
lambda do |corrector|
|
45
|
+
corrector.insert_before(offense.source_range, "<%# locals: () %>\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/erb_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erb_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Chan
|
8
8
|
- Shopify Developers
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/erb_lint/linters/space_around_erb_tag.rb
|
179
179
|
- lib/erb_lint/linters/space_in_html_tag.rb
|
180
180
|
- lib/erb_lint/linters/space_indentation.rb
|
181
|
+
- lib/erb_lint/linters/strict_locals.rb
|
181
182
|
- lib/erb_lint/linters/trailing_whitespace.rb
|
182
183
|
- lib/erb_lint/offense.rb
|
183
184
|
- lib/erb_lint/processed_source.rb
|