Skip to content

Commit

Permalink
lint: migrate to ESLint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Oct 18, 2024
1 parent acf75fe commit bb7581f
Show file tree
Hide file tree
Showing 48 changed files with 815 additions and 1,869 deletions.
9 changes: 0 additions & 9 deletions apps/docs/.eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion apps/docs/app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ function Why(): React.ReactElement {
>
{new Array(10).fill(0).map((_, i) => (
<div
// eslint-disable-next-line react/no-array-index-key -- static
key={i}
className="absolute -left-20 top-0 z-[-1] h-[1000px] max-h-[100vw] origin-top-right rotate-45 bg-gradient-to-b from-primary blur-xl"
style={{
Expand Down
1 change: 0 additions & 1 deletion apps/docs/app/(home)/sponsors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export default async function Page(): Promise<ReactNode> {
strokeWidth="0.5"
/>
{new Array(3).fill(null).map((_, i) => (
// eslint-disable-next-line react/no-array-index-key -- safe
<Fragment key={i}>
<rect
x="368"
Expand Down
3 changes: 1 addition & 2 deletions apps/docs/components/ai/search-ai.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let session: AnswerSession | undefined;
export function AIDialog(): React.ReactElement {
const [message, setMessage] = useState('');
const [loading, setLoading] = useState(false);
// eslint-disable-next-line react/hook-use-state -- rerender

const [_, update] = useState<unknown>();
const shouldFocus = useRef(false); // should focus on input on next render
const [relatedQueries, setRelatedQueries] = useState<string[]>([]);
Expand Down Expand Up @@ -166,7 +166,6 @@ export function AIDialog(): React.ReactElement {
<>
<List className={cn(messages.length === 0 && 'hidden')}>
{messages.map((item, i) => (
// eslint-disable-next-line react/no-array-index-key -- safe
<Message key={i} {...item}>
{!loading &&
item.role === 'assistant' &&
Expand Down
22 changes: 22 additions & 0 deletions apps/docs/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import next from 'eslint-config-custom/next.js';

export default [
{
ignores: [
'dist',
'node_modules',
'.next/',
'out/',
'next.config.mjs',
'postcss.config.js',
],
},
...next,
{
rules: {
'no-console': 'off',
// for Fumadocs CLI
'import/no-relative-packages': 'off',
},
},
];
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,21 @@
"types:check": "turbo run types:check",
"version": "changeset version && pnpm install --lockfile-only"
},
"prettier": "@vercel/style-guide/prettier",
"devDependencies": {
"@changesets/cli": "^2.27.9",
"@typescript-eslint/eslint-plugin": "^8.9.0",
"@typescript-eslint/parser": "^8.9.0",
"@vercel/style-guide": "^6.0.0",
"@eslint/js": "^9.12.0",
"@types/eslint__js": "^8.42.3",
"concurrently": "^9.0.1",
"eslint": "^8.57.1",
"eslint": "^9.12.0",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "5.1.0-rc-bf7e210c-20241017",
"eslint-plugin-tailwindcss": "^3.17.5",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"tsup": "8.3.0",
"turbo": "2.1.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.10.0",
"vitest": "^2.1.3"
},
"packageManager": "[email protected]",
Expand Down
7 changes: 0 additions & 7 deletions packages/cli/.eslintrc.cjs

This file was deleted.

13 changes: 13 additions & 0 deletions packages/cli/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import library from 'eslint-config-custom/library.js';

export default [
{
ignores: ['dist', 'node_modules', 'test/repo', 'test/repo-2'],
},
...library,
{
rules: {
'import/no-relative-packages': 'off',
},
},
];
2 changes: 1 addition & 1 deletion packages/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function loadConfig(file = './cli.json'): Promise<Config> {
const content = await fs.readFile(file);

return JSON.parse(content.toString()) as Config;
} catch (_) {
} catch {
return {};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ program

try {
nodes = JSON.parse(str ?? '') as JsonTreeNode[];
} catch (e) {
} catch {
nodes = await runTree(str ?? './');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/i18n/transform-layout-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function transformLayoutConfig(

try {
content = await fs.readFile(filePath).then((res) => res.toString());
} catch (_) {
} catch {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/i18n/transform-root-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function transformRootLayout(

try {
content = await fs.readFile(filePath).then((res) => res.toString());
} catch (_) {
} catch {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/i18n/transform-source-i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function transformSourceI18n(

try {
content = await fs.readFile(filePath).then((res) => res.toString());
} catch (e) {
} catch {
return;
}
const sourceFile = project.createSourceFile(filePath, content, {
Expand Down
16 changes: 4 additions & 12 deletions packages/cli/src/utils/move-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { type Stats } from 'node:fs';
import { type Project } from 'ts-morph';
import { isRelative } from '@/utils/fs';
import {
Expand All @@ -26,13 +25,8 @@ export async function moveFiles(
*/
originalDir = from,
): Promise<void> {
let stats: Stats;

try {
stats = await fs.lstat(from);
} catch (_) {
return;
}
const stats = await fs.lstat(from).catch(() => undefined);
if (!stats) return;

if (stats.isDirectory()) {
const items = await fs.readdir(from);
Expand All @@ -50,11 +44,9 @@ export async function moveFiles(
}),
);

try {
await fs.rmdir(from);
} catch (_) {
await fs.rmdir(from).catch(() => {
// it is possible that some files are ignored, so the directory isn't empty
}
});
}

if (!stats.isFile()) return;
Expand Down
4 changes: 0 additions & 4 deletions packages/content-collections/.eslintrc.cjs

This file was deleted.

8 changes: 8 additions & 0 deletions packages/content-collections/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import library from 'eslint-config-custom/library.js';

export default [
{
ignores: ['dist', 'node_modules', '*.test.ts'],
},
...library,
];
2 changes: 0 additions & 2 deletions packages/content-collections/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export async function transformMDX<D extends BaseDoc>(
);
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- The type is dynamically generated by Zod
export function createDocSchema(z: typeof Zod) {
return {
title: z.string(),
Expand All @@ -153,7 +152,6 @@ export function createDocSchema(z: typeof Zod) {
};
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- The type is dynamically generated by Zod
export function createMetaSchema(z: typeof Zod) {
return {
title: z.string().optional(),
Expand Down
9 changes: 0 additions & 9 deletions packages/core/.eslintrc.cjs

This file was deleted.

15 changes: 15 additions & 0 deletions packages/core/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import next from 'eslint-config-custom/next.js';

export default [
{
ignores: ['dist/', 'node_modules/', '*.test.ts', '*.output.js'],
},
...next,
{
rules: {
'no-console': 'off',
// handled by bundler
'import/no-cycle': 'off',
},
},
];
1 change: 0 additions & 1 deletion packages/core/src/utils/remove-undefined.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export function removeUndefined<T extends object>(value: T): T {
const obj = value as Record<string, unknown>;
Object.keys(obj).forEach((key) => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- Remove undefined values
if (obj[key] === undefined) delete obj[key];
});

Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@/source/loader';
import { parseFilePath } from '@/source';
import { PageTree } from '../dist/server';
import type { ReactElement } from 'react';

test('get slugs', () => {
expect(getSlugs(parseFilePath('index.mdx'))).toStrictEqual([]);
Expand Down Expand Up @@ -90,7 +91,7 @@ test('Loader: Simple', () => {

test('Nested Directories', async () => {
const result = loader({
icon: (v) => v as any,
icon: (v) => v as unknown as ReactElement,
pageTree: {
noRef: true,
},
Expand Down
1 change: 0 additions & 1 deletion packages/core/test/mdx-plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { fileURLToPath } from 'node:url';
import remarkMdx from 'remark-mdx';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import { createProcessor } from '@mdx-js/mdx';

const cwd = path.dirname(fileURLToPath(import.meta.url));
Expand Down
7 changes: 0 additions & 7 deletions packages/create-app/.eslintrc.cjs

This file was deleted.

13 changes: 13 additions & 0 deletions packages/create-app/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import library from 'eslint-config-custom/next.js';

export default [
{
ignores: ['dist/', 'scripts/', 'node_modules/', 'template/'],
},
...library,
{
rules: {
'import/no-relative-packages': 'off',
},
},
];
10 changes: 5 additions & 5 deletions packages/create-app/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isInGitRepository(cwd: string): boolean {
try {
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore', cwd });
return true;
} catch (_) {
} catch {
return false;
}
}
Expand All @@ -21,7 +21,7 @@ function isInMercurialRepository(cwd: string): boolean {
try {
execSync('hg --cwd . root', { stdio: 'ignore', cwd });
return true;
} catch (_) {
} catch {
return false;
}
}
Expand All @@ -30,7 +30,7 @@ function isDefaultBranchSet(cwd: string): boolean {
try {
execSync('git config init.defaultBranch', { stdio: 'ignore', cwd });
return true;
} catch (_) {
} catch {
return false;
}
}
Expand All @@ -57,11 +57,11 @@ export function tryGitInit(root: string): boolean {
cwd: root,
});
return true;
} catch (e) {
} catch {
if (didInit) {
try {
rmSync(join(root, '.git'), { recursive: true, force: true });
} catch (_) {
} catch {
// do nothing
}
}
Expand Down
4 changes: 0 additions & 4 deletions packages/doc-gen/.eslintrc.cjs

This file was deleted.

8 changes: 8 additions & 0 deletions packages/doc-gen/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import library from 'eslint-config-custom/library.js';

export default [
...library,
{
ignores: ['dist/', 'node_modules/', '*.test.ts', '**/test/fixtures/'],
},
];
Loading

0 comments on commit bb7581f

Please sign in to comment.