From 97da46273c0897aa5d695be56a055c74fb7e6085 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 4 Jan 2025 21:49:26 +0100 Subject: [PATCH] Fix spec warnings (#650) * Fix unassigned variable warning Fix `warning: assigned but unused variable - comp` warning * Remove frozen string literals from `arb` templates It does not have effect there and outputs a warning when running tests with `RUBYOPTS='-w' rake` ``` warning: 'frozen_string_literal' is ignored after any tokens ``` Behavior tested in `empty.arb` template ``` # frozen_string_literal: true hello = 'hello' hello.concat ' world' ``` Expected: fail Actual: pass Close #649 * Enable some `Lint` cops to prevent warnings Parity with ActiveAdmin to prevent introduction of new warnings Manually fix a `Lint/UselessAssignment` warning Ref: activeadmin/activeadmin#8597 --- .rubocop.yml | 10 ++++++++++ spec/arbre/unit/component_spec.rb | 2 +- spec/rails/templates/arbre/_partial.arb | 1 - .../rails/templates/arbre/_partial_with_assignment.arb | 1 - .../arbre/page_with_arb_partial_and_assignment.arb | 1 - spec/rails/templates/arbre/page_with_assignment.arb | 1 - spec/rails/templates/arbre/page_with_erb_partial.arb | 1 - spec/rails/templates/arbre/page_with_partial.arb | 1 - .../templates/arbre/page_with_render_with_block.arb | 1 - spec/rails/templates/arbre/simple_page.arb | 1 - 10 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 4d0d4ddc..f2fcd2a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -86,6 +86,15 @@ Layout/TrailingWhitespace: Layout/TrailingEmptyLines: Enabled: true +Lint/AmbiguousOperator: + Enabled: true + +Lint/AmbiguousRegexpLiteral: + Enabled: true + +Lint/UselessAssignment: + Enabled: true + Packaging/BundlerSetupInTests: Enabled: true @@ -584,6 +593,7 @@ Style/FrozenStringLiteralComment: Enabled: true Exclude: - bin/console + - '**/*.arb' Style/HashSyntax: Enabled: true diff --git a/spec/arbre/unit/component_spec.rb b/spec/arbre/unit/component_spec.rb index 9019e504..19545cbf 100644 --- a/spec/arbre/unit/component_spec.rb +++ b/spec/arbre/unit/component_spec.rb @@ -30,7 +30,7 @@ def build end it "renders the object using the builder method name" do - comp = expect(arbre { + expect(arbre { mock_component }.to_s).to eq <<~HTML
diff --git a/spec/rails/templates/arbre/_partial.arb b/spec/rails/templates/arbre/_partial.arb index 26cbc2b1..3f46cbff 100644 --- a/spec/rails/templates/arbre/_partial.arb +++ b/spec/rails/templates/arbre/_partial.arb @@ -1,2 +1 @@ -# frozen_string_literal: true para "Hello from a partial" diff --git a/spec/rails/templates/arbre/_partial_with_assignment.arb b/spec/rails/templates/arbre/_partial_with_assignment.arb index 2ceeb022..95f003ae 100644 --- a/spec/rails/templates/arbre/_partial_with_assignment.arb +++ b/spec/rails/templates/arbre/_partial_with_assignment.arb @@ -1,2 +1 @@ -# frozen_string_literal: true para "Partial: #{my_instance_var}" diff --git a/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb b/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb index 18f26289..c44516d5 100644 --- a/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb +++ b/spec/rails/templates/arbre/page_with_arb_partial_and_assignment.arb @@ -1,4 +1,3 @@ -# frozen_string_literal: true h1 "Before Partial" render "arbre/partial_with_assignment" h2 "After Partial" diff --git a/spec/rails/templates/arbre/page_with_assignment.arb b/spec/rails/templates/arbre/page_with_assignment.arb index e3a0c411..c330d3b4 100644 --- a/spec/rails/templates/arbre/page_with_assignment.arb +++ b/spec/rails/templates/arbre/page_with_assignment.arb @@ -1,2 +1 @@ -# frozen_string_literal: true h1 my_instance_var diff --git a/spec/rails/templates/arbre/page_with_erb_partial.arb b/spec/rails/templates/arbre/page_with_erb_partial.arb index 14cd3447..8c47543b 100644 --- a/spec/rails/templates/arbre/page_with_erb_partial.arb +++ b/spec/rails/templates/arbre/page_with_erb_partial.arb @@ -1,4 +1,3 @@ -# frozen_string_literal: true h1 "Before Partial" render "erb/partial" h2 "After Partial" diff --git a/spec/rails/templates/arbre/page_with_partial.arb b/spec/rails/templates/arbre/page_with_partial.arb index 44142dee..6e766931 100644 --- a/spec/rails/templates/arbre/page_with_partial.arb +++ b/spec/rails/templates/arbre/page_with_partial.arb @@ -1,4 +1,3 @@ -# frozen_string_literal: true h1 "Before Partial" render "arbre/partial" h2 "After Partial" diff --git a/spec/rails/templates/arbre/page_with_render_with_block.arb b/spec/rails/templates/arbre/page_with_render_with_block.arb index e5c78e3c..a5c42150 100644 --- a/spec/rails/templates/arbre/page_with_render_with_block.arb +++ b/spec/rails/templates/arbre/page_with_render_with_block.arb @@ -1,4 +1,3 @@ -# frozen_string_literal: true render_in_object = Class.new do def render_in(_, &block) block.call diff --git a/spec/rails/templates/arbre/simple_page.arb b/spec/rails/templates/arbre/simple_page.arb index 9d4e2fe3..04d7557f 100644 --- a/spec/rails/templates/arbre/simple_page.arb +++ b/spec/rails/templates/arbre/simple_page.arb @@ -1,4 +1,3 @@ -# frozen_string_literal: true html do head do end