diff options
Diffstat (limited to 'python/mozlint/test/linters')
-rw-r--r-- | python/mozlint/test/linters/badreturncode.lint | 21 | ||||
-rw-r--r-- | python/mozlint/test/linters/explicit_path.lint | 13 | ||||
-rw-r--r-- | python/mozlint/test/linters/external.lint | 30 | ||||
-rw-r--r-- | python/mozlint/test/linters/invalid_exclude.lint | 10 | ||||
-rw-r--r-- | python/mozlint/test/linters/invalid_extension.lnt | 9 | ||||
-rw-r--r-- | python/mozlint/test/linters/invalid_include.lint | 10 | ||||
-rw-r--r-- | python/mozlint/test/linters/invalid_type.lint | 9 | ||||
-rw-r--r-- | python/mozlint/test/linters/missing_attrs.lint | 7 | ||||
-rw-r--r-- | python/mozlint/test/linters/missing_definition.lint | 4 | ||||
-rw-r--r-- | python/mozlint/test/linters/raises.lint | 19 | ||||
-rw-r--r-- | python/mozlint/test/linters/regex.lint | 15 | ||||
-rw-r--r-- | python/mozlint/test/linters/string.lint | 15 | ||||
-rw-r--r-- | python/mozlint/test/linters/structured.lint | 28 |
13 files changed, 190 insertions, 0 deletions
diff --git a/python/mozlint/test/linters/badreturncode.lint b/python/mozlint/test/linters/badreturncode.lint new file mode 100644 index 0000000000..398d51a553 --- /dev/null +++ b/python/mozlint/test/linters/badreturncode.lint @@ -0,0 +1,21 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +def lint(files, **lintargs): + return 1 + + +LINTER = { + 'name': "BadReturnCodeLinter", + 'description': "Returns an error code no matter what", + 'include': [ + 'files', + ], + 'type': 'external', + 'extensions': ['.js', '.jsm'], + 'payload': lint, +} diff --git a/python/mozlint/test/linters/explicit_path.lint b/python/mozlint/test/linters/explicit_path.lint new file mode 100644 index 0000000000..8c1a88a1fb --- /dev/null +++ b/python/mozlint/test/linters/explicit_path.lint @@ -0,0 +1,13 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "ExplicitPathLinter", + 'description': "Only lint a specific file name", + 'rule': 'no-foobar', + 'include': [ + 'no_foobar.js', + ], + 'type': 'string', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/external.lint b/python/mozlint/test/linters/external.lint new file mode 100644 index 0000000000..dcae419dbf --- /dev/null +++ b/python/mozlint/test/linters/external.lint @@ -0,0 +1,30 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from mozlint import result + + +def lint(files, **lintargs): + results = [] + for path in files: + with open(path, 'r') as fh: + for i, line in enumerate(fh.readlines()): + if 'foobar' in line: + results.append(result.from_linter( + LINTER, path=path, lineno=i+1, column=1, rule="no-foobar")) + return results + + +LINTER = { + 'name': "ExternalLinter", + 'description': "It's bad to have the string foobar in js files.", + 'include': [ + 'files', + ], + 'type': 'external', + 'extensions': ['.js', '.jsm'], + 'payload': lint, +} diff --git a/python/mozlint/test/linters/invalid_exclude.lint b/python/mozlint/test/linters/invalid_exclude.lint new file mode 100644 index 0000000000..be6d0045cf --- /dev/null +++ b/python/mozlint/test/linters/invalid_exclude.lint @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "BadExcludeLinter", + 'description': "Has an invalid exclude directive.", + 'exclude': [0, 1], # should be a list of strings + 'type': 'string', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/invalid_extension.lnt b/python/mozlint/test/linters/invalid_extension.lnt new file mode 100644 index 0000000000..3cb8153a00 --- /dev/null +++ b/python/mozlint/test/linters/invalid_extension.lnt @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "BadExtensionLinter", + 'description': "Has an invalid file extension.", + 'type': 'string', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/invalid_include.lint b/python/mozlint/test/linters/invalid_include.lint new file mode 100644 index 0000000000..343d5e1950 --- /dev/null +++ b/python/mozlint/test/linters/invalid_include.lint @@ -0,0 +1,10 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "BadIncludeLinter", + 'description': "Has an invalid include directive.", + 'include': 'should be a list', + 'type': 'string', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/invalid_type.lint b/python/mozlint/test/linters/invalid_type.lint new file mode 100644 index 0000000000..9e5926c5a5 --- /dev/null +++ b/python/mozlint/test/linters/invalid_type.lint @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "BadTypeLinter", + 'description': "Has an invalid type.", + 'type': 'invalid', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/missing_attrs.lint b/python/mozlint/test/linters/missing_attrs.lint new file mode 100644 index 0000000000..380512b640 --- /dev/null +++ b/python/mozlint/test/linters/missing_attrs.lint @@ -0,0 +1,7 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "MissingAttrsLinter", + 'description': "Missing type and payload", +} diff --git a/python/mozlint/test/linters/missing_definition.lint b/python/mozlint/test/linters/missing_definition.lint new file mode 100644 index 0000000000..a84b305d2a --- /dev/null +++ b/python/mozlint/test/linters/missing_definition.lint @@ -0,0 +1,4 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +# No LINTER variable diff --git a/python/mozlint/test/linters/raises.lint b/python/mozlint/test/linters/raises.lint new file mode 100644 index 0000000000..f17e187337 --- /dev/null +++ b/python/mozlint/test/linters/raises.lint @@ -0,0 +1,19 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from mozlint.errors import LintException + + +def lint(files, **lintargs): + raise LintException("Oh no something bad happened!") + + +LINTER = { + 'name': "RaisesLinter", + 'description': "Raises an exception", + 'type': 'external', + 'payload': lint, +} diff --git a/python/mozlint/test/linters/regex.lint b/python/mozlint/test/linters/regex.lint new file mode 100644 index 0000000000..439cadf366 --- /dev/null +++ b/python/mozlint/test/linters/regex.lint @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "RegexLinter", + 'description': "Make sure the string 'foobar' never appears " + "in a js variable file because it is bad.", + 'rule': 'no-foobar', + 'include': [ + '**/*.js', + '**/*.jsm', + ], + 'type': 'regex', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/string.lint b/python/mozlint/test/linters/string.lint new file mode 100644 index 0000000000..46bf0e8b86 --- /dev/null +++ b/python/mozlint/test/linters/string.lint @@ -0,0 +1,15 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: + +LINTER = { + 'name': "StringLinter", + 'description': "Make sure the string 'foobar' never appears " + "in browser js files because it is bad.", + 'rule': 'no-foobar', + 'include': [ + '**/*.js', + '**/*.jsm', + ], + 'type': 'string', + 'payload': 'foobar', +} diff --git a/python/mozlint/test/linters/structured.lint b/python/mozlint/test/linters/structured.lint new file mode 100644 index 0000000000..e8be8d7b3a --- /dev/null +++ b/python/mozlint/test/linters/structured.lint @@ -0,0 +1,28 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +def lint(files, logger, **kwargs): + for path in files: + with open(path, 'r') as fh: + for i, line in enumerate(fh.readlines()): + if 'foobar' in line: + logger.lint_error(path=path, + lineno=i+1, + column=1, + rule="no-foobar") + + +LINTER = { + 'name': "StructuredLinter", + 'description': "It's bad to have the string foobar in js files.", + 'include': [ + 'files', + ], + 'type': 'structured_log', + 'extensions': ['.js', '.jsm'], + 'payload': lint, +} |