Skip to content

Commit

Permalink
feat: support eslint flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 11, 2023
1 parent bc854b0 commit 51cd143
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -15,9 +15,9 @@ For more details on how to extend your configuration from a plugin configuration

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

| | Name | Description |
| :- | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|| `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. |
| | Name | Description |
| :- | :------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|| `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')`. |

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

Expand Down
12 changes: 11 additions & 1 deletion index.js
Expand Up @@ -8,14 +8,24 @@
"use strict";

const requireIndex = require("requireindex");
const pkg = require("./package.json");

module.exports = {
meta: {
name: pkg.name,
version: pkg.version
},

rules: requireIndex(`${__dirname}/lib/rules`),

// eslint-disable-next-line sort-keys
configs: {
recommended: {
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.",
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.",
"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')`."
].join(" "),
plugins: ["qunit"],
rules: {
"qunit/assert-args": "error",
Expand Down
8 changes: 8 additions & 0 deletions lib/configs/recommended.js
@@ -0,0 +1,8 @@
"use strict";

const plugin = require("../../index.js");

module.exports = {
plugins: { qunit: plugin },
rules: plugin.configs.recommended.rules
};
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -2,7 +2,10 @@
"name": "eslint-plugin-qunit",
"version": "8.0.1",
"description": "ESLint plugin containing rules useful for QUnit tests.",
"exports": "./index.js",
"exports": {
".": "./index.js",
"./configs/*": "./lib/configs/*.js"
},
"main": "./index.js",
"scripts": {
"lint": "npm-run-all --continue-on-error --aggregate-output --parallel lint:*",
Expand Down
31 changes: 23 additions & 8 deletions tests/index.js
Expand Up @@ -11,7 +11,9 @@
const assert = require("chai").assert,
{ rules, configs } = require("../index"),
fs = require("node:fs"),
path = require("node:path");
path = require("node:path"),
requireIndex = require("requireindex"),
plugin = require("../index.js");

//------------------------------------------------------------------------------
// Tests
Expand Down Expand Up @@ -59,13 +61,26 @@ describe("index.js", function () {
});

describe("configs", function () {
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
for (const [configName, config] of Object.entries(configs)) {
describe(configName, function () {
it("has the right plugins", function () {
assert.deepStrictEqual(config.plugins, ["qunit"]);
describe("legacy", function () {
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
for (const [configName, config] of Object.entries(configs)) {
describe(configName, function () {
it("has the right plugins", function () {
assert.deepStrictEqual(config.plugins, ["qunit"]);
});
});
});
}
}
});

describe("flat", function () {
// eslint-disable-next-line mocha/no-setup-in-describe -- rule doesn't like function calls like `Object.entries()`
for (const [configName, config] of Object.entries(requireIndex(`${__dirname}/../lib/configs`))) {
describe(configName, function () {
it("has the right plugins", function () {
assert.deepStrictEqual(config.plugins, { qunit: plugin });
});
});
}
});
});
});

0 comments on commit 51cd143

Please sign in to comment.