diff --git a/tools/lint/eslint/__init__.py b/tools/lint/eslint/__init__.py index 4707dcd6045f..c15f9af7b852 100644 --- a/tools/lint/eslint/__init__.py +++ b/tools/lint/eslint/__init__.py @@ -97,7 +97,8 @@ def lint(paths, config, binary=None, fix=None, rules=[], setup=None, **lintargs) "--no-error-on-unmatched-pattern", ] + rules - + extra_args + # Flat configuration doesn't understand --ignore-path, though Prettier does. + + list(filter(lambda x: not x.startswith("--ignore-path"), extra_args)) + exclude_args + paths ) @@ -122,7 +123,9 @@ def lint(paths, config, binary=None, fix=None, rules=[], setup=None, **lintargs) "--list-different", "--no-error-on-unmatched-pattern", ] - + extra_args + # Don't pass the configuration to Prettier as well, as it doesn't understand + # the ESLint configuration. + + list(filter(lambda x: not x.startswith("--config"), extra_args)) # Prettier does not support exclude arguments. # + exclude_args + paths diff --git a/tools/lint/test/files/eslint/test-eslint.config.mjs b/tools/lint/test/files/eslint/test-eslint.config.mjs new file mode 100644 index 000000000000..5c18c794147b --- /dev/null +++ b/tools/lint/test/files/eslint/test-eslint.config.mjs @@ -0,0 +1,10 @@ +/* Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ */ + +import js from "@eslint/js"; +import mozilla from "eslint-plugin-mozilla"; + +export default [ + js.configs.recommended, + ...mozilla.configs["flat/recommended"], +]; diff --git a/tools/lint/test/test_eslint.py b/tools/lint/test/test_eslint.py index b4fda2fb351b..1b3b82eac836 100644 --- a/tools/lint/test/test_eslint.py +++ b/tools/lint/test/test_eslint.py @@ -15,6 +15,7 @@ def eslint(lint): kwargs["extra_args"] = [ "--no-ignore", "--ignore-path=tools/lint/test/files/eslint/testprettierignore", + "--config=tools/lint/test/files/eslint/test-eslint.config.mjs", ] return lint(*args, **kwargs) @@ -35,7 +36,9 @@ def test_no_files_to_lint(eslint, config, paths): # Errors still show up even when a directory with no files is passed in. results = eslint(paths("nolint", "subdir/bad.js"), root=build.topsrcdir) - assert len(results) == 1 + # This will fail for ESLint, with 'foo' is assigned a value but never used, + # and for Prettier, as it needs formatting. + assert len(results) == 2 def test_bad_import(eslint, config, paths): @@ -43,6 +46,9 @@ def test_bad_import(eslint, config, paths): assert results == 1 +@pytest.mark.skip( + reason="Bug 1967219. --no-ignore doesn't seem to work properly with flat config and v8." +) def test_eslint_rule(eslint, config, create_temp_file): contents = """var re = /foo bar/; var re = new RegExp("foo bar"); @@ -55,6 +61,9 @@ var re = new RegExp("foo bar"); assert len(results) == 2 +@pytest.mark.skip( + reason="Bug 1967219. --no-ignore doesn't seem to work properly with flat config and v8." +) def test_eslint_fix(eslint, config, create_temp_file): contents = """/*eslint no-regex-spaces: "error"*/ @@ -74,6 +83,9 @@ var re = new RegExp("foo bar"); assert fixed == 1 +@pytest.mark.skip( + reason="Bug 1967219. --no-ignore doesn't seem to work properly with flat config and v8." +) def test_prettier_rule(eslint, config, create_temp_file): contents = """var re = /foobar/; var re = "foo"; @@ -84,6 +96,9 @@ def test_prettier_rule(eslint, config, create_temp_file): assert len(results) == 1 +@pytest.mark.skip( + reason="Bug 1967219. --no-ignore doesn't seem to work properly with flat config and v8." +) def test_prettier_fix(eslint, config, create_temp_file): contents = """var re = /foobar/; var re = "foo"; diff --git a/tools/lint/test/test_file_license.py b/tools/lint/test/test_file_license.py index 250d4a0778e6..463b558d71d7 100644 --- a/tools/lint/test/test_file_license.py +++ b/tools/lint/test/test_file_license.py @@ -9,7 +9,7 @@ def test_lint_license(lint, paths): print(results) assert len(results) == 3 - assert ".eslintrc.js" in results[0].relpath + assert ".eslintrc.mjs" in results[0].relpath assert "No matching license strings" in results[1].message assert results[1].level == "error"