feat: replace no only tests with vitest (!2)

This gives us a much more robust configuration for our rules. Additionally, it expects tests to be converted to the `expect` API.

Reviewed-on: https://codeberg.org/nhcarrigan/eslint-config/pulls/2
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
2024-09-26 00:21:31 +00:00
committed by Naomi the Technomancer
parent 9b128c1bf1
commit 883274a3e4
9 changed files with 172 additions and 213 deletions

View File

@ -4,42 +4,27 @@
* @author Naomi Carrigan
*/
import { suite, assert, test } from "vitest";
import { describe, expect, it } from "vitest";
import { disabledEslintRules, eslintRules } from "../src/rules/eslint.ts";
suite("ESLint Configs", () => {
test("should not enable disabled rules", () => {
describe("eslint configs", () => {
it("should not enable disabled rules", () => {
expect.assertions(20);
const disabled = Object.keys(disabledEslintRules);
const enabled = Object.keys(eslintRules);
for (const key of disabled) {
assert.notInclude(
enabled,
key,
`Disabled rule ${key} has been re-enabled!`,
);
expect(enabled, `Disabled rule ${key} has been re-enabled!`).not.toContain(key);
}
});
test("all disabled rules should be off", () => {
it("all disabled rules should be off", () => {
expect.assertions(20);
const rules = Object.entries(disabledEslintRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.strictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.strictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned on - disabled rules should be explicitly turned off.`).toBe("off");
continue;
}
});
});

View File

@ -4,174 +4,83 @@
* @author Naomi Carrigan
*/
import { suite, assert, test } from "vitest";
import { describe, expect, it } from "vitest";
import { eslintRules } from "../src/rules/eslint.ts";
import { importRules } from "../src/rules/import.js";
import { jsdocRules } from "../src/rules/jsdoc.js";
import { noOnlyTestsRules } from "../src/rules/noOnlyTests.js";
import { stylisticRules } from "../src/rules/stylistic.ts";
import { typescriptEslintRules } from "../src/rules/typescriptEslint.js";
import { unicornRules } from "../src/rules/unicorn.js";
import { vitestRules } from "../src/rules/vitest.js";
suite("No rules should be turned off in", () => {
test("eslint rules", () => {
describe("no rules should be turned off in", () => {
it("eslint rules", () => {
expect.assertions(148);
const rules = Object.entries(eslintRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
test("import rules", () => {
it("import rules", () => {
expect.assertions(29);
const rules = Object.entries(importRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
test("jsdoc rules", () => {
it("jsdoc rules", () => {
expect.assertions(43);
const rules = Object.entries(jsdocRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
test("no-only-tests rules", () => {
const rules = Object.entries(noOnlyTestsRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
}
});
test("stylistic rules", () => {
it("stylistic rules", () => {
expect.assertions(65);
const rules = Object.entries(stylisticRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
test("typescript-eslint rules", () => {
it("typescript-eslint rules", () => {
expect.assertions(59);
const rules = Object.entries(typescriptEslintRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
test("unicorn rules", () => {
it("unicorn rules", () => {
expect.assertions(73);
const rules = Object.entries(unicornRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.notStrictEqual(
rule.at(0),
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
if (typeof rule === "string") {
assert.notStrictEqual(
rule,
"off",
`${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
it("vitest rules", () => {
expect.assertions(45);
const rules = Object.entries(vitestRules);
for (const [ name, rule ] of rules) {
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be turned off - this project does not use any external configs, so all rules should be off by default.`).not.toBe("off");
}
});
});

View File

@ -4,30 +4,18 @@
* @author Naomi Carrigan
*/
import { suite, assert, test } from "vitest";
import { describe, expect, it } from "vitest";
import { stylisticRules } from "../src/rules/stylistic.ts";
suite("Stylistic Configs", () => {
test("should never be an error", () => {
describe("stylistic configs", () => {
it("should never be an error", () => {
expect.assertions(65);
const rules = Object.entries(stylisticRules);
for (const [ name, rule ] of rules) {
if (Array.isArray(rule)) {
assert.include(
[ "off", "warn" ],
rule.at(0),
`${name} appears to be set to an error!`,
);
continue;
}
if (typeof rule === "string") {
assert.include(
[ "off", "warn" ],
rule,
`${name} appears to be set to an error!`,
);
continue;
}
assert.fail(`Could not determine rule type for ${name}!`);
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be set to an error!`).not.toBe("error");
continue;
}
});
});

21
test/vitest.spec.ts Normal file
View File

@ -0,0 +1,21 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { describe, expect, it } from "vitest";
import { vitestRules } from "../src/rules/vitest.ts";
describe("vitest configs", () => {
it("should never be an error", () => {
expect.assertions(45);
const rules = Object.entries(vitestRules);
for (const [ name, rule ] of rules) {
expect(Array.isArray(rule)
? rule.at(0)
: rule, `${name} appears to be set to an error!`).not.toBe("error");
continue;
}
});
});