Skip to content

Commit

Permalink
feat: flat-rule-tester make sure default config always matches (#17585)
Browse files Browse the repository at this point in the history
* feat: flat-rule-tester make sure default config always matches

* fix: flat rule tester default config also matches paths without file extension

* fix: actually test for extensionless paths

* fix: use base config to make sure that every file is included

* fix: add missing extensionless path tests
  • Loading branch information
DMartens committed Sep 22, 2023
1 parent 83914ad commit f9082ff
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rule-tester/flat-rule-tester.js
Expand Up @@ -535,6 +535,7 @@ class FlatRuleTester {
}

const baseConfig = [
{ files: ["**"] }, // Make sure the default config matches for all files
{
plugins: {

Expand Down
78 changes: 78 additions & 0 deletions tests/lib/rule-tester/flat-rule-tester.js
Expand Up @@ -1116,6 +1116,84 @@ describe("FlatRuleTester", () => {
}());
});

it("should allow setting the filename to a non-JavaScript file", () => {
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
valid: [
{
code: "var foo = 'bar'",
filename: "somefile.ts"
}
],
invalid: []
});
});

it("should allow setting the filename to a file path without extension", () => {
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
valid: [
{
code: "var foo = 'bar'",
filename: "somefile"
},
{
code: "var foo = 'bar'",
filename: "path/to/somefile"
}
],
invalid: []
});
});

it("should allow setting the filename to a file path with extension", () => {
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
valid: [
{
code: "var foo = 'bar'",
filename: "path/to/somefile.js"
},
{
code: "var foo = 'bar'",
filename: "src/somefile.ts"
},
{
code: "var foo = 'bar'",
filename: "components/Component.vue"
}
],
invalid: []
});
});

it("should allow setting the filename to a file path without extension", () => {
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
valid: [
{
code: "var foo = 'bar'",
filename: "path/to/somefile"
},
{
code: "var foo = 'bar'",
filename: "src/somefile"
}
],
invalid: []
});
});

it("should keep allowing non-JavaScript files if the default config does not specify files", () => {
FlatRuleTester.setDefaultConfig({ rules: {} });
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
valid: [
{
code: "var foo = 'bar'",
filename: "somefile.ts"
}
],
invalid: []
});
FlatRuleTester.resetDefaultConfig();
});

it("should pass-through the options to the rule", () => {
ruleTester.run("no-invalid-args", require("../../fixtures/testers/rule-tester/no-invalid-args"), {
valid: [
Expand Down

0 comments on commit f9082ff

Please sign in to comment.