Skip to content

Commit 51cd143

Browse files
committed
feat: support eslint flat config
1 parent bc854b0 commit 51cd143

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ For more details on how to extend your configuration from a plugin configuration
1515

1616
<!-- begin auto-generated configs list -->
1717

18-
| | Name | Description |
19-
| :- | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20-
|| `recommended` | This configuration includes rules which I recommend to avoid QUnit runtime errors or incorrect behavior, some of which can be difficult to debug. Some of these rules also encourage best practices that help QUnit work better for you. You can use this configuration by extending from `"plugin:qunit/recommended"` in your configuration file. |
18+
| | Name | Description |
19+
| :- | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
20+
|| `recommended` | This configuration includes rules which I recommend to avoid QUnit runtime errors or incorrect behavior, some of which can be difficult to debug. Some of these rules also encourage best practices that help QUnit work better for you. For ESLint `.eslintrc.js` legacy config, extend from `"plugin:qunit/recommended"`. For ESLint `eslint.config.js` flat config, load from `require('eslint-plugin-qunit/configs/recommended')`. |
2121

2222
<!-- end auto-generated configs list -->
2323

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@
88
"use strict";
99

1010
const requireIndex = require("requireindex");
11+
const pkg = require("./package.json");
1112

1213
module.exports = {
14+
meta: {
15+
name: pkg.name,
16+
version: pkg.version
17+
},
18+
1319
rules: requireIndex(`${__dirname}/lib/rules`),
1420

1521
// eslint-disable-next-line sort-keys
1622
configs: {
1723
recommended: {
18-
description: "This configuration includes rules which I recommend to avoid QUnit runtime errors or incorrect behavior, some of which can be difficult to debug. Some of these rules also encourage best practices that help QUnit work better for you. You can use this configuration by extending from `\"plugin:qunit/recommended\"` in your configuration file.",
24+
description: [
25+
"This configuration includes rules which I recommend to avoid QUnit runtime errors or incorrect behavior, some of which can be difficult to debug. Some of these rules also encourage best practices that help QUnit work better for you.",
26+
"For ESLint `.eslintrc.js` legacy config, extend from `\"plugin:qunit/recommended\"`.",
27+
"For ESLint `eslint.config.js` flat config, load from `require('eslint-plugin-qunit/configs/recommended')`."
28+
].join(" "),
1929
plugins: ["qunit"],
2030
rules: {
2131
"qunit/assert-args": "error",

lib/configs/recommended.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"use strict";
2+
3+
const plugin = require("../../index.js");
4+
5+
module.exports = {
6+
plugins: { qunit: plugin },
7+
rules: plugin.configs.recommended.rules
8+
};

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "eslint-plugin-qunit",
33
"version": "8.0.1",
44
"description": "ESLint plugin containing rules useful for QUnit tests.",
5-
"exports": "./index.js",
5+
"exports": {
6+
".": "./index.js",
7+
"./configs/*": "./lib/configs/*.js"
8+
},
69
"main": "./index.js",
710
"scripts": {
811
"lint": "npm-run-all --continue-on-error --aggregate-output --parallel lint:*",

tests/index.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
const assert = require("chai").assert,
1212
{ rules, configs } = require("../index"),
1313
fs = require("node:fs"),
14-
path = require("node:path");
14+
path = require("node:path"),
15+
requireIndex = require("requireindex"),
16+
plugin = require("../index.js");
1517

1618
//------------------------------------------------------------------------------
1719
// Tests
@@ -59,13 +61,26 @@ describe("index.js", function () {
5961
});
6062

6163
describe("configs", function () {
62-
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
63-
for (const [configName, config] of Object.entries(configs)) {
64-
describe(configName, function () {
65-
it("has the right plugins", function () {
66-
assert.deepStrictEqual(config.plugins, ["qunit"]);
64+
describe("legacy", function () {
65+
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
66+
for (const [configName, config] of Object.entries(configs)) {
67+
describe(configName, function () {
68+
it("has the right plugins", function () {
69+
assert.deepStrictEqual(config.plugins, ["qunit"]);
70+
});
6771
});
68-
});
69-
}
72+
}
73+
});
74+
75+
describe("flat", function () {
76+
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
77+
for (const [configName, config] of Object.entries(requireIndex(`${__dirname}/../lib/configs`))) {
78+
describe(configName, function () {
79+
it("has the right plugins", function () {
80+
assert.deepStrictEqual(config.plugins, { qunit: plugin });
81+
});
82+
});
83+
}
84+
});
7085
});
7186
});

0 commit comments

Comments
 (0)