2024-12-01 10:07:35 +01:00
|
|
|
import eslint from '@eslint/js'
|
|
|
|
|
import tseslint from 'typescript-eslint'
|
|
|
|
|
// @ts-expect-error no types are available for this plugin
|
|
|
|
|
import eslintPluginImport from 'eslint-plugin-import'
|
2024-12-23 11:43:04 +01:00
|
|
|
import eslintPluginReact from 'eslint-plugin-react'
|
2024-12-22 18:03:03 +01:00
|
|
|
// @ts-expect-error no types are available for this plugin
|
|
|
|
|
import eslintPluginReactHooks from 'eslint-plugin-react-hooks'
|
2024-12-01 10:07:35 +01:00
|
|
|
|
2025-01-26 15:02:49 +01:00
|
|
|
/** @type import('typescript-eslint').ConfigArray */
|
|
|
|
|
const tuonoEslintConfig = tseslint.config(
|
2024-12-01 10:07:35 +01:00
|
|
|
{
|
|
|
|
|
ignores: [
|
|
|
|
|
// #region shared
|
|
|
|
|
'**/dist',
|
2025-01-02 13:35:22 +01:00
|
|
|
'**/out',
|
2024-12-01 16:40:58 +01:00
|
|
|
'**/.tuono',
|
2024-12-01 10:07:35 +01:00
|
|
|
'**/vite.config.ts.timestamp**',
|
|
|
|
|
// #endregion shared
|
|
|
|
|
|
|
|
|
|
// #region package-specific
|
2024-12-23 18:28:06 +01:00
|
|
|
'packages/tuono-fs-router-vite-plugin/tests/generator/**',
|
2025-01-02 13:35:22 +01:00
|
|
|
|
2024-12-23 18:28:06 +01:00
|
|
|
'packages/tuono-lazy-fn-vite-plugin/tests/sources/**',
|
2024-12-01 10:07:35 +01:00
|
|
|
|
|
|
|
|
'packages/tuono/bin/**',
|
|
|
|
|
// #endregion package-specific
|
2025-01-02 13:35:22 +01:00
|
|
|
|
|
|
|
|
'examples/**',
|
2024-12-01 10:07:35 +01:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
linterOptions: {
|
|
|
|
|
reportUnusedDisableDirectives: 'error',
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-12-22 12:08:21 +01:00
|
|
|
|
2024-12-01 10:07:35 +01:00
|
|
|
eslint.configs.recommended,
|
2024-12-22 12:08:21 +01:00
|
|
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
|
2024-12-01 10:07:35 +01:00
|
|
|
eslintPluginImport.flatConfigs.recommended,
|
|
|
|
|
eslintPluginImport.flatConfigs.typescript,
|
2024-12-22 12:08:21 +01:00
|
|
|
/* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/no-named-as-default-member
|
|
|
|
|
tseslint.configs.strictTypeChecked,
|
|
|
|
|
|
2024-12-23 11:43:04 +01:00
|
|
|
// @ts-expect-error flat is optional but always defined on runtime
|
|
|
|
|
eslintPluginReact.configs.flat.recommended,
|
|
|
|
|
eslintPluginReact.configs.flat['jsx-runtime'],
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
|
|
|
|
|
plugins: {
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
|
|
'react-hooks': eslintPluginReactHooks,
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
'react-hooks/rules-of-hooks': 'error',
|
|
|
|
|
'react-hooks/exhaustive-deps': 'error',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2024-12-01 10:07:35 +01:00
|
|
|
{
|
|
|
|
|
languageOptions: {
|
|
|
|
|
parserOptions: {
|
|
|
|
|
projectService: true,
|
|
|
|
|
tsconfigRootDir: import.meta.dirname,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
settings: {
|
|
|
|
|
'import/parsers': {
|
|
|
|
|
'@typescript-eslint/parser': ['.ts', '.tsx'],
|
|
|
|
|
},
|
|
|
|
|
'import/resolver': {
|
|
|
|
|
typescript: true,
|
|
|
|
|
},
|
|
|
|
|
react: {
|
|
|
|
|
version: 'detect',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
rules: {
|
|
|
|
|
// #region @typescript-eslint
|
2024-12-07 11:58:58 +01:00
|
|
|
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
|
2024-12-01 10:07:35 +01:00
|
|
|
'@typescript-eslint/consistent-type-definitions': 'error',
|
|
|
|
|
'@typescript-eslint/consistent-type-imports': [
|
|
|
|
|
'error',
|
|
|
|
|
{ prefer: 'type-imports' },
|
|
|
|
|
],
|
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'error',
|
2024-12-22 12:08:21 +01:00
|
|
|
'@typescript-eslint/explicit-function-return-type': 'error',
|
2024-12-01 10:07:35 +01:00
|
|
|
'@typescript-eslint/method-signature-style': ['error', 'property'],
|
|
|
|
|
'@typescript-eslint/naming-convention': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
selector: 'typeParameter',
|
|
|
|
|
format: ['PascalCase'],
|
|
|
|
|
leadingUnderscore: 'forbid',
|
|
|
|
|
trailingUnderscore: 'forbid',
|
|
|
|
|
custom: {
|
|
|
|
|
regex: '^(T|T[A-Z][A-Za-z]+)$',
|
|
|
|
|
match: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'@typescript-eslint/no-empty-function': 'error',
|
|
|
|
|
'@typescript-eslint/no-empty-interface': 'error',
|
2024-12-22 12:08:21 +01:00
|
|
|
|
2024-12-01 10:07:35 +01:00
|
|
|
'@typescript-eslint/no-inferrable-types': [
|
|
|
|
|
'error',
|
|
|
|
|
{ ignoreParameters: true },
|
|
|
|
|
],
|
2024-12-22 12:08:21 +01:00
|
|
|
'@typescript-eslint/restrict-template-expressions': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
allowAny: false,
|
|
|
|
|
allowBoolean: false,
|
|
|
|
|
allowNever: false,
|
|
|
|
|
allowNullish: false,
|
|
|
|
|
allowNumber: true,
|
|
|
|
|
allowRegExp: false,
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-12-01 10:07:35 +01:00
|
|
|
// #endregion @typescript-eslint
|
|
|
|
|
|
|
|
|
|
// #region import
|
|
|
|
|
'import/default': 'error',
|
|
|
|
|
'import/export': 'error',
|
|
|
|
|
'import/namespace': 'error',
|
|
|
|
|
'import/newline-after-import': 'error',
|
|
|
|
|
'import/no-cycle': 'error',
|
|
|
|
|
'import/no-duplicates': 'error',
|
|
|
|
|
'import/no-named-as-default-member': 'error',
|
|
|
|
|
'import/no-unused-modules': 'error',
|
|
|
|
|
'import/order': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
'newlines-between': 'always-and-inside-groups',
|
|
|
|
|
groups: [
|
|
|
|
|
'builtin',
|
|
|
|
|
'external',
|
|
|
|
|
'internal',
|
|
|
|
|
'parent',
|
|
|
|
|
'sibling',
|
|
|
|
|
'index',
|
|
|
|
|
'object',
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
// #endregion import
|
|
|
|
|
|
|
|
|
|
// #region misc
|
|
|
|
|
/**
|
|
|
|
|
* @todo some of this might be removed.
|
|
|
|
|
* They are handled by other plugin and / or typescript
|
|
|
|
|
*/
|
|
|
|
|
'no-case-declarations': 'error',
|
|
|
|
|
'no-empty': 'error',
|
|
|
|
|
'no-prototype-builtins': 'error',
|
|
|
|
|
'no-redeclare': 'error',
|
|
|
|
|
'no-shadow': 'error',
|
|
|
|
|
'no-undef': 'off',
|
|
|
|
|
'sort-imports': 'off',
|
2024-12-22 12:08:21 +01:00
|
|
|
// #endregion misc
|
2024-12-01 10:07:35 +01:00
|
|
|
},
|
|
|
|
|
},
|
2024-12-22 18:03:03 +01:00
|
|
|
|
2024-12-01 16:40:58 +01:00
|
|
|
{
|
|
|
|
|
files: ['apps/documentation/**'],
|
|
|
|
|
settings: {
|
|
|
|
|
'import/resolver': {
|
|
|
|
|
typescript: 'apps/documentation/tsconfig.json',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-12-01 10:07:35 +01:00
|
|
|
)
|
2025-01-26 15:02:49 +01:00
|
|
|
|
|
|
|
|
export default tuonoEslintConfig
|