chore(eslint): shared rules

This commit is contained in:
Elliot DeNolf
2024-03-13 11:50:58 -04:00
parent 931e2f6134
commit e43c80b4f5

View File

@@ -1,3 +1,61 @@
const sharedRules = {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
// Type-aware any rules:
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// This rule doesn't work well in .tsx files
'@typescript-eslint/no-misused-promises': 'off',
// Type-aware any rules end
// ts-expect should always be preferred over ts-ignore
'@typescript-eslint/prefer-ts-expect-error': 'warn',
// This rule makes no sense when overriding class methods. This is used a lot in richtext-lexical.
'class-methods-use-this': 'off',
// By default, it errors for unused variables. This is annoying, warnings are enough.
'@typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^ignore',
},
],
'@typescript-eslint/no-use-before-define': 'off',
'arrow-body-style': 0,
'import/prefer-default-export': 'off',
'no-restricted-exports': ['warn', { restrictDefaultExports: { direct: true } }],
'no-console': 'warn',
'no-sparse-arrays': 'off',
'no-underscore-dangle': 'off',
'no-use-before-define': 'off',
'object-shorthand': 'warn',
'react/no-unused-prop-types': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'perfectionist/sort-objects': [
'error',
{
type: 'natural',
order: 'asc',
'partition-by-comment': true,
groups: ['top', 'unknown'],
'custom-groups': {
top: ['_id', 'id', 'name', 'slug', 'type'],
},
},
],
}
/** @type {import('eslint').Linter.Config} */
module.exports = {
env: {
@@ -32,6 +90,7 @@ module.exports = {
'prettier',
],
parser: '@typescript-eslint/parser',
rules: sharedRules,
},
{
files: ['**/*.ts'],
@@ -44,6 +103,7 @@ module.exports = {
'prettier',
],
parser: '@typescript-eslint/parser',
rules: sharedRules,
},
{
files: ['**/*.tsx'],
@@ -59,77 +119,24 @@ module.exports = {
'prettier',
],
parser: '@typescript-eslint/parser',
rules: sharedRules,
},
{
files: ['*.config.ts'],
rules: {
'no-restricted-exports': 'off',
...sharedRules,
},
},
{
files: ['config.ts'],
rules: {
'no-restricted-exports': 'off',
...sharedRules,
},
},
],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
// Type-aware any rules:
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
// This rule doesn't work well in .tsx files
'@typescript-eslint/no-misused-promises': 'off',
// Type-aware any rules end
// ts-expect should always be preferred over ts-ignore
'@typescript-eslint/prefer-ts-expect-error': 'warn',
// This rule makes no sense when overriding class methods. This is used a lot in richtext-lexical.
'class-methods-use-this': 'off',
// By default, it errors for unused variables. This is annoying, warnings are enough.
'@typescript-eslint/no-unused-vars': [
'warn',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^ignore',
},
],
'@typescript-eslint/no-use-before-define': 'off',
'arrow-body-style': 0,
'import/prefer-default-export': 'off',
'no-restricted-exports': ['warn', { restrictDefaultExports: { direct: true } }],
'no-console': 'warn',
'no-sparse-arrays': 'off',
'no-underscore-dangle': 'off',
'no-use-before-define': 'off',
'object-shorthand': 'warn',
'react/no-unused-prop-types': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'perfectionist/sort-objects': [
'error',
{
type: 'natural',
order: 'asc',
'partition-by-comment': true,
groups: ['top', 'unknown'],
'custom-groups': {
top: ['_id', 'id', 'name', 'slug', 'type'],
},
},
],
},
rules: sharedRules,
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],