From 275fcabb8684330afd6adae0605972481ab462c5 Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Sat, 28 Mar 2015 12:13:22 -0700 Subject: [PATCH] Clean up AltText linter There were a few Rubocop warnings to be fixed. Change-Id: I1db6543a3b6149e44902360b72a9ccf1a5db6066 Reviewed-on: http://gerrit.causes.com/48347 Tested-by: jenkins Reviewed-by: Shane da Silva --- CHANGELOG.md | 1 + lib/haml_lint/linter/alt_text.rb | 3 ++- lib/haml_lint/tree/tag_node.rb | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c85b0bfc..4adee053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ containing `if`/`else` blocks containing only HAML filters * Add `MultilineScript` linter to report scripts with trailing operators that should be merged with the following line +* Add `AltText` linter to report missing `alt` attributes on `img` tags ## 0.11.0 diff --git a/lib/haml_lint/linter/alt_text.rb b/lib/haml_lint/linter/alt_text.rb index ce479c2b..814a5425 100644 --- a/lib/haml_lint/linter/alt_text.rb +++ b/lib/haml_lint/linter/alt_text.rb @@ -1,10 +1,11 @@ module HamlLint + # Checks for missing `alt` attributes on `img` tags. class Linter::AltText < Linter include LinterRegistry def visit_tag(node) if node.tag_name == 'img' && !node.has_hash_attribute?(:alt) - add_lint(node, "`img` tags must include alt text.") + add_lint(node, '`img` tags must include alt text') end end end diff --git a/lib/haml_lint/tree/tag_node.rb b/lib/haml_lint/tree/tag_node.rb index 1d010a87..a1ba025a 100644 --- a/lib/haml_lint/tree/tag_node.rb +++ b/lib/haml_lint/tree/tag_node.rb @@ -20,8 +20,7 @@ def contains_script? @value[:parse] && !@value[:value].strip.empty? end - # Returns whether this tag has a specified attribute - # `=`). + # Returns whether this tag has a specified attribute. # # @return [true,false] def has_hash_attribute?(attribute)