Skip to content

Commit

Permalink
feat: ✨ add eslint-comments rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Nov 2, 2024
1 parent b4a524a commit 268d6d8
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 46 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"prettier": "@jimmy.codes/prettier-config",
"dependencies": {
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
"@eslint/js": "^9.14.0",
"@tanstack/eslint-plugin-query": "^5.59.7",
"@types/eslint": "9.6.1",
Expand Down
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/configs/eslint-comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";

import { eslintCommentsRules } from "../rules/eslint-comments";

const eslintCommentsConfig = () => {
return [
{
...comments.recommended,
name: "jimmy.codes/eslint-comments",
rules: eslintCommentsRules,
},
];
};

export default eslintCommentsConfig;
7 changes: 4 additions & 3 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vi.mock("local-pkg");

describe("jimmyDotCodes", () => {
describe("base", () => {
it.each(["node", "imports", "perfectionist", "unicorn"])(
it.each(["node", "imports", "perfectionist", "unicorn", "eslint-comments"])(
"should create configuration w/ %s",
(input) => {
expect(jimmyDotCodes({ autoDetect: false })).toStrictEqual(
Expand All @@ -17,6 +17,7 @@ describe("jimmyDotCodes", () => {
},
);
});

it("should create configuration w/ typescript", () => {
expect(
jimmyDotCodes({ autoDetect: false, typescript: true }),
Expand Down Expand Up @@ -179,7 +180,7 @@ describe("jimmyDotCodes", () => {

it("should include react-query when auto detection is enabled", () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "react" || name === "@tanstack/react-query";
});

Expand Down Expand Up @@ -240,7 +241,7 @@ describe("jimmyDotCodes", () => {

it("should include test-library when auto detection is enabled", () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "@testing-library/react" || name === "vitest";
});

Expand Down
2 changes: 2 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Options, TypedConfigItem } from "./types";

import { astroConfig } from "./configs/astro";
import { commonjsConfig } from "./configs/commonjs";
import eslintCommentsConfig from "./configs/eslint-comments";
import importsConfig from "./configs/imports";
import nodeConfig from "./configs/node";
import perfectionistConfig from "./configs/perfectionist";
Expand Down Expand Up @@ -44,6 +45,7 @@ export const jimmyDotCodes = (
...perfectionistConfig(),
...nodeConfig(),
...unicornConfig(),
...eslintCommentsConfig(),
...importsConfig({ typescript: isTypescriptEnabled }),
...(isTypescriptEnabled
? typescriptConfig(getTypescriptOptions(typescript))
Expand Down
97 changes: 97 additions & 0 deletions src/rules.gen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@
import type { Linter } from 'eslint'

export interface RuleOptions {
/**
* require a `eslint-enable` comment for every `eslint-disable` comment
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html
*/
"@eslint-community/eslint-comments/disable-enable-pair"?: Linter.RuleEntry<EslintCommunityEslintCommentsDisableEnablePair>;
/**
* disallow a `eslint-enable` comment for multiple `eslint-disable` comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html
*/
"@eslint-community/eslint-comments/no-aggregating-enable"?: Linter.RuleEntry<
[]
>;
/**
* disallow duplicate `eslint-disable` comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html
*/
"@eslint-community/eslint-comments/no-duplicate-disable"?: Linter.RuleEntry<
[]
>;
/**
* disallow `eslint-disable` comments about specific rules
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html
*/
"@eslint-community/eslint-comments/no-restricted-disable"?: Linter.RuleEntry<EslintCommunityEslintCommentsNoRestrictedDisable>;
/**
* disallow `eslint-disable` comments without rule names
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html
*/
"@eslint-community/eslint-comments/no-unlimited-disable"?: Linter.RuleEntry<
[]
>;
/**
* disallow unused `eslint-disable` comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html
*/
"@eslint-community/eslint-comments/no-unused-disable"?: Linter.RuleEntry<[]>;
/**
* disallow unused `eslint-enable` comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html
*/
"@eslint-community/eslint-comments/no-unused-enable"?: Linter.RuleEntry<[]>;
/**
* disallow ESLint directive-comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html
*/
"@eslint-community/eslint-comments/no-use"?: Linter.RuleEntry<EslintCommunityEslintCommentsNoUse>;
/**
* require include descriptions in ESLint directive-comments
* @see https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html
*/
"@eslint-community/eslint-comments/require-description"?: Linter.RuleEntry<EslintCommunityEslintCommentsRequireDescription>;
/**
* Exhaustive deps rule for useQuery
* @see https://tanstack.com/query/latest/docs/eslint/exhaustive-deps
Expand Down Expand Up @@ -4952,6 +5003,52 @@ export interface RuleOptions {
}

/* ======= Declarations ======= */
// ----- @eslint-community/eslint-comments/disable-enable-pair -----
type EslintCommunityEslintCommentsDisableEnablePair =
| []
| [
{
allowWholeFile?: boolean;
},
];
// ----- @eslint-community/eslint-comments/no-restricted-disable -----
type EslintCommunityEslintCommentsNoRestrictedDisable = string[];
// ----- @eslint-community/eslint-comments/no-use -----
type EslintCommunityEslintCommentsNoUse =
| []
| [
{
allow?: (
| "eslint"
| "eslint-disable"
| "eslint-disable-line"
| "eslint-disable-next-line"
| "eslint-enable"
| "eslint-env"
| "exported"
| "global"
| "globals"
)[];
},
];
// ----- @eslint-community/eslint-comments/require-description -----
type EslintCommunityEslintCommentsRequireDescription =
| []
| [
{
ignore?: (
| "eslint"
| "eslint-disable"
| "eslint-disable-line"
| "eslint-disable-next-line"
| "eslint-enable"
| "eslint-env"
| "exported"
| "global"
| "globals"
)[];
},
];
// ----- @typescript-eslint/array-type -----
type TypescriptEslintArrayType =
| []
Expand Down
12 changes: 12 additions & 0 deletions src/rules/__snapshots__/eslint-comments.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should create eslintComments rules 1`] = `
{
"@eslint-community/eslint-comments/disable-enable-pair": "error",
"@eslint-community/eslint-comments/no-aggregating-enable": "error",
"@eslint-community/eslint-comments/no-duplicate-disable": "error",
"@eslint-community/eslint-comments/no-unlimited-disable": "error",
"@eslint-community/eslint-comments/no-unused-enable": "error",
"@eslint-community/eslint-comments/require-description": "error",
}
`;
5 changes: 5 additions & 0 deletions src/rules/eslint-comments.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { eslintCommentsRules } from "./eslint-comments";

test("should create eslintComments rules", () => {
expect(eslintCommentsRules).toMatchSnapshot();
});
8 changes: 8 additions & 0 deletions src/rules/eslint-comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs";

import type { Rules } from "../types";

export const eslintCommentsRules = {
...comments.recommended.rules,
"@eslint-community/eslint-comments/require-description": "error",
} satisfies Rules;
Loading

0 comments on commit 268d6d8

Please sign in to comment.