2023-06-08 11:25:15 +03:00
|
|
|
const { resolve } = require('node:path');
|
|
|
|
const { readdirSync, statSync } = require('node:fs');
|
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-06-08 11:25:15 +03:00
|
|
|
const pkgs = readdirSync(resolve(__dirname, './packages')).filter(pkg => {
|
2023-06-08 10:23:20 +03:00
|
|
|
return statSync(`./packages/${pkg}`).isDirectory();
|
|
|
|
});
|
2023-06-08 11:25:15 +03:00
|
|
|
|
|
|
|
const apps = readdirSync(resolve(__dirname, './apps')).filter(pkg => {
|
2023-06-08 10:23:20 +03:00
|
|
|
return statSync(`./apps/${pkg}`).isDirectory();
|
|
|
|
});
|
|
|
|
|
|
|
|
const allPackages = pkgs.concat(apps);
|
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: {
|
|
|
|
rootDir: 'apps/web',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
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',
|
|
|
|
],
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
globalReturn: false,
|
|
|
|
impliedStrict: true,
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
ecmaVersion: 'latest',
|
|
|
|
sourceType: 'module',
|
2023-06-08 10:23:20 +03:00
|
|
|
project: './tsconfig.eslint.json',
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
'react',
|
|
|
|
'@typescript-eslint',
|
|
|
|
'simple-import-sort',
|
|
|
|
'import',
|
|
|
|
'unused-imports',
|
2023-05-09 01:37:07 +03:00
|
|
|
'unicorn',
|
2023-02-17 10:33:32 +03:00
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
'no-undef': 'off',
|
|
|
|
'no-empty': 'off',
|
|
|
|
'no-func-assign': 'off',
|
|
|
|
'no-cond-assign': 'off',
|
2023-03-01 10:40:01 +03:00
|
|
|
'react/prop-types': 'off',
|
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-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',
|
|
|
|
'@typescript-eslint/ban-ts-comment': 0,
|
|
|
|
'@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-05-09 01:37:07 +03:00
|
|
|
'unicorn/filename-case': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
case: 'kebabCase',
|
|
|
|
ignore: ['^\\[[a-zA-Z0-9-_]+\\]\\.tsx$'],
|
|
|
|
},
|
|
|
|
],
|
2023-02-17 10:33:32 +03:00
|
|
|
},
|
2023-04-18 06:24:44 +03:00
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
files: 'apps/server/**/*.ts',
|
|
|
|
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-08 10:23:20 +03:00
|
|
|
{
|
|
|
|
files: ['**/__tests__/**/*', '**/*.stories.tsx'],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-non-null-assertion': 0,
|
|
|
|
},
|
|
|
|
},
|
2023-05-31 10:00:50 +03:00
|
|
|
...allPackages.map(pkg => ({
|
|
|
|
files: [`packages/${pkg}/src/**/*.ts`, `packages/${pkg}/src/**/*.tsx`],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
patterns: createPattern(pkg),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})),
|
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;
|