forked from sds/haml-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter that checks for the use of HTML-style attributes. Change-Id: Ibbd8461c5c857cafc2d04ee1b977f7cbd8f05971 Reviewed-on: http://gerrit.causes.com/42567 Tested-by: jenkins <[email protected]> Reviewed-by: Shane da Silva <[email protected]>
- Loading branch information
Showing
7 changed files
with
73 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ linters: | |
EmptyScript: | ||
enabled: true | ||
|
||
HtmlAttributes: | ||
enabled: true | ||
|
||
ImplicitDiv: | ||
enabled: true | ||
|
||
|
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,14 @@ | ||
module HamlLint | ||
# Checks for the setting of attributes via HTML shorthand syntax on elements | ||
# (e.g. `%tag(lang=en)`). | ||
class Linter::HtmlAttributes < Linter | ||
include LinterRegistry | ||
|
||
def visit_tag(node) | ||
return unless node.html_attributes? | ||
|
||
add_lint(node, "Prefer the hash attributes syntax (%tag{ lang: 'en' }) over " \ | ||
'HTML attributes syntax (%tag(lang=en))') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
describe HamlLint::Linter::HtmlAttributes do | ||
include_context 'linter' | ||
|
||
context 'when a tag has no attributes' do | ||
let(:haml) { '%tag' } | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when a tag contains hash attributes' do | ||
let(:haml) { "%tag{ lang: 'en' }" } | ||
|
||
it { should_not report_lint } | ||
end | ||
|
||
context 'when a tag contains HTML attributes' do | ||
let(:haml) { '%tag(lang=en)' } | ||
|
||
it { should report_lint } | ||
end | ||
|
||
context 'when a tag contains HTML attributes and hash attributes' do | ||
let(:haml) { '%tag(lang=en){ attr: value }' } | ||
|
||
it { should report_lint } | ||
end | ||
end |