summaryrefslogtreecommitdiffstats
path: root/python/mozlint/test/linters
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--python/mozlint/test/linters/badreturncode.yml8
-rw-r--r--python/mozlint/test/linters/excludes.yml10
-rw-r--r--python/mozlint/test/linters/excludes_empty.yml8
-rw-r--r--python/mozlint/test/linters/explicit_path.yml8
-rw-r--r--python/mozlint/test/linters/external.py74
-rw-r--r--python/mozlint/test/linters/external.yml8
-rw-r--r--python/mozlint/test/linters/global.yml8
-rw-r--r--python/mozlint/test/linters/global_payload.py38
-rw-r--r--python/mozlint/test/linters/global_skipped.yml8
-rw-r--r--python/mozlint/test/linters/invalid_exclude.yml6
-rw-r--r--python/mozlint/test/linters/invalid_extension.ym5
-rw-r--r--python/mozlint/test/linters/invalid_include.yml6
-rw-r--r--python/mozlint/test/linters/invalid_include_with_glob.yml6
-rw-r--r--python/mozlint/test/linters/invalid_support_files.yml6
-rw-r--r--python/mozlint/test/linters/invalid_type.yml5
-rw-r--r--python/mozlint/test/linters/missing_attrs.yml3
-rw-r--r--python/mozlint/test/linters/missing_definition.yml1
-rw-r--r--python/mozlint/test/linters/multiple.yml19
-rw-r--r--python/mozlint/test/linters/non_existing_exclude.yml7
-rw-r--r--python/mozlint/test/linters/non_existing_include.yml7
-rw-r--r--python/mozlint/test/linters/non_existing_support_files.yml7
-rw-r--r--python/mozlint/test/linters/raises.yml6
-rw-r--r--python/mozlint/test/linters/regex.yml10
-rw-r--r--python/mozlint/test/linters/setup.yml9
-rw-r--r--python/mozlint/test/linters/setupfailed.yml9
-rw-r--r--python/mozlint/test/linters/setupraised.yml9
-rw-r--r--python/mozlint/test/linters/slow.yml8
-rw-r--r--python/mozlint/test/linters/string.yml9
-rw-r--r--python/mozlint/test/linters/structured.yml8
-rw-r--r--python/mozlint/test/linters/support_files.yml10
-rw-r--r--python/mozlint/test/linters/warning.yml11
-rw-r--r--python/mozlint/test/linters/warning_no_code_review.yml12
32 files changed, 349 insertions, 0 deletions
diff --git a/python/mozlint/test/linters/badreturncode.yml b/python/mozlint/test/linters/badreturncode.yml
new file mode 100644
index 0000000000..72abf83cc7
--- /dev/null
+++ b/python/mozlint/test/linters/badreturncode.yml
@@ -0,0 +1,8 @@
+---
+BadReturnCodeLinter:
+ description: Returns an error code no matter what
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:badreturncode
diff --git a/python/mozlint/test/linters/excludes.yml b/python/mozlint/test/linters/excludes.yml
new file mode 100644
index 0000000000..1fc1068735
--- /dev/null
+++ b/python/mozlint/test/linters/excludes.yml
@@ -0,0 +1,10 @@
+---
+ExcludesLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad
+ rule: no-foobar
+ exclude: ['**/foobar.js']
+ extensions: ['.js', 'jsm']
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/excludes_empty.yml b/python/mozlint/test/linters/excludes_empty.yml
new file mode 100644
index 0000000000..03cd1aecab
--- /dev/null
+++ b/python/mozlint/test/linters/excludes_empty.yml
@@ -0,0 +1,8 @@
+---
+ExcludesEmptyLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: foobar
diff --git a/python/mozlint/test/linters/explicit_path.yml b/python/mozlint/test/linters/explicit_path.yml
new file mode 100644
index 0000000000..1e7e8f4bf1
--- /dev/null
+++ b/python/mozlint/test/linters/explicit_path.yml
@@ -0,0 +1,8 @@
+---
+ExplicitPathLinter:
+ description: Only lint a specific file name
+ rule: no-foobar
+ include:
+ - files/no_foobar.js
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/external.py b/python/mozlint/test/linters/external.py
new file mode 100644
index 0000000000..9c2e58909d
--- /dev/null
+++ b/python/mozlint/test/linters/external.py
@@ -0,0 +1,74 @@
+# 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/.
+
+import os
+import time
+
+from mozlint import result
+from mozlint.errors import LintException
+
+
+def badreturncode(files, config, **lintargs):
+ return 1
+
+
+def external(files, config, **lintargs):
+ if lintargs.get("fix"):
+ # mimics no results because they got fixed
+ return []
+
+ results = []
+ for path in files:
+ if os.path.isdir(path):
+ continue
+
+ with open(path, "r") as fh:
+ for i, line in enumerate(fh.readlines()):
+ if "foobar" in line:
+ results.append(
+ result.from_config(
+ config, path=path, lineno=i + 1, column=1, rule="no-foobar"
+ )
+ )
+ return results
+
+
+def raises(files, config, **lintargs):
+ raise LintException("Oh no something bad happened!")
+
+
+def slow(files, config, **lintargs):
+ time.sleep(2)
+ return []
+
+
+def structured(files, config, logger, **kwargs):
+ for path in files:
+ if os.path.isdir(path):
+ continue
+
+ 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"
+ )
+
+
+def passes(files, config, **lintargs):
+ return []
+
+
+def setup(**lintargs):
+ print("setup passed")
+
+
+def setupfailed(**lintargs):
+ print("setup failed")
+ return 1
+
+
+def setupraised(**lintargs):
+ print("setup raised")
+ raise LintException("oh no setup failed")
diff --git a/python/mozlint/test/linters/external.yml b/python/mozlint/test/linters/external.yml
new file mode 100644
index 0000000000..574b8df4cb
--- /dev/null
+++ b/python/mozlint/test/linters/external.yml
@@ -0,0 +1,8 @@
+---
+ExternalLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:external
diff --git a/python/mozlint/test/linters/global.yml b/python/mozlint/test/linters/global.yml
new file mode 100644
index 0000000000..47d5ce81e4
--- /dev/null
+++ b/python/mozlint/test/linters/global.yml
@@ -0,0 +1,8 @@
+---
+GlobalLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: global
+ extensions: ['.js', '.jsm']
+ payload: global_payload:global_payload
diff --git a/python/mozlint/test/linters/global_payload.py b/python/mozlint/test/linters/global_payload.py
new file mode 100644
index 0000000000..ec620b6af1
--- /dev/null
+++ b/python/mozlint/test/linters/global_payload.py
@@ -0,0 +1,38 @@
+# 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/.
+
+import mozpack.path as mozpath
+from external import external
+from mozpack.files import FileFinder
+
+from mozlint import result
+
+
+def global_payload(config, **lintargs):
+ # A global linter that runs the external linter to actually lint.
+ finder = FileFinder(lintargs["root"])
+ files = [mozpath.join(lintargs["root"], p) for p, _ in finder.find("files/**")]
+ issues = external(files, config, **lintargs)
+ for issue in issues:
+ # Make issue look like it comes from this linter.
+ issue.linter = "global_payload"
+ return issues
+
+
+def global_skipped(config, **lintargs):
+ # A global linter that always registers a lint error. Absence of
+ # this error shows that the path exclusion mechanism can cause
+ # global lint payloads to not be invoked at all. In particular,
+ # the `extensions` field means that nothing under `files/**` will
+ # match.
+
+ finder = FileFinder(lintargs["root"])
+ files = [mozpath.join(lintargs["root"], p) for p, _ in finder.find("files/**")]
+
+ issues = []
+ issues.append(
+ result.from_config(
+ config, path=files[0], lineno=1, column=1, rule="not-skipped"
+ )
+ )
diff --git a/python/mozlint/test/linters/global_skipped.yml b/python/mozlint/test/linters/global_skipped.yml
new file mode 100644
index 0000000000..99b784e8be
--- /dev/null
+++ b/python/mozlint/test/linters/global_skipped.yml
@@ -0,0 +1,8 @@
+---
+GlobalSkippedLinter:
+ description: It's bad to run global linters when nothing matches.
+ include:
+ - files
+ type: global
+ extensions: ['.non.existent.extension']
+ payload: global_payload:global_skipped
diff --git a/python/mozlint/test/linters/invalid_exclude.yml b/python/mozlint/test/linters/invalid_exclude.yml
new file mode 100644
index 0000000000..7231d2c146
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_exclude.yml
@@ -0,0 +1,6 @@
+---
+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.ym b/python/mozlint/test/linters/invalid_extension.ym
new file mode 100644
index 0000000000..435fa10320
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_extension.ym
@@ -0,0 +1,5 @@
+---
+BadExtensionLinter:
+ description: Has an invalid file extension.
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/invalid_include.yml b/python/mozlint/test/linters/invalid_include.yml
new file mode 100644
index 0000000000..b76b3e6a61
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_include.yml
@@ -0,0 +1,6 @@
+---
+BadIncludeLinter:
+ description: Has an invalid include directive.
+ include: should be a list
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/invalid_include_with_glob.yml b/python/mozlint/test/linters/invalid_include_with_glob.yml
new file mode 100644
index 0000000000..857bb1376b
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_include_with_glob.yml
@@ -0,0 +1,6 @@
+---
+BadIncludeLinterWithGlob:
+ description: Has an invalid include directive.
+ include: ['**/*.js']
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/invalid_support_files.yml b/python/mozlint/test/linters/invalid_support_files.yml
new file mode 100644
index 0000000000..db39597d68
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_support_files.yml
@@ -0,0 +1,6 @@
+---
+BadSupportFilesLinter:
+ description: Has an invalid support files directive.
+ support-files: should be a list
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/invalid_type.yml b/python/mozlint/test/linters/invalid_type.yml
new file mode 100644
index 0000000000..29d82e541e
--- /dev/null
+++ b/python/mozlint/test/linters/invalid_type.yml
@@ -0,0 +1,5 @@
+---
+BadTypeLinter:
+ description: Has an invalid type.
+ type: invalid
+ payload: foobar
diff --git a/python/mozlint/test/linters/missing_attrs.yml b/python/mozlint/test/linters/missing_attrs.yml
new file mode 100644
index 0000000000..5abe15fcfc
--- /dev/null
+++ b/python/mozlint/test/linters/missing_attrs.yml
@@ -0,0 +1,3 @@
+---
+MissingAttrsLinter:
+ description: Missing type and payload
diff --git a/python/mozlint/test/linters/missing_definition.yml b/python/mozlint/test/linters/missing_definition.yml
new file mode 100644
index 0000000000..d66b2cb781
--- /dev/null
+++ b/python/mozlint/test/linters/missing_definition.yml
@@ -0,0 +1 @@
+# No definition
diff --git a/python/mozlint/test/linters/multiple.yml b/python/mozlint/test/linters/multiple.yml
new file mode 100644
index 0000000000..5b880b3691
--- /dev/null
+++ b/python/mozlint/test/linters/multiple.yml
@@ -0,0 +1,19 @@
+---
+StringLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad
+ rule: no-foobar
+ extensions: ['.js', 'jsm']
+ type: string
+ payload: foobar
+
+---
+RegexLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad
+ rule: no-foobar
+ extensions: ['.js', 'jsm']
+ type: regex
+ payload: foobar
diff --git a/python/mozlint/test/linters/non_existing_exclude.yml b/python/mozlint/test/linters/non_existing_exclude.yml
new file mode 100644
index 0000000000..8190123027
--- /dev/null
+++ b/python/mozlint/test/linters/non_existing_exclude.yml
@@ -0,0 +1,7 @@
+---
+BadExcludeLinter:
+ description: Has an invalid exclude directive.
+ exclude:
+ - files/does_not_exist
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/non_existing_include.yml b/python/mozlint/test/linters/non_existing_include.yml
new file mode 100644
index 0000000000..5443d751ed
--- /dev/null
+++ b/python/mozlint/test/linters/non_existing_include.yml
@@ -0,0 +1,7 @@
+---
+BadIncludeLinter:
+ description: Has an invalid include directive.
+ include:
+ - files/does_not_exist
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/non_existing_support_files.yml b/python/mozlint/test/linters/non_existing_support_files.yml
new file mode 100644
index 0000000000..e636fadf93
--- /dev/null
+++ b/python/mozlint/test/linters/non_existing_support_files.yml
@@ -0,0 +1,7 @@
+---
+BadSupportFilesLinter:
+ description: Has an invalid support-files directive.
+ support-files:
+ - files/does_not_exist
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/raises.yml b/python/mozlint/test/linters/raises.yml
new file mode 100644
index 0000000000..9c0b234779
--- /dev/null
+++ b/python/mozlint/test/linters/raises.yml
@@ -0,0 +1,6 @@
+---
+RaisesLinter:
+ description: Raises an exception
+ include: ['.']
+ type: external
+ payload: external:raises
diff --git a/python/mozlint/test/linters/regex.yml b/python/mozlint/test/linters/regex.yml
new file mode 100644
index 0000000000..2c9c812428
--- /dev/null
+++ b/python/mozlint/test/linters/regex.yml
@@ -0,0 +1,10 @@
+---
+RegexLinter:
+ description: >-
+ Make sure the string foobar never appears in a js variable
+ file because it is bad.
+ rule: no-foobar
+ include: ['.']
+ extensions: ['js', '.jsm']
+ type: regex
+ payload: foobar
diff --git a/python/mozlint/test/linters/setup.yml b/python/mozlint/test/linters/setup.yml
new file mode 100644
index 0000000000..ac75d72c70
--- /dev/null
+++ b/python/mozlint/test/linters/setup.yml
@@ -0,0 +1,9 @@
+---
+SetupLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:external
+ setup: external:setup
diff --git a/python/mozlint/test/linters/setupfailed.yml b/python/mozlint/test/linters/setupfailed.yml
new file mode 100644
index 0000000000..1e3543286f
--- /dev/null
+++ b/python/mozlint/test/linters/setupfailed.yml
@@ -0,0 +1,9 @@
+---
+SetupFailedLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:external
+ setup: external:setupfailed
diff --git a/python/mozlint/test/linters/setupraised.yml b/python/mozlint/test/linters/setupraised.yml
new file mode 100644
index 0000000000..8c987f2d3c
--- /dev/null
+++ b/python/mozlint/test/linters/setupraised.yml
@@ -0,0 +1,9 @@
+---
+SetupRaisedLinter:
+ description: It's bad to have the string foobar in js files.
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:external
+ setup: external:setupraised
diff --git a/python/mozlint/test/linters/slow.yml b/python/mozlint/test/linters/slow.yml
new file mode 100644
index 0000000000..2c47679010
--- /dev/null
+++ b/python/mozlint/test/linters/slow.yml
@@ -0,0 +1,8 @@
+---
+SlowLinter:
+ description: A linter that takes awhile to run
+ include:
+ - files
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:slow
diff --git a/python/mozlint/test/linters/string.yml b/python/mozlint/test/linters/string.yml
new file mode 100644
index 0000000000..836d866ae2
--- /dev/null
+++ b/python/mozlint/test/linters/string.yml
@@ -0,0 +1,9 @@
+---
+StringLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad
+ rule: no-foobar
+ extensions: ['.js', 'jsm']
+ type: string
+ payload: foobar
diff --git a/python/mozlint/test/linters/structured.yml b/python/mozlint/test/linters/structured.yml
new file mode 100644
index 0000000000..01ef447ee3
--- /dev/null
+++ b/python/mozlint/test/linters/structured.yml
@@ -0,0 +1,8 @@
+---
+StructuredLinter:
+ description: "It's bad to have the string foobar in js files."
+ include:
+ - files
+ type: structured_log
+ extensions: ['.js', '.jsm']
+ payload: external:structured
diff --git a/python/mozlint/test/linters/support_files.yml b/python/mozlint/test/linters/support_files.yml
new file mode 100644
index 0000000000..0c278d51fa
--- /dev/null
+++ b/python/mozlint/test/linters/support_files.yml
@@ -0,0 +1,10 @@
+---
+SupportFilesLinter:
+ description: Linter that has a few support files
+ include:
+ - files
+ support-files:
+ - '**/*.py'
+ type: external
+ extensions: ['.js', '.jsm']
+ payload: external:passes
diff --git a/python/mozlint/test/linters/warning.yml b/python/mozlint/test/linters/warning.yml
new file mode 100644
index 0000000000..b86bfd07c7
--- /dev/null
+++ b/python/mozlint/test/linters/warning.yml
@@ -0,0 +1,11 @@
+---
+WarningLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad, but not too bad (just a warning)
+ rule: no-foobar
+ level: warning
+ include: ['.']
+ type: string
+ extensions: ['.js', 'jsm']
+ payload: foobar
diff --git a/python/mozlint/test/linters/warning_no_code_review.yml b/python/mozlint/test/linters/warning_no_code_review.yml
new file mode 100644
index 0000000000..20bfc0503b
--- /dev/null
+++ b/python/mozlint/test/linters/warning_no_code_review.yml
@@ -0,0 +1,12 @@
+---
+WarningNoCodeReviewLinter:
+ description: >-
+ Make sure the string foobar never appears in browser js
+ files because it is bad, but not too bad (just a warning)
+ rule: no-foobar-no-code-review
+ level: warning
+ include: ['.']
+ type: string
+ extensions: ['.js', 'jsm']
+ payload: foobar
+ code_review_warnings: false