immosquare-cleaner 0.1.108 → 0.1.109

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a413bdb4ca65fd168c69d440ecc430e69fb4906557bb608b78de5012c15b163
4
- data.tar.gz: d51d4e83187b0822638b8b682ce7153d853adffe955e805f7374f3d5b6fb9772
3
+ metadata.gz: fd38a7439f9f3972620d9b1bd626dbdda59ea57c4b44b4c3358fae765d4ee25a
4
+ data.tar.gz: 13127c3a36e4b00c3b29de218df8f0c974f82b056f1c5ad2846cea09d69a610c
5
5
  SHA512:
6
- metadata.gz: 1603c7f8f815bbdc32a518dbf6b6edb6dfe69d93e4540091bba8391591530aa6ac0849fef18d83d842c2b784740bc53833b3d69a9d295c2a078b6f179eb2a38d
7
- data.tar.gz: 383fc4bf784457aaae1530a9aeb63654bc35218ad121f48feff13560ce8720e286a135b30ce5bdda36e86e71c7430452c07e9cbc5a89e2b7f906e9722c670546
6
+ metadata.gz: 3a27177e3c628cc6db2ad30fb6225111cd54e4dae8d0da0a94abec69bab21cd68fe99dc2357b0f15b3c7decd7648d719d0ed24f87b8960f78fef3147d885965b
7
+ data.tar.gz: 7f89548fc37bc0801b9609114ddfd752e59cbeab3ee35f12fb416ed32857cc5e87c8b506666631887112cca3aa8a9873a8547c938a68200ac55d3922a88e3793
@@ -6,15 +6,30 @@ module ImmosquareCleaner
6
6
  module Processors
7
7
  class Javascript < Base
8
8
 
9
- EXTENSIONS = [
9
+ ##============================================================##
10
+ ## ERB templates whose host language is JS/TS (not HTML).
11
+ ## erb_lint's HTML-context linters must not run on these —
12
+ ## they would corrupt HTML literals embedded inside JS string
13
+ ## literals. Routed to the JS-specific erb_lint config.
14
+ ##============================================================##
15
+ JS_ERB_EXTENSIONS = [
16
+ ".js.erb",
17
+ ".jsx.erb",
18
+ ".ts.erb",
19
+ ".tsx.erb",
20
+ ".mjs.erb",
21
+ ".cjs.erb",
22
+ ".coffee.erb"
23
+ ].freeze
24
+
25
+ EXTENSIONS = ([
10
26
  ".js",
11
27
  ".mjs",
28
+ ".cjs",
12
29
  ".jsx",
13
30
  ".ts",
14
- ".tsx",
15
- "js.erb",
16
- ".ts.erb"
17
- ].freeze
31
+ ".tsx"
32
+ ] + JS_ERB_EXTENSIONS).freeze
18
33
 
19
34
  def self.match?(file_path)
20
35
  file_path.end_with?(*EXTENSIONS)
@@ -50,7 +65,12 @@ module ImmosquareCleaner
50
65
  ## copy was taken before erb_lint ran).
51
66
  ##============================================================##
52
67
  if file_path.end_with?(".erb")
53
- erblint_config = "#{ImmosquareCleaner.gem_root}/linters/erb-lint-#{RUBY_VERSION}.yml"
68
+ ##============================================================##
69
+ ## JS/TS templates use the JS-specific erb_lint config to keep
70
+ ## HTML-context linters off the host string literals.
71
+ ##============================================================##
72
+ config_basename = file_path.downcase.end_with?(*JS_ERB_EXTENSIONS) ? "js-erb-lint" : "erb-lint"
73
+ erblint_config = "#{ImmosquareCleaner.gem_root}/linters/#{config_basename}-#{RUBY_VERSION}.yml"
54
74
  erblint_options = ImmosquareCleaner.configuration.erblint_options || "--autocorrect"
55
75
  cmds << "bundle exec erb_lint --config #{erblint_config} #{escaped_temp} #{erblint_options}"
56
76
  else
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.108".freeze
2
+ VERSION = "0.1.109".freeze
3
3
  end
@@ -124,7 +124,6 @@ module ImmosquareCleaner
124
124
  def setup_linter_configs!
125
125
  @setup_linter_configs ||= begin
126
126
  rubocop_config_with_version_path = "#{gem_root}/linters/rubocop-#{RUBY_VERSION}.yml"
127
- erblint_config_with_version_path = "#{gem_root}/linters/erb-lint-#{RUBY_VERSION}.yml"
128
127
 
129
128
  if !File.exist?(rubocop_config_with_version_path)
130
129
  rubocop_config = YAML.load_file("#{gem_root}/linters/rubocop.yml")
@@ -133,11 +132,20 @@ module ImmosquareCleaner
133
132
  File.write(rubocop_config_with_version_path, rubocop_config.to_yaml)
134
133
  end
135
134
 
136
- if !File.exist?(erblint_config_with_version_path)
137
- erblint_config = YAML.load_file("#{gem_root}/linters/erb-lint.yml")
138
- erblint_config["linters"]["Rubocop"]["rubocop_config"]["inherit_from"] = ["linters/rubocop-#{RUBY_VERSION}.yml"]
139
- File.write(erblint_config_with_version_path, erblint_config.to_yaml)
135
+ ##============================================================##
136
+ ## erb_lint configs that inherit the versioned rubocop config.
137
+ ## - erb-lint : default config for .html.erb
138
+ ## - js-erb-lint : JS-specific config for .js.erb / .ts.erb / etc.
139
+ ##============================================================##
140
+ ["erb-lint", "js-erb-lint"].each do |basename|
141
+ versioned_path = "#{gem_root}/linters/#{basename}-#{RUBY_VERSION}.yml"
142
+ next if File.exist?(versioned_path)
143
+
144
+ config = YAML.load_file("#{gem_root}/linters/#{basename}.yml")
145
+ config["linters"]["Rubocop"]["rubocop_config"]["inherit_from"] = ["linters/rubocop-#{RUBY_VERSION}.yml"]
146
+ File.write(versioned_path, config.to_yaml)
140
147
  end
148
+
141
149
  true
142
150
  end
143
151
  end
@@ -131,7 +131,28 @@ module ERBLint
131
131
  "full_error"
132
132
  ].freeze
133
133
 
134
+ ##============================================================##
135
+ ## File extensions that hold JS/TS source with embedded ERB.
136
+ ## Inside these files HTML literals live inside JS string
137
+ ## contexts ("..."/'...'/`...`). Promoting them to content_tag
138
+ ## breaks the surrounding string two ways: the helper's output
139
+ ## attributes are always double-quoted and would terminate a
140
+ ## double-quoted JS literal early, and any `j()` JS-escape
141
+ ## around the ERB output would no longer wrap the full HTML.
142
+ ##============================================================##
143
+ JS_TEMPLATE_EXTENSIONS = [
144
+ ".js.erb",
145
+ ".jsx.erb",
146
+ ".ts.erb",
147
+ ".tsx.erb",
148
+ ".mjs.erb",
149
+ ".cjs.erb",
150
+ ".coffee.erb"
151
+ ].freeze
152
+
134
153
  def run(processed_source)
154
+ return if javascript_template?(processed_source.filename)
155
+
135
156
  document = processed_source.ast
136
157
  children = document.children.to_a
137
158
 
@@ -195,6 +216,13 @@ module ERBLint
195
216
 
196
217
  private
197
218
 
219
+ def javascript_template?(filename)
220
+ return false if filename.nil?
221
+
222
+ downcased = filename.downcase
223
+ JS_TEMPLATE_EXTENSIONS.any? {|ext| downcased.end_with?(ext) }
224
+ end
225
+
198
226
  ##============================================================##
199
227
  ## Check if tag is a closing tag (has solidus as first child)
200
228
  ##============================================================##
@@ -0,0 +1,26 @@
1
+ ---
2
+ EnableDefaultLinters: true
3
+ linters:
4
+ NoJavascriptTagHelper:
5
+ enabled: false
6
+ SpaceInHtmlTag:
7
+ enabled: false
8
+ SelfClosingTag:
9
+ enabled: false
10
+ RequireInputAutocomplete:
11
+ enabled: false
12
+ DeprecatedClassesInline:
13
+ enabled: false
14
+ HardCodedString:
15
+ enabled: false
16
+ CustomHtmlToContentTag:
17
+ enabled: false
18
+ CustomSingleLineIfModifier:
19
+ enabled: true
20
+ Rubocop:
21
+ enabled: true
22
+ rubocop_config:
23
+ inherit_from:
24
+ - linters/rubocop-4.0.3.yml
25
+ Layout/TrailingWhitespace:
26
+ Enabled: false
@@ -0,0 +1,56 @@
1
+ ##============================================================##
2
+ ## erb_lint config for JS/TS templates (.js.erb, .ts.erb,
3
+ ## .jsx.erb, .tsx.erb, .mjs.erb, .cjs.erb, .coffee.erb).
4
+ ##
5
+ ## In these files HTML literals live inside JS string contexts
6
+ ## ("..."/'...'/`...`). erb_lint's default linters and our custom
7
+ ## ones assume HTML-document context and rewrite that HTML in
8
+ ## ways that corrupt the surrounding JS string (quote balance,
9
+ ## tag self-closing, content_tag promotion, etc.). This config
10
+ ## disables every HTML-context linter and keeps only:
11
+ ## - Rubocop (lints Ruby code inside <% %>/<%= %>)
12
+ ## - CustomSingleLineIfModifier (ERB structural, JS-safe)
13
+ ## - ParserErrors / formatting linters that operate on ERB
14
+ ## tokens, not HTML semantics
15
+ ##============================================================##
16
+ EnableDefaultLinters: true
17
+ linters:
18
+ ##============================================================##
19
+ ## HTML-context default linters — disabled for JS templates.
20
+ ##============================================================##
21
+ NoJavascriptTagHelper:
22
+ enabled: false
23
+ SpaceInHtmlTag:
24
+ enabled: false
25
+ SelfClosingTag:
26
+ enabled: false # Would rewrite `<br/>` -> `<br>` inside a JS string literal
27
+ RequireInputAutocomplete:
28
+ enabled: false # Flags `<input>` literals inside JS strings as missing autocomplete
29
+ DeprecatedClassesInline:
30
+ enabled: false # Inspects HTML class attributes — false positives in JS templates
31
+ HardCodedString:
32
+ enabled: false # i18n check — irrelevant for JS code (the JS lines themselves are not user-facing strings)
33
+
34
+ ##============================================================##
35
+ ## Custom HTML-context linters — disabled for JS templates.
36
+ ##============================================================##
37
+ CustomHtmlToContentTag:
38
+ enabled: false # Would promote HTML literals to content_tag(...) — breaks the host JS string
39
+
40
+ ##============================================================##
41
+ ## ERB-structural linters — safe in any context.
42
+ ##============================================================##
43
+ CustomSingleLineIfModifier:
44
+ enabled: true
45
+
46
+ ##============================================================##
47
+ ## Ruby code inside <% %>/<%= %> is linted by Rubocop with
48
+ ## the same config as .html.erb.
49
+ ##============================================================##
50
+ Rubocop:
51
+ enabled: true
52
+ rubocop_config:
53
+ inherit_from:
54
+ - linters/rubocop.yml
55
+ Layout/TrailingWhitespace:
56
+ Enabled: false
@@ -20,6 +20,8 @@ Lint/RescueException:
20
20
  Enabled: false
21
21
  Lint/UnusedMethodArgument:
22
22
  Enabled: false
23
+ Lint/UselessOr:
24
+ Enabled: false
23
25
  Naming/VariableNumber:
24
26
  Enabled: false
25
27
  Naming/FileName:
@@ -96,6 +98,8 @@ Style/SymbolArray:
96
98
  EnforcedStyle: brackets
97
99
  Style/RescueModifier:
98
100
  Enabled: false
101
+ Style/NestedParenthesizedCalls:
102
+ Enabled: false
99
103
  Style/MethodCallWithArgsParentheses:
100
104
  Enabled: true
101
105
  EnforcedStyle: require_parentheses
data/linters/rubocop.yml CHANGED
@@ -23,6 +23,8 @@ Lint/RescueException:
23
23
  Enabled: false # Allow `rescue Exception => e` without forcing StandardError
24
24
  Lint/UnusedMethodArgument:
25
25
  Enabled: false # Allow defining methods with unused parameters (otherwise the cop renames the param with a leading _ on save while still writing the method)
26
+ Lint/UselessOr:
27
+ Enabled: false # The cop strips defensive `expr || :default` fallbacks (e.g. `foo.to_sym || :default`) when the LHS technically can't return nil. Ruby raises rather than returning nil there, so the `||` is dead by the cop's logic — but the dev wrote it as a guard against the LHS itself being nil. erb_lint also bypasses `SafeAutoCorrect: false` so the strip happens silently on save. Keep the guard.
26
28
 
27
29
  #################### Naming ###########################
28
30
  Naming/VariableNumber:
@@ -106,6 +108,8 @@ Style/SymbolArray:
106
108
  EnforcedStyle: brackets # Format arrays as [:a, :b, :c], not %i[a b c]
107
109
  Style/RescueModifier:
108
110
  Enabled: false # Allow inline rescue modifier (some_method rescue SomeException)
111
+ Style/NestedParenthesizedCalls:
112
+ Enabled: false # Redundant with Style/MethodCallWithArgsParentheses (require_parentheses) — both flag `outer(inner arg)`. RuboCop dedupes the inserted `(` but not the matching `)`, and erb_lint's integration ships both corrections independently → output gets an extra `)` (e.g. `j(render :partial => "x")` becomes `j(render(:partial => "x")))`, breaking the ERB at render time).
109
113
 
110
114
  #################### OVERWRITE ###########################
111
115
  Style/MethodCallWithArgsParentheses:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.108
4
+ version: 0.1.109
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
@@ -182,6 +182,8 @@ files:
182
182
  - linters/erb_lint/custom_single_line_if_modifier.rb
183
183
  - linters/eslint-plugins/eslint10-compat.mjs
184
184
  - linters/eslint.config.mjs
185
+ - linters/js-erb-lint-4.0.3.yml
186
+ - linters/js-erb-lint.yml
185
187
  - linters/normalize-comments.mjs
186
188
  - linters/prettier.yml
187
189
  - linters/rubocop-4.0.3.yml