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
+6 -6
View File
@@ -8,10 +8,10 @@ import { fixupPluginRules } from "@eslint/compat";
import stylistic from "@stylistic/eslint-plugin";
import tslint from "@typescript-eslint/eslint-plugin";
import parser from "@typescript-eslint/parser";
import vitest from "@vitest/eslint-plugin";
import deprecation from "eslint-plugin-deprecation";
import importPlugin from "eslint-plugin-import";
import jsdoc from "eslint-plugin-jsdoc";
import noOnlyTests from "eslint-plugin-no-only-tests";
import sortKeysFix from "eslint-plugin-sort-keys-fix";
import unicorn from "eslint-plugin-unicorn";
import globals from "globals";
@@ -19,12 +19,12 @@ import { deprecationRules } from "./rules/deprecation.js";
import { disabledEslintRules, eslintRules } from "./rules/eslint.js";
import { importRules } from "./rules/import.js";
import { jsdocRules } from "./rules/jsdoc.js";
import { noOnlyTestsRules } from "./rules/noOnlyTests.js";
import { sortKeysFixRules } from "./rules/sortKeysFix.js";
import { stylisticRules } from "./rules/stylistic.js";
import { typescriptEslintRules, typescriptEslintRulesWithTypes }
from "./rules/typescriptEslint.js";
import { unicornRules } from "./rules/unicorn.js";
import { vitestRules } from "./rules/vitest.js";
import type { ESLint, Linter } from "eslint";
const config: Array<Linter.Config> = [
@@ -49,24 +49,24 @@ const config: Array<Linter.Config> = [
"deprecation": fixupPluginRules(deprecation),
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
"jsdoc": jsdoc,
"no-only-tests": noOnlyTests as ESLint.Plugin,
"sort-keys-fix": sortKeysFix as ESLint.Plugin,
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
"stylistic": fixupPluginRules(stylistic),
"unicorn": unicorn,
"vitest": vitest,
},
rules: {
...eslintRules,
...disabledEslintRules,
...typescriptEslintRules,
...typescriptEslintRulesWithTypes,
...noOnlyTestsRules,
...importRules,
...jsdocRules,
...deprecationRules,
...stylisticRules,
...unicornRules,
...sortKeysFixRules,
...vitestRules,
},
},
{
@@ -86,17 +86,17 @@ const config: Array<Linter.Config> = [
"@typescript-eslint": tslint,
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
"jsdoc": jsdoc,
"no-only-tests": noOnlyTests as ESLint.Plugin,
"sort-keys-fix": sortKeysFix as ESLint.Plugin,
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
"stylistic": fixupPluginRules(stylistic),
"unicorn": unicorn,
"vitest": vitest,
},
rules: {
...eslintRules,
...disabledEslintRules,
...typescriptEslintRules,
...noOnlyTestsRules,
...vitestRules,
...importRules,
...jsdocRules,
...stylisticRules,
-17
View File
@@ -1,17 +0,0 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Linter } from "eslint";
export const noOnlyTestsRules: Linter.RulesRecord = {
"no-only-tests/no-only-tests": [
"warn",
{
block: [ "test", "expect", "assert", "describe", "bench" ],
focus: [ "only", "skip" ],
},
],
};
+57
View File
@@ -0,0 +1,57 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { Linter } from "eslint";
export const vitestRules: Linter.RulesRecord = {
"vitest/consistent-test-filename":
[ "warn", { pattern: /^[\da-z-]+\.spec\.ts$/ } ],
"vitest/consistent-test-it": "warn",
"vitest/expect-expect": "warn",
"vitest/max-nested-describe": [ "warn", { max: 2 } ],
"vitest/no-alias-methods": "warn",
"vitest/no-commented-out-tests": "warn",
"vitest/no-conditional-expect": "warn",
"vitest/no-conditional-in-test": "warn",
"vitest/no-conditional-tests": "warn",
"vitest/no-disabled-tests": "warn",
"vitest/no-done-callback": "warn",
"vitest/no-duplicate-hooks": "warn",
"vitest/no-focused-tests": "warn",
"vitest/no-identical-title": "warn",
"vitest/no-import-node-test": "warn",
"vitest/no-interpolation-in-snapshots": "warn",
"vitest/no-restricted-vi-methods": "warn",
"vitest/no-standalone-expect": "warn",
"vitest/no-test-prefixes": "warn",
"vitest/no-test-return-statement": "warn",
"vitest/prefer-called-with": "warn",
"vitest/prefer-comparison-matcher": "warn",
"vitest/prefer-each": "warn",
"vitest/prefer-equality-matcher": "warn",
"vitest/prefer-expect-assertions": "warn",
"vitest/prefer-expect-resolves": "warn",
"vitest/prefer-hooks-in-order": "warn",
"vitest/prefer-hooks-on-top": "warn",
"vitest/prefer-lowercase-title": "warn",
"vitest/prefer-mock-promise-shorthand": "warn",
"vitest/prefer-spy-on": "warn",
"vitest/prefer-strict-equal": "warn",
"vitest/prefer-to-be": "warn",
"vitest/prefer-to-be-falsy": "warn",
"vitest/prefer-to-be-object": "warn",
"vitest/prefer-to-be-truthy": "warn",
"vitest/prefer-to-contain": "warn",
"vitest/prefer-to-have-length": "warn",
"vitest/prefer-todo": "warn",
"vitest/require-hook": "warn",
"vitest/require-to-throw-message": "warn",
"vitest/require-top-level-describe": "warn",
"vitest/valid-describe-callback": "warn",
"vitest/valid-expect":
[ "warn", { maxArgs: 2, minArgs: 2 } ],
"vitest/valid-title": "warn",
};