Skip to content

Commit

Permalink
HTMLLintBear: Add settings for individual features
Browse files Browse the repository at this point in the history
Settings have been added for enabling/disabling indidual
features of the `html_linter`.

Closes #1247
  • Loading branch information
pratyushprakash committed Jan 14, 2017
1 parent b8d3820 commit 55ce1ea
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
88 changes: 87 additions & 1 deletion bears/hypertext/HTMLLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,95 @@ class HTMLLintBear:

@staticmethod
def create_arguments(filename, file, config_file,
doctype: str='Enable',
entities: str='Enable',
trailing_whitespace: str='Enable',
tabs: str='Enable',
charset: str='Enable',
void_element: str='Enable',
optional_tag: str='Enable',
type_attribute: str='Enable',
concerns_separation: str='Enable',
protocol: str='Enable',
names: str='Enable',
capitalization: str='Enable',
quotation: str='Enable',
indentation: str='Enable',
formatting: str='Enable',
boolean_attribute: str='Enable',
invalid_attribute: str='Enable',
void_zero: str='Enable',
invalid_handler: str='Enable',
http_equiv: str='Enable',
extra_whitespace: str='Enable',
htmllint_ignore: typed_list(str)=()):
"""
:param htmllint_ignore: List of checkers to ignore.
:param doctype: Enable or disable doctype checker.
:param entities: Enable or disable unicode entity checker.
:param trailing_whitespace: Enable or disable checker
for trailing whitespace.
:param tabs: Enable or disable check for tabs.
:param charset: Enable or disable utf-8 checking.
:param void_element: Enable or disable checker for void tags.
:param optional_tag: Enable or disable checker for
optional tags.
:param type_attribute: Enable or disable checker for
default types.
:param concerns_separation: Enable or disable checker for
seperation of concern.
:param protocol: Enable or disable checker for
protocol specification.
:param names: Enable or disable checker for
id or class name delimiters.
:param capitalization: Enable or disable checker for
capitalization of tags and attributes.
:param quotation: Enable or disable checker for
quotation marks.
:param indentation: Enable or disable checker for
indentation using spaces.
:param formatting: Enable or disable checker for general
formatting.
:param boolean_attribute: Enable or disable checker
for boolean attributes.
:param invalid_attribute: Enable or disable checker
for invalid attributes.
:param void_zero: Enable or disable checker for javascript
void(0).
:param invalid_handler: Enable or disable checker for Javascript
links.
:param http_equiv: Enable or disable checker for http-equiv.
:param extra_whitespace: Enable or disable checker
for extra whitespace.
:param htmllint_ignore: List of checkers to ignore.
"""
param_dict = {
'doctype': doctype,
'entities': entities,
'trailing_whitespace': trailing_whitespace,
'tabs': tabs,
'charset': charset,
'void_element': void_element,
'optional_tag': optional_tag,
'type_attribute': type_attribute,
'concerns_separation': concerns_separation,
'protocol': protocol,
'names': names,
'capitalization': capitalization,
'quotation': quotation,
'indentation': indentation,
'formatting': formatting,
'boolean_attribute': boolean_attribute,
'invalid_attribute': invalid_attribute,
'void_zero': void_zero,
'invalid_handler': invalid_handler,
'http_equiv': http_equiv,
'extra_whitespace': extra_whitespace,
}

disable_words = ['no', 'off', 'disable']
ignore = ','.join(part.strip() for part in htmllint_ignore)
for param, use in param_dict.items():
if use.lower() in disable_words \
and param not in htmllint_ignore:
ignore += ',{}'.format(param)
return HTMLLintBear._html_lint, '--disable=' + ignore, filename
7 changes: 7 additions & 0 deletions tests/hypertext/HTMLLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@
invalid_files=(test_file,),
settings={'htmllint_ignore': 'quotation'},
tempfile_kwargs={'suffix': '.html'})

HTMLLintBearDisableCheckerTest = verify_local_bear(
HTMLLintBear,
valid_files=(test_file,),
invalid_files=(),
settings={'optional_tag': 'off'},
tempfile_kwargs={'suffix': '.html'})

0 comments on commit 55ce1ea

Please sign in to comment.