Skip to content

Commit f9082ff

Browse files
authored
feat: flat-rule-tester make sure default config always matches (#17585)
* 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
1 parent 83914ad commit f9082ff

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

lib/rule-tester/flat-rule-tester.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ class FlatRuleTester {
535535
}
536536

537537
const baseConfig = [
538+
{ files: ["**"] }, // Make sure the default config matches for all files
538539
{
539540
plugins: {
540541

tests/lib/rule-tester/flat-rule-tester.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,84 @@ describe("FlatRuleTester", () => {
11161116
}());
11171117
});
11181118

1119+
it("should allow setting the filename to a non-JavaScript file", () => {
1120+
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
1121+
valid: [
1122+
{
1123+
code: "var foo = 'bar'",
1124+
filename: "somefile.ts"
1125+
}
1126+
],
1127+
invalid: []
1128+
});
1129+
});
1130+
1131+
it("should allow setting the filename to a file path without extension", () => {
1132+
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
1133+
valid: [
1134+
{
1135+
code: "var foo = 'bar'",
1136+
filename: "somefile"
1137+
},
1138+
{
1139+
code: "var foo = 'bar'",
1140+
filename: "path/to/somefile"
1141+
}
1142+
],
1143+
invalid: []
1144+
});
1145+
});
1146+
1147+
it("should allow setting the filename to a file path with extension", () => {
1148+
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
1149+
valid: [
1150+
{
1151+
code: "var foo = 'bar'",
1152+
filename: "path/to/somefile.js"
1153+
},
1154+
{
1155+
code: "var foo = 'bar'",
1156+
filename: "src/somefile.ts"
1157+
},
1158+
{
1159+
code: "var foo = 'bar'",
1160+
filename: "components/Component.vue"
1161+
}
1162+
],
1163+
invalid: []
1164+
});
1165+
});
1166+
1167+
it("should allow setting the filename to a file path without extension", () => {
1168+
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
1169+
valid: [
1170+
{
1171+
code: "var foo = 'bar'",
1172+
filename: "path/to/somefile"
1173+
},
1174+
{
1175+
code: "var foo = 'bar'",
1176+
filename: "src/somefile"
1177+
}
1178+
],
1179+
invalid: []
1180+
});
1181+
});
1182+
1183+
it("should keep allowing non-JavaScript files if the default config does not specify files", () => {
1184+
FlatRuleTester.setDefaultConfig({ rules: {} });
1185+
ruleTester.run("", require("../../fixtures/testers/rule-tester/no-test-filename"), {
1186+
valid: [
1187+
{
1188+
code: "var foo = 'bar'",
1189+
filename: "somefile.ts"
1190+
}
1191+
],
1192+
invalid: []
1193+
});
1194+
FlatRuleTester.resetDefaultConfig();
1195+
});
1196+
11191197
it("should pass-through the options to the rule", () => {
11201198
ruleTester.run("no-invalid-args", require("../../fixtures/testers/rule-tester/no-invalid-args"), {
11211199
valid: [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy