Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ESLint flat config #443

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 });
});
});
}
});
});
});