diff --git a/scripts/xsslint/tests/test_linters.py b/scripts/xsslint/tests/test_linters.py index bbe6937bab..bc7f560fbb 100644 --- a/scripts/xsslint/tests/test_linters.py +++ b/scripts/xsslint/tests/test_linters.py @@ -11,7 +11,6 @@ from ddt import data, ddt from xsslint.linters import JavaScriptLinter, MakoTemplateLinter, PythonLinter, UnderscoreTemplateLinter from xsslint.reporting import FileResults -from xsslint.rules import Rules from xsslint.utils import ParseString @@ -64,6 +63,8 @@ class TestUnderscoreTemplateLinter(TestLinter): Test UnderscoreTemplateLinter """ + ruleset = UnderscoreTemplateLinter.ruleset + def test_check_underscore_file_is_safe(self): """ Test check_underscore_file_is_safe with safe template @@ -101,8 +102,8 @@ class TestUnderscoreTemplateLinter(TestLinter): linter.check_underscore_file_is_safe(template, results) self.assertEqual(len(results.violations), 2) - self.assertEqual(results.violations[0].rule, Rules.underscore_not_escaped) - self.assertEqual(results.violations[1].rule, Rules.underscore_not_escaped) + self.assertEqual(results.violations[0].rule, self.ruleset.underscore_not_escaped) + self.assertEqual(results.violations[1].rule, self.ruleset.underscore_not_escaped) @data( { @@ -210,6 +211,9 @@ class TestJavaScriptLinter(TestLinter): """ Test JavaScriptLinter """ + + ruleset = JavaScriptLinter.ruleset + UnderscoreTemplateLinter.ruleset + @data( {'template': 'var m = "Plain text " + message + "plain text"', 'rule': None}, {'template': 'var m = "檌檒濦 " + message + "plain text"', 'rule': None}, @@ -219,14 +223,14 @@ class TestJavaScriptLinter(TestLinter): """ value: gettext("Copy Email To Editor"), id: 'copy_email_' + email_id))"""), 'rule': None }, - {'template': 'var m = "
" + message + "
"', 'rule': Rules.javascript_concat_html}, + {'template': 'var m = "" + message + "
"', 'rule': ruleset.javascript_concat_html}, { 'template': r'var m = "\"escaped quote\"" + message + "\"escaped quote\"
"', - 'rule': Rules.javascript_concat_html + 'rule': ruleset.javascript_concat_html }, {'template': ' // var m = "" + commentedOutMessage + "
"', 'rule': None}, - {'template': 'var m = "" + message + "
"', 'rule': Rules.javascript_concat_html}, - {'template': 'var m = "" + message + " broken string', 'rule': Rules.javascript_concat_html}, + {'template': 'var m = "
" + message + "
"', 'rule': ruleset.javascript_concat_html}, + {'template': 'var m = "" + message + " broken string', 'rule': ruleset.javascript_concat_html}, ) def test_concat_with_html(self, data): """ @@ -247,16 +251,16 @@ class TestJavaScriptLinter(TestLinter): # plain text is ok because any & will be escaped, and it stops false # negatives on some other objects with an append() method {'template': 'test.append("plain text")', 'rule': None}, - {'template': 'test.append("
")', 'rule': Rules.javascript_jquery_append}, + {'template': 'test.append("")', 'rule': ruleset.javascript_jquery_append}, {'template': 'graph.svg.append("g")', 'rule': None}, {'template': 'test.append( $( "" + commentedOutMessage + "
"', 'rule': None}, - {'template': 'm = "" + message + "
"', 'rule': [Rules.python_concat_html, Rules.python_concat_html]}, - {'template': 'm = "" + message + "
"', 'rule': [Rules.python_concat_html, Rules.python_concat_html]}, - {'template': 'm = "" + message + " broken string', 'rule': Rules.python_parse_error}, + {'template': 'm = "
" + message + "
"', 'rule': [ruleset.python_concat_html, ruleset.python_concat_html]}, + {'template': 'm = "" + message + "
"', 'rule': [ruleset.python_concat_html, ruleset.python_concat_html]}, + {'template': 'm = " " + message + " broken string', 'rule': ruleset.python_parse_error},
)
def test_concat_with_html(self, data):
"""
@@ -456,7 +463,7 @@ class TestPythonLinter(TestLinter):
linter.check_python_file_is_safe(python_file, results)
self.assertEqual(len(results.violations), 1)
- self.assertEqual(results.violations[0].rule, Rules.python_deprecated_display_name)
+ self.assertEqual(results.violations[0].rule, self.ruleset.python_deprecated_display_name)
def test_check_custom_escaping(self):
"""
@@ -472,7 +479,7 @@ class TestPythonLinter(TestLinter):
linter.check_python_file_is_safe(python_file, results)
self.assertEqual(len(results.violations), 1)
- self.assertEqual(results.violations[0].rule, Rules.python_custom_escape)
+ self.assertEqual(results.violations[0].rule, self.ruleset.python_custom_escape)
@data(
{
@@ -493,7 +500,7 @@ class TestPythonLinter(TestLinter):
span_end=HTML(""),
)
"""),
- 'rule': Rules.python_requires_html_or_text
+ 'rule': ruleset.python_requires_html_or_text
},
{
'python':
@@ -504,7 +511,7 @@ class TestPythonLinter(TestLinter):
span_end=HTML(""),
)
"""),
- 'rule': Rules.python_requires_html_or_text
+ 'rule': ruleset.python_requires_html_or_text
},
{
'python':
@@ -514,7 +521,7 @@ class TestPythonLinter(TestLinter):
link_end=HTML(""),
))
"""),
- 'rule': [Rules.python_close_before_format, Rules.python_requires_html_or_text]
+ 'rule': [ruleset.python_close_before_format, ruleset.python_requires_html_or_text]
},
{
'python':
@@ -524,7 +531,7 @@ class TestPythonLinter(TestLinter):
link_end=HTML(""),
)
"""),
- 'rule': Rules.python_close_before_format
+ 'rule': ruleset.python_close_before_format
},
{
'python':
@@ -536,10 +543,10 @@ class TestPythonLinter(TestLinter):
"""),
'rule':
[
- Rules.python_close_before_format,
- Rules.python_requires_html_or_text,
- Rules.python_close_before_format,
- Rules.python_requires_html_or_text
+ ruleset.python_close_before_format,
+ ruleset.python_requires_html_or_text,
+ ruleset.python_close_before_format,
+ ruleset.python_requires_html_or_text
]
},
{
@@ -550,7 +557,7 @@ class TestPythonLinter(TestLinter):
span_end="",
)
"""),
- 'rule': [Rules.python_wrap_html, Rules.python_wrap_html]
+ 'rule': [ruleset.python_wrap_html, ruleset.python_wrap_html]
},
{
'python':
@@ -581,11 +588,11 @@ class TestPythonLinter(TestLinter):
},
{
'python': r"""msg = ''.format(message)""",
- 'rule': Rules.python_wrap_html
+ 'rule': ruleset.python_wrap_html
},
{
'python': r"""r'regex with {} and named group(?P