Skip to content

Commit

Permalink
Add eslint-plugin-sort-destructure-keys-typescript and eslint-plugin-…
Browse files Browse the repository at this point in the history
…default-import-name (#3)
  • Loading branch information
nirtamir2 authored Feb 24, 2025
1 parent b9879d8 commit 1f38b71
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 46 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"eslint-plugin-array-func": "^5.0.2",
"eslint-plugin-clsx": "^0.0.10",
"eslint-plugin-command": "^3.1.0",
"eslint-plugin-default-import-name": "^0.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-expect-type": "^0.6.2",
"eslint-plugin-github": "^5.1.8",
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/configs/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
OptionsStylistic,
TypedFlatConfigItem,
} from "../types";
import {ensurePackages, interopDefault} from "../utils";
import { ensurePackages, interopDefault } from "../utils";

export async function astro(
options: OptionsOverrides & OptionsStylistic & OptionsFiles = {},
Expand All @@ -17,7 +17,7 @@ export async function astro(
stylistic = false,
} = options;

await ensurePackages(["eslint-plugin-astro"])
await ensurePackages(["eslint-plugin-astro"]);

const [pluginAstro, parserAstro, parserTs] = await Promise.all([
interopDefault(import("eslint-plugin-astro")),
Expand Down
6 changes: 6 additions & 0 deletions src/configs/default-import-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import defaultImportNameConfig from "eslint-plugin-default-import-name/config";
import type { TypedFlatConfigItem } from "../types";

export async function defaultImportName(): Promise<Array<TypedFlatConfigItem>> {
return [defaultImportNameConfig()];
}
57 changes: 30 additions & 27 deletions src/configs/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,38 @@ export async function formatters(
}

if (options.astro) {
configs.push({
files: [GLOB_ASTRO],
languageOptions: {
parser: parserPlain,
},
name: "antfu/formatter/astro",
rules: {
"format/prettier": [
"error",
{
...prettierOptions,
parser: "astro",
plugins: ["prettier-plugin-astro"],
},
],
configs.push(
{
files: [GLOB_ASTRO],
languageOptions: {
parser: parserPlain,
},
name: "antfu/formatter/astro",
rules: {
"format/prettier": [
"error",
{
...prettierOptions,
parser: "astro",
plugins: ["prettier-plugin-astro"],
},
],
},
},
}, {
files: [GLOB_ASTRO, GLOB_ASTRO_TS],
name: "antfu/formatter/astro/disables",
rules: {
"@stylistic/arrow-parens": "off",
"@stylistic/block-spacing": "off",
"@stylistic/comma-dangle": "off",
"@stylistic/indent": "off",
"@stylistic/no-multi-spaces": "off",
"@stylistic/quotes": "off",
"@stylistic/semi": "off",
{
files: [GLOB_ASTRO, GLOB_ASTRO_TS],
name: "antfu/formatter/astro/disables",
rules: {
"@stylistic/arrow-parens": "off",
"@stylistic/block-spacing": "off",
"@stylistic/comma-dangle": "off",
"@stylistic/indent": "off",
"@stylistic/no-multi-spaces": "off",
"@stylistic/quotes": "off",
"@stylistic/semi": "off",
},
},
});
);
}

if (options.graphql) {
Expand Down
2 changes: 1 addition & 1 deletion src/configs/ignores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function ignores(): Promise<Array<TypedFlatConfigItem>> {
{
ignores: GLOB_EXCLUDE,
// Awaits https://github.com/humanwhocodes/config-array/pull/131
name: 'antfu/ignores',
name: "antfu/ignores",
},
];
}
14 changes: 7 additions & 7 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export async function react(
allowExportNames: [
...(isUsingNext
? [
'dynamic',
'dynamicParams',
'revalidate',
'fetchCache',
'runtime',
'preferredRegion',
'maxDuration',
"dynamic",
"dynamicParams",
"revalidate",
"fetchCache",
"runtime",
"preferredRegion",
"maxDuration",
"config",
"generateStaticParams",
"metadata",
Expand Down
8 changes: 6 additions & 2 deletions src/configs/tsdoc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { compat } from "../compat";
import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, TypedFlatConfigItem } from "../types";

import type {
OptionsComponentExts,
OptionsFiles,
OptionsOverrides,
TypedFlatConfigItem,
} from "../types";

export async function tsdoc(
options: OptionsFiles & OptionsComponentExts & OptionsOverrides = {},
Expand Down
5 changes: 3 additions & 2 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import expectType from "eslint-plugin-expect-type/configs/recommended";
import tseslint from "typescript-eslint";
import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from "../globs";
import { pluginAntfu, pluginSortDestructureKeysTypescript } from "../plugins";
import sortDestructureKeysTypescriptConfig from "eslint-plugin-sort-destructure-keys-typescript/config";
import { pluginAntfu } from "../plugins";
import type {
OptionsComponentExts,
OptionsFiles,
Expand Down Expand Up @@ -103,7 +104,6 @@ export async function typescript(
name: "antfu/typescript/setup",
plugins: {
antfu: pluginAntfu,
"sort-destructure-keys-typescript": pluginSortDestructureKeysTypescript,
// "@typescript-eslint": pluginTs as any,
},
},
Expand Down Expand Up @@ -172,6 +172,7 @@ export async function typescript(
},
...(isTypeAware
? [
sortDestructureKeysTypescriptConfig(),
{
files: filesTypeAware,
ignores: ignoresTypeAware,
Expand Down
2 changes: 1 addition & 1 deletion src/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function vue(
vueVersion = 3,
} = options;

const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {};
const sfcBlocks = options.sfcBlocks === true ? {} : (options.sfcBlocks ?? {});

const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic;

Expand Down
2 changes: 2 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
vue,
yaml,
} from "./configs";
import { defaultImportName } from "./configs/default-import-name";
import { formatters } from "./configs/formatters";
import { i18n } from "./configs/i18n";
import { prettier } from "./configs/prettier";
Expand Down Expand Up @@ -183,6 +184,7 @@ export function nirtamir2(
stylistic: stylisticOptions,
}),
unicorn(),
defaultImportName(),
command(),

// Optional plugins (installed but not enabled by default)
Expand Down
1 change: 0 additions & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// @ts-nocheck

export { default as pluginAntfu } from "eslint-plugin-antfu";
export { default as pluginSortDestructureKeysTypescript } from "eslint-plugin-sort-destructure-keys-typescript";
export { default as pluginComments } from "eslint-plugin-eslint-comments";
export * as pluginImport from "eslint-plugin-import-x";
export { default as pluginNode } from "eslint-plugin-n";
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ export interface OptionsStylistic {
}

export type StylisticConfig = Pick<
StylisticCustomizeOptions,
"indent" | "quotes" | "jsx" | "semi"
>
StylisticCustomizeOptions,
"indent" | "quotes" | "jsx" | "semi"
>;

export interface OptionsOverrides {
overrides?: TypedFlatConfigItem["rules"];
Expand Down

0 comments on commit 1f38b71

Please sign in to comment.