Skip to content

Commit

Permalink
Add HAMLLintBear
Browse files Browse the repository at this point in the history
Performs style and lint checks on HAML files

Closes coala#289
  • Loading branch information
IpshitaC committed Dec 14, 2017
1 parent 6d57629 commit c86a6d0
Show file tree
Hide file tree
Showing 16 changed files with 543 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'
ruby '2.2.2'

gem "csvlint", require: false
gem "haml_lint", "0.27.0", require: false
gem "puppet-lint", "2.1.1", require: false
gem "reek", require: false
gem "rubocop", "0.51.0", require: false
Expand Down
366 changes: 366 additions & 0 deletions bears/haml/HAMLLintBear.py

Large diffs are not rendered by default.

Empty file added bears/haml/__init__.py
Empty file.
133 changes: 133 additions & 0 deletions tests/haml/HAMLLintBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import os
from queue import Queue

from coalib.settings.Section import Section
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.testing.BearTestHelper import generate_skip_decorator

from bears.haml.HAMLLintBear import HAMLLintBear


def get_testfile_path(name):
return os.path.join(os.path.dirname(__file__),
'hamllint_test_files',
name)


def load_testfile(name):
with open(get_testfile_path(name)) as f:
return f.readlines()


@generate_skip_decorator(HAMLLintBear)
class HAMLLintBearTest(LocalBearTestHelper):

def setUp(self):
self.section = Section('name')
self.uut = HAMLLintBear(self.section, Queue())

def test_alignment_tabs(self):
good_filename = 'test_alignment_tabs_good_file.haml'
file_contents = load_testfile(good_filename)
self.check_validity(self.uut, file_contents)

def test_alt_text(self):
good_filename = 'test_alt_text_good_file.haml'
file_contents = load_testfile(good_filename)
self.check_validity(self.uut, file_contents)

bad_filename = 'test_alt_text_bad_file.haml'
file_contents = load_testfile(bad_filename)
self.check_invalidity(self.uut, file_contents)

def test_class_attribute_with_static_value(self):
good_file = ['%tag.my-class']
self.check_validity(self.uut, good_file)

bad_file = ['%tag{ ',
'class: ',
'\'my-class'
'\' }']
self.check_invalidity(self.uut, bad_file)

def test_classes_before_ids(self):
good_file = ['%tag.class#id']
self.check_validity(self.uut, good_file)

bad_file = ['%tag#id.class']
self.check_invalidity(self.uut, bad_file)

def test_config_file(self):
filename = 'test_no_trailing_whitespace_file.haml'
file_contents = load_testfile(filename)
self.check_results(
self.uut,
file_contents,
[],
filename=get_testfile_path(filename),
settings={'hamllint_config': get_testfile_path('.haml-lint.yml')})

def test_consecutive_comments(self):
good_filename = 'test_consecutive_comments_good_file.haml'
file_contents = load_testfile(good_filename)
self.check_validity(self.uut, file_contents)

bad_filename = 'test_consecutive_comments_bad_file.haml'
file_contents = load_testfile(bad_filename)
self.check_invalidity(self.uut, file_contents)

good_filename = 'test_consecutive_comments_good_file_via_config.haml'
file_contents = load_testfile(good_filename)
settings = {'max_consecutive_comments': 2}
self.check_validity(self.uut, file_contents, settings=settings)

def test_consecutive_silent_scripts(self):
good_filename = 'test_consecutive_silent_scripts_good_file.haml'
file_contents = load_testfile(good_filename)
self.check_validity(self.uut, file_contents)

bad_filename = 'test_consecutive_silent_scripts_bad_file.haml'
file_contents = load_testfile(bad_filename)
self.check_invalidity(self.uut, file_contents)

def test_empty_object_reference(self):
good_file = ['%tag']
self.check_validity(self.uut, good_file)

bad_file = ['%tag[]']
self.check_invalidity(self.uut, bad_file)

def test_empty_script(self):
good_file = ['- some_expression']
self.check_validity(self.uut, good_file)

bad_file = ['-']
self.check_invalidity(self.uut, bad_file)

def test_final_newline(self):
bad_filename = 'test_no_trailing_whitespace_file.haml'
file_contents = load_testfile(bad_filename)
self.check_invalidity(self.uut, file_contents)

def test_html_attributes(self):
good_file = ['%tag{ lang: \'en\' }']
self.check_validity(self.uut, good_file)

bad_file = ['%tag(lang=en)']
self.check_invalidity(self.uut, bad_file)

def test_inline_styles(self):
good_file = ['%p.warning']
self.check_validity(self.uut, good_file)

bad_file = ['%p{ style: \'color: red;\' }']
self.check_invalidity(self.uut, bad_file)

def test_syntax(self):
good_file = ['%div\n',
'%p Hello, world']
self.check_validity(self.uut, good_file)

bad_file = ['%div\n',
'% Hello, world']
self.check_invalidity(self.uut, bad_file)
Empty file added tests/haml/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/haml/hamllint_test_files/.haml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
linters:
LineLength:
enabled: true
max: 80
TrailingWhitespace:
enabled: false
RuboCop:
enabled: false
cops:
- Style/IfUnlessModifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%div
%p Hello, world
%span This does not worry about alignment of tag text
1 change: 1 addition & 0 deletions tests/haml/hamllint_test_files/test_alt_text_bad_file.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%img{ src: 'my-photo.jpg' }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%img{ alt: 'Photo of me', src: 'my-photo.jpg' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-# A collection
-# of many
-# consecutive comments
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-#
A multiline comment
is much more clean
and concise
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-# A collection
-# of 2 consecutive comments
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- expression_one
- expression_two
- expression_three
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:ruby
expression_one
expression_two
expression_three
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#content
.left.column
%h2 Welcome to our site!
%p= print_information
.right.column
= render partial: 'sidebar'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#content
.left.column
%h2 Welcome to our site!
%p= print_information
.right.column
= render partial: 'sidebar'

0 comments on commit c86a6d0

Please sign in to comment.