Skip to content

Commit b441d0f

Browse files
committed
[optimize] update ESLint configuration from the Upstream scaffold
1 parent e2b67b4 commit b441d0f

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI & CD
22
on:
33
push:
44
branches:
5-
- main
5+
- '**'
66
jobs:
77
Build-and-Deploy:
88
env:

components/Layout/ScrollListPage.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { DataObject, Filter, ListModel } from 'mobx-restful';
2-
import { FC, ReactNode } from 'react';
2+
import { FC, HTMLAttributes } from 'react';
33

44
import { i18n } from '../../models/Translation';
55
import { PageHead } from '../PageHead';
66
import { ScrollList } from '../ScrollList';
77

8-
export interface ScrollListPageProps<D extends DataObject, F extends Filter<D> = Filter<D>> {
8+
export interface ScrollListPageProps<D extends DataObject, F extends Filter<D> = Filter<D>>
9+
extends HTMLAttributes<HTMLDivElement> {
910
store: ListModel<D, F>;
1011
filter?: F;
1112
defaultData?: D[];
1213
title: string;
1314
header: string;
14-
className?: string;
1515
scrollList?: boolean;
16-
children?: ReactNode;
1716
Layout: FC<{ defaultData: D[]; className?: string }>;
1817
}
1918

eslint.config.mjs

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
// @ts-check
2-
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
3-
import { FlatCompat } from '@eslint/eslintrc';
1+
import cspellPlugin from '@cspell/eslint-plugin';
42
import eslint from '@eslint/js';
3+
// @ts-expect-error eslint-plugin-next doesn't come with TypeScript definitions
4+
import nextPlugin from '@next/eslint-plugin-next';
55
import eslintConfigPrettier from 'eslint-config-prettier';
6-
import reactPlugin from 'eslint-plugin-react';
6+
import react from 'eslint-plugin-react';
77
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
88
import globals from 'globals';
99
import tsEslint from 'typescript-eslint';
1010
import { fileURLToPath } from 'url';
1111

12-
const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url)),
13-
flatCompat = new FlatCompat();
12+
/**
13+
* @see{@link https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs}
14+
* @see{@link https://github.com/vercel/next.js/issues/71763#issuecomment-2476838298}
15+
*/
16+
17+
const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url));
1418

1519
export default tsEslint.config(
1620
// register all of the plugins up-front
1721
{
1822
plugins: {
19-
'@typescript-eslint': tsEslint.plugin,
20-
react: fixupPluginRules(reactPlugin),
2123
'simple-import-sort': simpleImportSortPlugin,
24+
'@typescript-eslint': tsEslint.plugin,
25+
react,
26+
'@next/next': nextPlugin,
27+
'@cspell': cspellPlugin,
2228
},
2329
},
2430
{
@@ -29,7 +35,6 @@ export default tsEslint.config(
2935
// extends ...
3036
eslint.configs.recommended,
3137
...tsEslint.configs.recommended,
32-
...fixupConfigRules(flatCompat.extends('plugin:@next/next/core-web-vitals')),
3338

3439
// base config
3540
{
@@ -42,13 +47,33 @@ export default tsEslint.config(
4247
},
4348
},
4449
rules: {
50+
...nextPlugin.configs.recommended.rules,
51+
...nextPlugin.configs['core-web-vitals'].rules,
52+
'arrow-body-style': ['error', 'as-needed'],
4553
'no-empty-pattern': 'warn',
54+
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
55+
'no-restricted-syntax': [
56+
'error',
57+
{
58+
selector: "TSPropertySignature[key.name='children']",
59+
message: 'Please use PropsWithChildren<T> instead of defining children manually',
60+
},
61+
],
62+
'consistent-return': 'warn',
63+
'prefer-destructuring': ['error', { object: true, array: true }],
64+
// simple-import-sort
4665
'simple-import-sort/exports': 'error',
4766
'simple-import-sort/imports': 'error',
67+
// typescript
4868
'@typescript-eslint/no-unused-vars': 'warn',
4969
'@typescript-eslint/no-explicit-any': 'warn',
5070
'@typescript-eslint/no-empty-object-type': 'off',
5171
'@typescript-eslint/no-unsafe-declaration-merging': 'warn',
72+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
73+
// react
74+
'react/no-unescaped-entities': 'off',
75+
'react/self-closing-comp': ['error', { component: true, html: true }],
76+
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
5277
'react/jsx-no-target-blank': 'warn',
5378
'react/jsx-sort-props': [
5479
'error',
@@ -58,18 +83,18 @@ export default tsEslint.config(
5883
noSortAlphabetically: true,
5984
},
6085
],
86+
// next
6187
'@next/next/no-sync-scripts': 'warn',
62-
},
63-
},
64-
{
65-
files: ['**/*.js'],
66-
extends: [tsEslint.configs.disableTypeChecked],
67-
rules: {
68-
// turn off other type-aware rules
69-
'@typescript-eslint/internal/no-poorly-typed-ts-props': 'off',
70-
71-
// turn off rules that don't apply to JS code
72-
'@typescript-eslint/explicit-function-return-type': 'off',
88+
// spellchecker
89+
'@cspell/spellchecker': [
90+
'warn',
91+
{
92+
cspell: {
93+
language: 'en',
94+
dictionaries: ['typescript', 'node', 'html', 'css', 'bash', 'npm', 'pnpm'],
95+
},
96+
},
97+
],
7398
},
7499
},
75100
eslintConfigPrettier,

pages/api/crawler/task.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface CrawlerTask {
77
title?: string;
88
}
99

10-
const CRAWLER_TOKEN = process.env.CRAWLER_TOKEN;
10+
const { CRAWLER_TOKEN } = process.env;
1111

1212
export default safeAPI(async ({ method, headers, body }, response) => {
1313
if (!CRAWLER_TOKEN || CRAWLER_TOKEN !== headers.authorization?.split(/\s+/)[1])
@@ -20,7 +20,7 @@ export default safeAPI(async ({ method, headers, body }, response) => {
2020
const { status, body: data } = await githubClient.post('repos/idea2app/OWS-cache/issues', {
2121
title,
2222
body: `### URL\n\n${URI}`,
23-
labels: ['crawler']
23+
labels: ['crawler'],
2424
});
2525
response.status(status).send(data);
2626
});

0 commit comments

Comments
 (0)