generated from nhcarrigan/template
feat: add rules for eslint-disable directives (#11)
### Explanation _No response_ ### Issue _No response_ ### Attestations - [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [x] I have pinned the dependencies to a specific patch version. ### Style - [x] I have run the linter and resolved any errors. - [x] My pull request uses an appropriate title, matching the conventional commit standards. - [x] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [x] My contribution adds new code, and I have added tests to cover it. - [x] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [x] All new and existing tests pass locally with my changes. - [x] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning Minor - My pull request introduces a new non-breaking feature. Reviewed-on: https://codeberg.org/nhcarrigan/eslint-config/pulls/11 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
parent
75d02a9931
commit
39e29181a0
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -2,5 +2,11 @@
|
|||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": "explicit"
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
"eslint.validate": ["typescript"]
|
"eslint.validate": [
|
||||||
|
"typescript"
|
||||||
|
],
|
||||||
|
"sonarlint.connectedMode.project": {
|
||||||
|
"connectionId": "nhcarrigan",
|
||||||
|
"projectKey": "nhcarrigan_eslint-config"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://codeberg.org/naomi-lgbt/eslint-config",
|
"homepage": "https://codeberg.org/naomi-lgbt/eslint-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@eslint-community/eslint-plugin-eslint-comments": "4.4.1",
|
||||||
"@eslint/compat": "1.2.4",
|
"@eslint/compat": "1.2.4",
|
||||||
"@eslint/eslintrc": "3.2.0",
|
"@eslint/eslintrc": "3.2.0",
|
||||||
"@eslint/js": "9.16.0",
|
"@eslint/js": "9.16.0",
|
||||||
|
15
pnpm-lock.yaml
generated
15
pnpm-lock.yaml
generated
@ -8,6 +8,9 @@ importers:
|
|||||||
|
|
||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@eslint-community/eslint-plugin-eslint-comments':
|
||||||
|
specifier: 4.4.1
|
||||||
|
version: 4.4.1(eslint@9.7.0)
|
||||||
'@eslint/compat':
|
'@eslint/compat':
|
||||||
specifier: 1.2.4
|
specifier: 1.2.4
|
||||||
version: 1.2.4(eslint@9.7.0)
|
version: 1.2.4(eslint@9.7.0)
|
||||||
@ -239,6 +242,12 @@ packages:
|
|||||||
cpu: [x64]
|
cpu: [x64]
|
||||||
os: [win32]
|
os: [win32]
|
||||||
|
|
||||||
|
'@eslint-community/eslint-plugin-eslint-comments@4.4.1':
|
||||||
|
resolution: {integrity: sha512-lb/Z/MzbTf7CaVYM9WCFNQZ4L1yi3ev2fsFPF99h31ljhSEyUoyEsKsNWiU+qD1glbYTDJdqgyaLKtyTkkqtuQ==}
|
||||||
|
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||||
|
peerDependencies:
|
||||||
|
eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0
|
||||||
|
|
||||||
'@eslint-community/eslint-utils@4.4.0':
|
'@eslint-community/eslint-utils@4.4.0':
|
||||||
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==}
|
||||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||||
@ -1981,6 +1990,12 @@ snapshots:
|
|||||||
'@esbuild/win32-x64@0.21.5':
|
'@esbuild/win32-x64@0.21.5':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
'@eslint-community/eslint-plugin-eslint-comments@4.4.1(eslint@9.7.0)':
|
||||||
|
dependencies:
|
||||||
|
escape-string-regexp: 4.0.0
|
||||||
|
eslint: 9.7.0
|
||||||
|
ignore: 5.3.1
|
||||||
|
|
||||||
'@eslint-community/eslint-utils@4.4.0(eslint@9.7.0)':
|
'@eslint-community/eslint-utils@4.4.0(eslint@9.7.0)':
|
||||||
dependencies:
|
dependencies:
|
||||||
eslint: 9.7.0
|
eslint: 9.7.0
|
||||||
|
15
src/index.ts
15
src/index.ts
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { fixupPluginRules } from "@eslint/compat";
|
import { fixupPluginRules } from "@eslint/compat";
|
||||||
|
import comments from "@eslint-community/eslint-plugin-eslint-comments";
|
||||||
import stylistic from "@stylistic/eslint-plugin";
|
import stylistic from "@stylistic/eslint-plugin";
|
||||||
import tslint from "@typescript-eslint/eslint-plugin";
|
import tslint from "@typescript-eslint/eslint-plugin";
|
||||||
import parser from "@typescript-eslint/parser";
|
import parser from "@typescript-eslint/parser";
|
||||||
@ -17,6 +18,7 @@ import react from "eslint-plugin-react";
|
|||||||
import sortKeysFix from "eslint-plugin-sort-keys-fix";
|
import sortKeysFix from "eslint-plugin-sort-keys-fix";
|
||||||
import unicorn from "eslint-plugin-unicorn";
|
import unicorn from "eslint-plugin-unicorn";
|
||||||
import globals from "globals";
|
import globals from "globals";
|
||||||
|
import { commentsRules } from "./rules/comments.js";
|
||||||
import { deprecationRules } from "./rules/deprecation.js";
|
import { deprecationRules } from "./rules/deprecation.js";
|
||||||
import { disabledEslintRules, eslintRules } from "./rules/eslint.js";
|
import { disabledEslintRules, eslintRules } from "./rules/eslint.js";
|
||||||
import { importRules } from "./rules/import.js";
|
import { importRules } from "./rules/import.js";
|
||||||
@ -50,6 +52,8 @@ const config: Array<Linter.Config> = [
|
|||||||
plugins: {
|
plugins: {
|
||||||
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
||||||
"@typescript-eslint": tslint,
|
"@typescript-eslint": tslint,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Not unsafe, just not typed.
|
||||||
|
"comments": comments,
|
||||||
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
|
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
|
||||||
"deprecation": fixupPluginRules(deprecation),
|
"deprecation": fixupPluginRules(deprecation),
|
||||||
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
||||||
@ -70,6 +74,7 @@ const config: Array<Linter.Config> = [
|
|||||||
...stylisticRules,
|
...stylisticRules,
|
||||||
...unicornRules,
|
...unicornRules,
|
||||||
...sortKeysFixRules,
|
...sortKeysFixRules,
|
||||||
|
...commentsRules,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// #endregion
|
// #endregion
|
||||||
@ -90,6 +95,8 @@ const config: Array<Linter.Config> = [
|
|||||||
plugins: {
|
plugins: {
|
||||||
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
||||||
"@typescript-eslint": tslint,
|
"@typescript-eslint": tslint,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Not unsafe, just not typed.
|
||||||
|
"comments": comments,
|
||||||
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
||||||
"jsdoc": jsdoc,
|
"jsdoc": jsdoc,
|
||||||
"sort-keys-fix": sortKeysFix as ESLint.Plugin,
|
"sort-keys-fix": sortKeysFix as ESLint.Plugin,
|
||||||
@ -108,6 +115,7 @@ const config: Array<Linter.Config> = [
|
|||||||
...stylisticRules,
|
...stylisticRules,
|
||||||
...unicornRules,
|
...unicornRules,
|
||||||
...sortKeysFixRules,
|
...sortKeysFixRules,
|
||||||
|
...commentsRules,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// #endregion
|
// #endregion
|
||||||
@ -128,10 +136,11 @@ const config: Array<Linter.Config> = [
|
|||||||
plugins: {
|
plugins: {
|
||||||
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
||||||
"@typescript-eslint": tslint,
|
"@typescript-eslint": tslint,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Not unsafe, just not typed.
|
||||||
|
"comments": comments,
|
||||||
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
||||||
"jsdoc": jsdoc,
|
"jsdoc": jsdoc,
|
||||||
"playwright": playwright,
|
"playwright": playwright,
|
||||||
|
|
||||||
"sort-keys-fix": sortKeysFix 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
|
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
|
||||||
"stylistic": fixupPluginRules(stylistic),
|
"stylistic": fixupPluginRules(stylistic),
|
||||||
@ -147,6 +156,7 @@ const config: Array<Linter.Config> = [
|
|||||||
...stylisticRules,
|
...stylisticRules,
|
||||||
...unicornRules,
|
...unicornRules,
|
||||||
...sortKeysFixRules,
|
...sortKeysFixRules,
|
||||||
|
...commentsRules,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// #endregion
|
// #endregion
|
||||||
@ -172,6 +182,8 @@ const config: Array<Linter.Config> = [
|
|||||||
plugins: {
|
plugins: {
|
||||||
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
// @ts-expect-error It's a config. It's just not the narrow config. SMH.
|
||||||
"@typescript-eslint": tslint,
|
"@typescript-eslint": tslint,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Not unsafe, just not typed.
|
||||||
|
"comments": comments,
|
||||||
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
|
// @ts-expect-error They haven't typedef this yet because it technically doesn't support eslint9
|
||||||
"deprecation": fixupPluginRules(deprecation),
|
"deprecation": fixupPluginRules(deprecation),
|
||||||
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
"import": fixupPluginRules(importPlugin as ESLint.Plugin),
|
||||||
@ -194,6 +206,7 @@ const config: Array<Linter.Config> = [
|
|||||||
...unicornRules,
|
...unicornRules,
|
||||||
...sortKeysFixRules,
|
...sortKeysFixRules,
|
||||||
...reactRules,
|
...reactRules,
|
||||||
|
...commentsRules,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
12
src/rules/comments.ts
Normal file
12
src/rules/comments.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { Linter } from "eslint";
|
||||||
|
|
||||||
|
export const commentsRules: Linter.RulesRecord = {
|
||||||
|
"comments/no-unlimited-disable": "warn",
|
||||||
|
"comments/require-description": "warn",
|
||||||
|
};
|
1
src/types.d.ts
vendored
1
src/types.d.ts
vendored
@ -7,3 +7,4 @@
|
|||||||
declare module "eslint-plugin-no-only-tests";
|
declare module "eslint-plugin-no-only-tests";
|
||||||
declare module "eslint-plugin-import";
|
declare module "eslint-plugin-import";
|
||||||
declare module "eslint-plugin-sort-keys-fix";
|
declare module "eslint-plugin-sort-keys-fix";
|
||||||
|
declare module "@eslint-community/eslint-plugin-eslint-comments";
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import config from "../src/index.ts";
|
import config from "../src/index.ts";
|
||||||
|
import { commentsRules } from "../src/rules/comments.ts";
|
||||||
import { deprecationRules } from "../src/rules/deprecation.ts";
|
import { deprecationRules } from "../src/rules/deprecation.ts";
|
||||||
import { eslintRules } from "../src/rules/eslint.ts";
|
import { eslintRules } from "../src/rules/eslint.ts";
|
||||||
import { importRules } from "../src/rules/import.ts";
|
import { importRules } from "../src/rules/import.ts";
|
||||||
@ -39,7 +40,7 @@ expect.extend({
|
|||||||
const pass = missingRules.length === 0 && mismatchedRules.length === 0;
|
const pass = missingRules.length === 0 && mismatchedRules.length === 0;
|
||||||
|
|
||||||
let message = "";
|
let message = "";
|
||||||
// eslint-disable-next-line no-negated-condition
|
// eslint-disable-next-line no-negated-condition -- This is a test.
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
message = `${message}Expected rules to contain all specified rules.\n`;
|
message = `${message}Expected rules to contain all specified rules.\n`;
|
||||||
if (missingRules.length > 0) {
|
if (missingRules.length > 0) {
|
||||||
@ -121,13 +122,14 @@ const baseProperties = (
|
|||||||
ruleset?.rules,
|
ruleset?.rules,
|
||||||
"missing typescript-eslint rules with types",
|
"missing typescript-eslint rules with types",
|
||||||
).toContainRules(typescriptEslintRulesWithTypes);
|
).toContainRules(typescriptEslintRulesWithTypes);
|
||||||
|
expect(ruleset?.rules, "missing comment rules").toContainRules(commentsRules);
|
||||||
};
|
};
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
describe("global config", () => {
|
describe("global config", () => {
|
||||||
// #region Typescript
|
// #region Typescript
|
||||||
it("should apply the expected plugins for typescript", () => {
|
it("should apply the expected plugins for typescript", () => {
|
||||||
expect.assertions(26);
|
expect.assertions(27);
|
||||||
const ruleset = config.find((rule) => {
|
const ruleset = config.find((rule) => {
|
||||||
return rule?.files?.includes("src/**/*.ts");
|
return rule?.files?.includes("src/**/*.ts");
|
||||||
});
|
});
|
||||||
@ -159,13 +161,13 @@ describe("global config", () => {
|
|||||||
expect(
|
expect(
|
||||||
Object.keys(ruleset?.plugins ?? {}),
|
Object.keys(ruleset?.plugins ?? {}),
|
||||||
"should not have extraneous plugins",
|
"should not have extraneous plugins",
|
||||||
).toHaveLength(7);
|
).toHaveLength(8);
|
||||||
});
|
});
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Vitest
|
// #region Vitest
|
||||||
it("should apply the expected plugins for vitest files", () => {
|
it("should apply the expected plugins for vitest files", () => {
|
||||||
expect.assertions(26);
|
expect.assertions(27);
|
||||||
const ruleset = config.find((rule) => {
|
const ruleset = config.find((rule) => {
|
||||||
return rule?.files?.includes("test/**/*.spec.ts");
|
return rule?.files?.includes("test/**/*.spec.ts");
|
||||||
});
|
});
|
||||||
@ -192,13 +194,13 @@ describe("global config", () => {
|
|||||||
expect(
|
expect(
|
||||||
Object.keys(ruleset?.plugins ?? {}),
|
Object.keys(ruleset?.plugins ?? {}),
|
||||||
"should not have extraneous plugins",
|
"should not have extraneous plugins",
|
||||||
).toHaveLength(7);
|
).toHaveLength(8);
|
||||||
});
|
});
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Playwright
|
// #region Playwright
|
||||||
it("should apply the expected plugins for playwright", () => {
|
it("should apply the expected plugins for playwright", () => {
|
||||||
expect.assertions(26);
|
expect.assertions(27);
|
||||||
const ruleset = config.find((rule) => {
|
const ruleset = config.find((rule) => {
|
||||||
return rule?.files?.includes("e2e/**/*.spec.ts");
|
return rule?.files?.includes("e2e/**/*.spec.ts");
|
||||||
});
|
});
|
||||||
@ -228,13 +230,13 @@ describe("global config", () => {
|
|||||||
expect(
|
expect(
|
||||||
Object.keys(ruleset?.plugins ?? {}),
|
Object.keys(ruleset?.plugins ?? {}),
|
||||||
"should not have extraneous plugins",
|
"should not have extraneous plugins",
|
||||||
).toHaveLength(7);
|
).toHaveLength(8);
|
||||||
});
|
});
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region React
|
// #region React
|
||||||
it("should apply the expected plugins for react", () => {
|
it("should apply the expected plugins for react", () => {
|
||||||
expect.assertions(26);
|
expect.assertions(27);
|
||||||
const ruleset = config.find((rule) => {
|
const ruleset = config.find((rule) => {
|
||||||
return rule?.files?.includes("src/**/*.tsx");
|
return rule?.files?.includes("src/**/*.tsx");
|
||||||
});
|
});
|
||||||
@ -262,7 +264,7 @@ describe("global config", () => {
|
|||||||
expect(
|
expect(
|
||||||
Object.keys(ruleset?.plugins ?? {}),
|
Object.keys(ruleset?.plugins ?? {}),
|
||||||
"should not have extraneous plugins",
|
"should not have extraneous plugins",
|
||||||
).toHaveLength(8);
|
).toHaveLength(9);
|
||||||
});
|
});
|
||||||
// #endregion
|
// #endregion
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user