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

test: Ensure all rules are exported #53

Merged
merged 2 commits into from
Nov 12, 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
37 changes: 37 additions & 0 deletions tests/package/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

import * as exports from "../../src/index.js";
import assert from "node:assert";
import path from "node:path";
import fs from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";

//-----------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const rulesDir = path.resolve(dirname, "../../src/rules");

//------------------------------------------------------------------------------
// Tests
Expand All @@ -24,6 +35,32 @@ describe("Package exports", () => {
]);
});

it("has all available rules exported in the ESLint plugin", async () => {
const allRules = (await fs.readdir(rulesDir))
.filter(name => name.endsWith(".js"))
.map(name => name.slice(0, -".js".length))
.sort();
const exportedRules = exports.default.rules;

assert.deepStrictEqual(
Object.keys(exportedRules).sort(),
allRules,
"Expected all rules to be exported in the ESLint plugin (`plugin.rules` in `src/index.js`)",
);

for (const [ruleName, rule] of Object.entries(exportedRules)) {
assert.strictEqual(
rule,
(
await import(
pathToFileURL(path.resolve(rulesDir, `${ruleName}.js`))
)
).default,
`Expected ${ruleName}.js to be exported under key "${ruleName}" in the ESLint plugin (\`plugin.rules\` in \`src/index.js\`)`,
);
}
});

it("has a JSONLanguage export", () => {
assert.ok(exports.JSONLanguage);
});
Expand Down
19 changes: 19 additions & 0 deletions tests/plugin/eslint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ import dedent from "dedent";
//-----------------------------------------------------------------------------

describe("when the plugin is used with ESLint", () => {
describe("plugin configs", () => {
Object.keys(json.configs).forEach(configName => {
it(`Using "${configName}" config should not throw`, async () => {
const config = {
files: ["**/*.json"],
language: "json/json",
...json.configs[configName],
};

const eslint = new ESLint({
overrideConfigFile: true,
overrideConfig: config,
});

await eslint.lintText("{}", { filePath: "test.json" });
});
});
});

describe("config comments", () => {
["jsonc", "json5"].forEach(language => {
describe(`with ${language} language`, () => {
Expand Down