webai/eslint.config.mjs
2024-07-27 23:38:19 +00:00

181 lines
7.5 KiB
JavaScript

// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import unusedImports from 'eslint-plugin-unused-imports';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
files: ["src/**/*.ts", "src/**/*.tsx"],
plugins: {
'unused-imports': unusedImports,
react,
'react-hooks': reactHooks,
},
settings: {
react: {
version: 'detect',
},
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},
rules: {
// syntax
'no-unused-vars': 'off',
'arrow-body-style': ['warn', 'as-needed'],
'capitalized-comments': ['warn', 'never', { ignorePattern: 'TODO|WARNING|NOTE|LOG' }], // make these statements stand out
// 'curly': [ 'warn', 'multi-line', 'consistent' ],
'dot-notation': 'warn',
eqeqeq: 'warn',
'func-style': ['warn', 'declaration', { allowArrowFunctions: true }],
'guard-for-in': 'error',
'init-declarations': ['warn', 'always'], // there are a few cases for not specifying the declaration around scoping
'max-lines': ['warn', 800],
'no-alert': 'error',
'no-array-constructor': 'error',
'no-caller': 'error',
'no-empty': 'warn', // this is error by default. very annoying
'no-empty-function': ['warn', { allow: ['constructors'] }],
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-implied-eval': 'error',
'no-invalid-this': 'error',
//"no-magic-numbers": "warn",
// 'no-mixed-operators': 'warn',
'no-multi-str': 'error',
'no-new-func': 'warn',
'no-new-object': 'error',
'no-new-wrappers': 'error',
'no-return-assign': 'warn',
'no-script-url': 'error',
'no-throw-literal': 'error',
'no-unneeded-ternary': 'error',
'no-unused-expressions': 'warn',
'no-useless-call': 'error',
'no-useless-computed-key': 'warn',
'no-useless-concat': 'warn',
'no-useless-rename': 'warn',
'no-useless-return': 'warn',
'no-var': 'error',
'no-void': 'error',
'object-shorthand': 'warn',
'one-var': ['warn', 'never'],
'operator-assignment': 'warn',
'prefer-arrow-callback': ['error', { allowNamedFunctions: true, allowUnboundThis: false }],
'prefer-const': 'warn',
'prefer-exponentiation-operator': 'error',
'prefer-numeric-literals': 'error',
'prefer-object-has-own': 'error',
'prefer-promise-reject-errors': 'warn',
'prefer-regex-literals': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
//"prefer-template": "warn", // can add whenever, I don't feel like fixing the warnings atm
// 'quote-props': [ 'error', 'as-needed' ],
radix: ['warn', 'as-needed'],
//"sort-imports": "warn",
yoda: 'error',
// formatting
// 'array-bracket-newline': [ 'warn', 'consistent' ],
// 'array-bracket-spacing': [ 'warn', 'always' ],
// 'arrow-parens': [ 'warn', 'as-needed' ],
// 'arrow-spacing': 'warn',
// 'block-spacing': [ 'warn', 'always' ],
// 'brace-style': [ 'error', '1tbs', { allowSingleLine: true } ],
// 'comma-dangle': [ 'warn', 'always-multiline' ],
// 'comma-spacing': 'warn',
// 'comma-style': [ 'warn', 'last' ], // first is best in SQL contexts
// 'computed-property-spacing': 'warn',
// 'dot-location': [ 'warn', 'property' ],
// 'eol-last': [ 'warn', 'always' ],
// 'func-call-spacing': 'error',
// 'function-call-argument-newline': [ 'warn', 'consistent' ],
// 'generator-star-spacing': [ 'warn', { before: false, after: true } ],
// 'implicit-arrow-linebreak': 'warn',
//'indent': [ 'warn', 'tab' ], // causes a crash
// 'key-spacing': [ 'warn', { beforeColon: false, afterColon: true, align: 'value' } ], // potentially the most opinionated one here
// 'keyword-spacing': 'warn',
// 'linebreak-style': [ 'warn', 'unix' ],
//"max-len": [ "warn", { code: 160, ignoreTrailingComments: true } ],
// 'new-parens': 'warn',
// 'newline-per-chained-call': [ 'warn', { ignoreChainWithDepth: 3 } ],
//"no-extra-parens": "warn", TODO: get better at true && false || true
// 'no-multi-spaces': [ 'warn', { 'exceptions': { 'Property': true } } ],
// 'no-multiple-empty-lines': 'warn',
// 'no-trailing-spaces': 'warn',
// 'no-whitespace-before-property': 'error',
// 'nonblock-statement-body-position': [ 'warn', 'beside' ],
// 'object-curly-newline': [ 'warn', { 'consistent': true } ],
// 'object-curly-spacing': [ 'warn', 'always' ],
//"object-property-newline": "warn",
// 'operator-linebreak': [ 'warn', 'after' ],
// 'padded-blocks': [ 'warn', 'never' ],
// 'quotes': [ 'warn', 'single', { avoidEscape: true, allowTemplateLiterals: true } ],
// 'rest-spread-spacing': [ 'error', 'never' ],
// 'semi': [ 'error', 'always', { omitLastInOneLineBlock: false } ],
// 'semi-spacing': [ 'warn', { before: false, after: true } ],
// 'semi-style': [ 'error', 'last' ],
// 'space-before-function-paren': [ 'warn', { anonymous: 'never', named: 'never', asyncArrow: 'always' } ],
// 'space-in-parens': [ 'warn', 'never' ],
// 'space-infix-ops': [ 'warn' ],
// 'space-unary-ops': [ 'warn' ],
// 'template-curly-spacing': [ 'warn', 'never' ],
// 'template-tag-spacing': [ 'warn', 'never' ],
// 'wrap-iife': [ 'warn', 'inside' ],
// 'yield-star-spacing': [ 'warn', 'after' ],
// typescript/react/jsx
// 'jsx-quotes': [ 'warn', 'prefer-double' ],
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'unused-imports/no-unused-imports': 'warn',
'react/self-closing-comp': 'warn',
'react/jsx-boolean-value': ['warn', 'always'],
// 'react/jsx-closing-tag-location': 'warn',
'react/jsx-curly-brace-presence': ['warn', { props: 'never', children: 'never' }], // coming soon is propElementValues
// 'react/jsx-curly-newline': [ 'warn', 'consistent' ],
// 'react/jsx-equals-spacing': [ 'warn', 'never' ],
// 'react/jsx-first-prop-new-line': [ 'warn', 'multiline' ],
'react/jsx-fragments': ['warn', 'syntax'],
// 'react/jsx-indent': [ 'warn', 'tab', { checkAttributes: true, indentLogicalExpressions: true } ],
// 'react/jsx-indent-props': [ 'warn', 'tab' ],
// 'react/jsx-max-props-per-line': [ 'warn', { maximum: 1, when: 'multiline' } ],
// 'react/jsx-no-bind': 'error',
'react/jsx-no-constructed-context-values': 'error',
'react/jsx-no-useless-fragment': 'error',
'react/jsx-pascal-case': 'warn',
// 'react/jsx-props-no-multi-spaces': 'warn',
'react/jsx-props-no-spreading': 'error',
// 'react/jsx-tag-spacing': [ 'warn', { closingSlash: 'never', beforeSelfClosing: 'always', afterOpening: 'never', beforeClosing: 'never' } ],
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': [
'warn',
{ additionalHooks: '(useAsyncMemo|useAsyncCallback|useAsyncSubmitText)' },
],
},
}
);