2023-06-08 11:25:15 +03:00
|
|
|
const { resolve } = require('node:path');
|
2023-06-08 10:23:20 +03:00
|
|
|
|
2023-05-31 10:00:50 +03:00
|
|
|
const createPattern = packageName => [
|
|
|
|
{
|
|
|
|
group: ['**/dist', '**/dist/**'],
|
|
|
|
message: 'Do not import from dist',
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
group: ['**/src', '**/src/**'],
|
|
|
|
message: 'Do not import from src',
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
group: [`@affine/${packageName}`],
|
|
|
|
message: 'Do not import package itself',
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
group: [`@toeverything/${packageName}`],
|
|
|
|
message: 'Do not import package itself',
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
2023-07-04 20:34:22 +03:00
|
|
|
{
|
2023-08-07 10:00:57 +03:00
|
|
|
group: ['@blocksuite/store'],
|
2023-07-04 20:34:22 +03:00
|
|
|
message: "Import from '@blocksuite/global/utils'",
|
|
|
|
importNames: ['assertExists', 'assertEquals'],
|
|
|
|
},
|
2023-07-27 21:06:30 +03:00
|
|
|
{
|
|
|
|
group: ['react-router-dom'],
|
|
|
|
message: 'Use `useNavigateHelper` instead',
|
|
|
|
importNames: ['useNavigate'],
|
|
|
|
},
|
2023-08-29 13:07:05 +03:00
|
|
|
{
|
|
|
|
group: ['next-auth/react'],
|
|
|
|
message: "Import hooks from 'use-current-user.tsx'",
|
|
|
|
// useSession is type unsafe
|
|
|
|
importNames: ['useSession'],
|
|
|
|
},
|
2023-08-31 00:22:34 +03:00
|
|
|
{
|
|
|
|
group: ['next-auth/react'],
|
|
|
|
message: "Import hooks from 'cloud-utils.ts'",
|
|
|
|
importNames: ['signIn', 'signOut'],
|
|
|
|
},
|
2023-08-11 18:55:17 +03:00
|
|
|
{
|
|
|
|
group: ['yjs'],
|
|
|
|
message: 'Do not use this API because it has a bug',
|
|
|
|
importNames: ['mergeUpdates'],
|
|
|
|
},
|
2023-09-15 11:59:29 +03:00
|
|
|
{
|
|
|
|
group: ['@affine/env/constant'],
|
|
|
|
message:
|
|
|
|
'Do not import from @affine/env/constant. Use `environment.isDesktop` instead',
|
|
|
|
importNames: ['isDesktop'],
|
|
|
|
},
|
2023-05-31 10:00:50 +03:00
|
|
|
];
|
|
|
|
|
2023-06-08 20:11:53 +03:00
|
|
|
const allPackages = [
|
2023-10-18 18:30:08 +03:00
|
|
|
'packages/backend/server',
|
|
|
|
'packages/frontend/component',
|
2023-11-10 13:25:59 +03:00
|
|
|
'packages/frontend/core',
|
2023-10-18 18:30:08 +03:00
|
|
|
'packages/frontend/electron',
|
|
|
|
'packages/frontend/graphql',
|
|
|
|
'packages/frontend/i18n',
|
|
|
|
'packages/frontend/native',
|
|
|
|
'packages/frontend/templates',
|
2024-01-30 10:16:39 +03:00
|
|
|
'packages/frontend/workspace-impl',
|
2023-10-18 18:30:08 +03:00
|
|
|
'packages/common/debug',
|
|
|
|
'packages/common/env',
|
|
|
|
'packages/common/infra',
|
|
|
|
'packages/common/theme',
|
|
|
|
'packages/common/y-indexeddb',
|
|
|
|
'tools/cli',
|
|
|
|
'tests/storybook',
|
2023-06-08 20:11:53 +03:00
|
|
|
];
|
2023-05-31 10:00:50 +03:00
|
|
|
|
2023-04-18 06:24:44 +03:00
|
|
|
/**
|
|
|
|
* @type {import('eslint').Linter.Config}
|
|
|
|
*/
|
|
|
|
const config = {
|
2023-02-17 10:33:32 +03:00
|
|
|
root: true,
|
|
|
|
settings: {
|
|
|
|
react: {
|
2023-04-18 06:24:44 +03:00
|
|
|
version: 'detect',
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
|
|
|
next: {
|
2023-10-18 18:30:08 +03:00
|
|
|
rootDir: 'packages/frontend/core',
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
extends: [
|
|
|
|
'eslint:recommended',
|
2023-04-14 08:24:44 +03:00
|
|
|
'plugin:react-hooks/recommended',
|
2023-02-17 10:33:32 +03:00
|
|
|
'plugin:react/recommended',
|
2023-02-18 07:52:14 +03:00
|
|
|
'plugin:react/jsx-runtime',
|
2023-02-17 10:33:32 +03:00
|
|
|
'plugin:@typescript-eslint/recommended',
|
2023-06-29 07:13:35 +03:00
|
|
|
'prettier',
|
2023-02-17 10:33:32 +03:00
|
|
|
],
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
globalReturn: false,
|
|
|
|
impliedStrict: true,
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
ecmaVersion: 'latest',
|
|
|
|
sourceType: 'module',
|
2023-06-08 20:11:53 +03:00
|
|
|
project: resolve(__dirname, './tsconfig.eslint.json'),
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
'react',
|
|
|
|
'@typescript-eslint',
|
|
|
|
'simple-import-sort',
|
2023-06-14 05:45:14 +03:00
|
|
|
'sonarjs',
|
2023-07-01 19:35:16 +03:00
|
|
|
'i',
|
2023-02-17 10:33:32 +03:00
|
|
|
'unused-imports',
|
2023-05-09 01:37:07 +03:00
|
|
|
'unicorn',
|
2023-02-17 10:33:32 +03:00
|
|
|
],
|
|
|
|
rules: {
|
2023-06-14 05:45:14 +03:00
|
|
|
'array-callback-return': 'error',
|
2023-02-17 10:33:32 +03:00
|
|
|
'no-undef': 'off',
|
|
|
|
'no-empty': 'off',
|
|
|
|
'no-func-assign': 'off',
|
|
|
|
'no-cond-assign': 'off',
|
2023-06-14 05:45:14 +03:00
|
|
|
'no-constant-binary-expression': 'error',
|
|
|
|
'no-constructor-return': 'error',
|
2023-11-28 11:55:50 +03:00
|
|
|
'no-self-compare': 'error',
|
2023-11-29 07:43:31 +03:00
|
|
|
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
2023-03-01 10:40:01 +03:00
|
|
|
'react/prop-types': 'off',
|
2023-11-08 12:54:41 +03:00
|
|
|
'react/jsx-no-useless-fragment': 'error',
|
2023-03-15 19:58:43 +03:00
|
|
|
'@typescript-eslint/consistent-type-imports': 'error',
|
2023-06-08 10:23:20 +03:00
|
|
|
'@typescript-eslint/no-non-null-assertion': 'error',
|
2023-02-17 10:33:32 +03:00
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2023-10-12 08:04:58 +03:00
|
|
|
'@typescript-eslint/await-thenable': 'error',
|
2023-11-29 07:44:14 +03:00
|
|
|
'@typescript-eslint/require-array-sort-compare': 'error',
|
2023-11-29 07:44:17 +03:00
|
|
|
'@typescript-eslint/unified-signatures': 'error',
|
2023-11-29 07:44:21 +03:00
|
|
|
'@typescript-eslint/prefer-for-of': 'error',
|
2023-04-28 08:41:06 +03:00
|
|
|
'@typescript-eslint/no-unused-vars': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
varsIgnorePattern: '^_',
|
|
|
|
argsIgnorePattern: '^_',
|
|
|
|
caughtErrorsIgnorePattern: '^_',
|
|
|
|
},
|
|
|
|
],
|
2023-02-18 07:52:14 +03:00
|
|
|
'unused-imports/no-unused-imports': 'error',
|
2023-02-17 10:33:32 +03:00
|
|
|
'simple-import-sort/imports': 'error',
|
|
|
|
'simple-import-sort/exports': 'error',
|
2023-06-09 06:55:23 +03:00
|
|
|
'@typescript-eslint/ban-ts-comment': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
'ts-expect-error': 'allow-with-description',
|
|
|
|
'ts-ignore': true,
|
|
|
|
'ts-nocheck': true,
|
|
|
|
'ts-check': false,
|
|
|
|
},
|
|
|
|
],
|
2023-02-17 10:33:32 +03:00
|
|
|
'@typescript-eslint/no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
group: ['**/dist'],
|
|
|
|
message: "Don't import from dist",
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
group: ['**/src'],
|
|
|
|
message: "Don't import from src",
|
|
|
|
allowTypeImports: false,
|
|
|
|
},
|
2023-07-04 20:34:22 +03:00
|
|
|
{
|
|
|
|
group: ['@blocksuite/store'],
|
|
|
|
message: "Import from '@blocksuite/global/utils'",
|
|
|
|
importNames: ['assertExists', 'assertEquals'],
|
|
|
|
},
|
2023-07-27 21:06:30 +03:00
|
|
|
{
|
|
|
|
group: ['react-router-dom'],
|
|
|
|
message: 'Use `useNavigateHelper` instead',
|
|
|
|
importNames: ['useNavigate'],
|
|
|
|
},
|
2023-08-29 13:07:05 +03:00
|
|
|
{
|
|
|
|
group: ['next-auth/react'],
|
|
|
|
message: "Import hooks from 'use-current-user.tsx'",
|
|
|
|
// useSession is type unsafe
|
|
|
|
importNames: ['useSession'],
|
|
|
|
},
|
2023-08-31 00:22:34 +03:00
|
|
|
{
|
|
|
|
group: ['next-auth/react'],
|
|
|
|
message: "Import hooks from 'cloud-utils.ts'",
|
|
|
|
importNames: ['signIn', 'signOut'],
|
|
|
|
},
|
2023-08-11 18:55:17 +03:00
|
|
|
{
|
|
|
|
group: ['yjs'],
|
|
|
|
message: 'Do not use this API because it has a bug',
|
|
|
|
importNames: ['mergeUpdates'],
|
|
|
|
},
|
2023-02-17 10:33:32 +03:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-05-09 01:37:07 +03:00
|
|
|
'unicorn/filename-case': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
case: 'kebabCase',
|
|
|
|
ignore: ['^\\[[a-zA-Z0-9-_]+\\]\\.tsx$'],
|
|
|
|
},
|
|
|
|
],
|
2023-10-12 08:04:58 +03:00
|
|
|
'unicorn/no-unnecessary-await': 'error',
|
2023-11-29 07:43:27 +03:00
|
|
|
'unicorn/no-useless-fallback-in-spread': 'error',
|
2023-11-29 07:43:35 +03:00
|
|
|
'unicorn/prefer-dom-node-dataset': 'error',
|
2023-11-29 07:43:39 +03:00
|
|
|
'unicorn/prefer-dom-node-append': 'error',
|
2023-11-29 07:43:50 +03:00
|
|
|
'unicorn/prefer-dom-node-remove': 'error',
|
2023-11-29 07:43:43 +03:00
|
|
|
'unicorn/prefer-array-some': 'error',
|
2023-11-29 07:43:54 +03:00
|
|
|
'unicorn/prefer-date-now': 'error',
|
2023-11-29 07:44:10 +03:00
|
|
|
'unicorn/prefer-blob-reading-methods': 'error',
|
2023-11-29 07:43:58 +03:00
|
|
|
'unicorn/no-typeof-undefined': 'error',
|
2023-11-29 07:43:46 +03:00
|
|
|
'unicorn/no-useless-promise-resolve-reject': 'error',
|
2023-11-29 07:44:06 +03:00
|
|
|
'unicorn/no-new-array': 'error',
|
2023-11-29 07:44:02 +03:00
|
|
|
'unicorn/new-for-builtins': 'error',
|
2024-01-19 06:47:08 +03:00
|
|
|
'unicorn/prefer-node-protocol': 'error',
|
2023-06-14 05:45:14 +03:00
|
|
|
'sonarjs/no-all-duplicated-branches': 'error',
|
|
|
|
'sonarjs/no-element-overwrite': 'error',
|
|
|
|
'sonarjs/no-empty-collection': 'error',
|
|
|
|
'sonarjs/no-extra-arguments': 'error',
|
|
|
|
'sonarjs/no-identical-conditions': 'error',
|
|
|
|
'sonarjs/no-identical-expressions': 'error',
|
|
|
|
'sonarjs/no-ignored-return': 'error',
|
|
|
|
'sonarjs/no-one-iteration-loop': 'error',
|
|
|
|
'sonarjs/no-use-of-empty-return-value': 'error',
|
|
|
|
'sonarjs/non-existent-operator': 'error',
|
|
|
|
'sonarjs/no-collapsible-if': 'error',
|
|
|
|
'sonarjs/no-same-line-conditional': 'error',
|
|
|
|
'sonarjs/no-duplicated-branches': 'error',
|
|
|
|
'sonarjs/no-collection-size-mischeck': 'error',
|
|
|
|
'sonarjs/no-useless-catch': 'error',
|
2023-06-28 15:29:12 +03:00
|
|
|
'sonarjs/no-identical-functions': 'error',
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
2023-04-18 06:24:44 +03:00
|
|
|
overrides: [
|
|
|
|
{
|
2023-10-18 18:30:08 +03:00
|
|
|
files: 'packages/backend/server/**/*.ts',
|
2023-04-18 06:24:44 +03:00
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/consistent-type-imports': 0,
|
|
|
|
},
|
|
|
|
},
|
2023-04-25 05:13:52 +03:00
|
|
|
{
|
|
|
|
files: '*.cjs',
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-var-requires': 0,
|
|
|
|
},
|
|
|
|
},
|
2023-06-13 09:55:23 +03:00
|
|
|
...allPackages.map(pkg => ({
|
|
|
|
files: [`${pkg}/src/**/*.ts`, `${pkg}/src/**/*.tsx`],
|
|
|
|
parserOptions: {
|
|
|
|
project: resolve(__dirname, './tsconfig.eslint.json'),
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
patterns: createPattern(pkg),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'@typescript-eslint/no-floating-promises': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
ignoreVoid: false,
|
|
|
|
ignoreIIFE: false,
|
|
|
|
},
|
|
|
|
],
|
2023-08-04 11:08:10 +03:00
|
|
|
'@typescript-eslint/no-misused-promises': ['error'],
|
2023-11-29 07:44:25 +03:00
|
|
|
'@typescript-eslint/prefer-readonly': 'error',
|
2023-10-10 20:51:47 +03:00
|
|
|
'i/no-extraneous-dependencies': ['error'],
|
2023-11-10 13:25:59 +03:00
|
|
|
'react-hooks/exhaustive-deps': [
|
|
|
|
'warn',
|
|
|
|
{
|
|
|
|
additionalHooks: 'useAsyncCallback',
|
|
|
|
},
|
|
|
|
],
|
2023-06-13 09:55:23 +03:00
|
|
|
},
|
|
|
|
})),
|
2023-06-08 10:23:20 +03:00
|
|
|
{
|
2023-06-09 06:55:23 +03:00
|
|
|
files: [
|
|
|
|
'**/__tests__/**/*',
|
|
|
|
'**/*.stories.tsx',
|
|
|
|
'**/*.spec.ts',
|
|
|
|
'**/tests/**/*',
|
|
|
|
'scripts/**/*',
|
|
|
|
'**/benchmark/**/*',
|
|
|
|
'**/__debug__/**/*',
|
2023-07-03 13:46:47 +03:00
|
|
|
'**/e2e/**/*',
|
2023-06-09 06:55:23 +03:00
|
|
|
],
|
2023-06-08 10:23:20 +03:00
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-non-null-assertion': 0,
|
2023-06-09 06:55:23 +03:00
|
|
|
'@typescript-eslint/ban-ts-comment': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
'ts-expect-error': false,
|
|
|
|
'ts-ignore': true,
|
|
|
|
'ts-nocheck': true,
|
|
|
|
'ts-check': false,
|
|
|
|
},
|
|
|
|
],
|
2023-06-13 09:55:23 +03:00
|
|
|
'@typescript-eslint/no-floating-promises': 0,
|
2023-08-04 11:08:10 +03:00
|
|
|
'@typescript-eslint/no-misused-promises': 0,
|
2023-09-15 10:34:14 +03:00
|
|
|
'@typescript-eslint/no-restricted-imports': 0,
|
2023-06-08 10:23:20 +03:00
|
|
|
},
|
|
|
|
},
|
2023-04-18 06:24:44 +03:00
|
|
|
],
|
2023-02-17 10:33:32 +03:00
|
|
|
};
|
2023-04-18 06:24:44 +03:00
|
|
|
|
|
|
|
module.exports = config;
|