Skip to content

Commit

Permalink
Update ESLint to v9 (#1796)
Browse files Browse the repository at this point in the history
* Convert to flat config with FlatCompat

* Remove FlatCompat

* Update to ESLint v9
  • Loading branch information
stephenwade authored Oct 10, 2024
1 parent ecb2f71 commit 004f880
Show file tree
Hide file tree
Showing 8 changed files with 665 additions and 750 deletions.
130 changes: 0 additions & 130 deletions .eslintrc.cjs

This file was deleted.

1 change: 1 addition & 0 deletions app/components/admin/SaveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const SaveButton: FC<SaveButtonProps> = ({
}) => {
const isSubmitting = useIsSubmitting();
const { isValid } = useFormContext();
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const disabled = disabledProp || isSubmitting || !isValid;

return (
Expand Down
1 change: 1 addition & 0 deletions app/hooks/useSse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const eventSources = new Map<
{ eventSource: EventSource; refCount: number }
>();

// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
export function useSse<T>(url: string | URL, onMessage: (data: T) => void) {
useEffect(() => {
const eventSourceData = eventSources.get(url);
Expand Down
2 changes: 1 addition & 1 deletion app/types/validateShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type DeepNonNullable<T> = T extends (infer U)[]
/**
* Ensure that all of an object's properties are not null.
*/
function validate<T>(obj: T): boolean {
function validate(obj: Record<string, unknown> | null): boolean {
if (obj === null) return false;
if (typeof obj !== 'object') return true;
for (const key in obj) {
Expand Down
158 changes: 158 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { fixupPluginRules, includeIgnoreFile } from '@eslint/compat';
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import _import from 'eslint-plugin-import';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import noOnlyTests from 'eslint-plugin-no-only-tests';
import playwright from 'eslint-plugin-playwright';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import unicorn from 'eslint-plugin-unicorn';
import unusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';
import tseslint from 'typescript-eslint';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, '.gitignore');

export default tseslint.config(
js.configs.recommended,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
// This doesn't work yet
// reactHooks.configs.recommended,
jsxA11y.flatConfigs.recommended,
playwright.configs['flat/recommended'],

...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,

unicorn.configs['flat/recommended'],

prettier,

{
plugins: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
import: fixupPluginRules(_import),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'no-only-tests': noOnlyTests,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
'react-hooks': reactHooks,
'simple-import-sort': simpleImportSort,
'unused-imports': unusedImports,
},

languageOptions: {
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
projectService: true,
},
},

settings: {
react: {
version: 'detect',
},
formComponents: ['Form'],
linkComponents: [
{ name: 'Link', linkAttribute: 'to' },
{ name: 'NavLink', linkAttribute: 'to' },
],
},

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
rules: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...reactHooks.configs.recommended.rules,

'no-plusplus': 'error',
'object-shorthand': 'warn',
quotes: ['warn', 'single', { avoidEscape: true }],
'require-unicode-regexp': 'warn',

'import/first': 'warn',
'import/newline-after-import': 'warn',
'import/no-duplicates': 'warn',

'simple-import-sort/imports': 'warn',
'simple-import-sort/exports': 'warn',

'playwright/expect-expect': [
'warn',
{
assertFunctionNames: [
'expectAudioIsPlaying',
'expectAudioIsNotPlaying',
'expectAudioCurrentTimeToAlmostEqual',
],
},
],
'no-only-tests/no-only-tests': 'error',

'@typescript-eslint/no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'warn',
'unused-imports/no-unused-vars': 'warn',

'@typescript-eslint/consistent-type-exports': 'warn',
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off', // Used for route params and in tests
'@typescript-eslint/only-throw-error': 'off', // Remix allows throwing `Response`s
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowAny: false,
allowBoolean: false,
allowNullish: false,
allowNumber: true,
allowRegExp: false,
allowNever: false,
},
],
'@typescript-eslint/switch-exhaustiveness-check': [
'error',
{
allowDefaultCaseForExhaustiveSwitch: false,
requireDefaultForNonUnion: true,
},
],

'unicorn/better-regex': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/no-null': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/prefer-module': 'off',
'unicorn/prefer-switch': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/switch-case-braces': 'off',

'react/jsx-no-leaked-render': ['warn', { validStrategies: ['ternary'] }],
},
},
{
files: ['.eslintrc.cjs', 'stylelint.config.js', 'svgo.config.js'],

languageOptions: {
globals: globals.node,
},
},
{
files: ['playwright/**/*.ts', 'playwright/**/*.tsx'],

rules: {
'no-empty-pattern': 'off',
'@typescript-eslint/unbound-method': 'off',
},
},
includeIgnoreFile(gitignorePath),
);
Loading

0 comments on commit 004f880

Please sign in to comment.