Files
SpacetimeDB/eslint.config.js
joshua-spacetime 156d515afe Remove Promise.withResolvers and replace with deferred pattern (#5384)
# Description of Changes

Removes all references to `Promise.withResolvers` from the codebase
since it's not supported universally and replaces it with the classic
pre-ES2024 deferred pattern. See #5031 and #5342.

Also adds a lint to avoid re-introducing it in the future.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

...
2026-06-18 14:21:12 +00:00

141 lines
3.9 KiB
JavaScript

import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import { jsdoc } from 'eslint-plugin-jsdoc';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
export default tseslint.config(
jsdoc({
rules: {
'jsdoc/no-undefined-types': 'error',
},
}),
{
ignores: [
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/templates/angular-ts/.angular/**',
],
},
{
rules: {
'no-restricted-properties': [
'error',
{
object: 'Promise',
property: 'withResolvers',
message:
'Use createDeferred() instead; Promise.withResolvers is ES2024 and not supported in all SDK runtimes.',
},
],
},
},
js.configs.recommended,
{
files: ['**/*.{js,cjs,mjs}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
globals: globals.node,
parserOptions: {
project: false,
tsconfigRootDir: __dirname,
},
},
},
...tseslint.configs.recommended,
{
files: ['**/*.{ts,tsx}'],
languageOptions: {
parser: tseslint.parser,
ecmaVersion: 'latest',
sourceType: 'module',
globals: { ...globals.browser, ...globals.node },
parserOptions: {
project: [
'./tsconfig.json',
'./crates/bindings-typescript/tsconfig.json',
'./crates/bindings-typescript/test-app/tsconfig.json',
'./templates/react-ts/tsconfig.json',
'./templates/chat-react-ts/tsconfig.json',
'./templates/money-exchange-react-ts/tsconfig.json',
'./templates/hangman-react-ts/tsconfig.json',
'./templates/basic-ts/tsconfig.json',
'./templates/angular-ts/tsconfig.app.json',
'./docs/tsconfig.json',
],
projectService: true,
tsconfigRootDir: __dirname,
},
},
linterOptions: {
reportUnusedDisableDirectives: 'off',
},
plugins: {
'@typescript-eslint': tseslint.plugin,
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration',
message: 'Do not use enums; stick to JS-compatible types.',
},
{
selector: 'TSEnumDeclaration[const=true]',
message: 'Do not use const enum; use unions or objects.',
},
{ selector: 'Decorator', message: 'Do not use decorators.' },
],
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'eslint-comments/no-unused-disable': 'off',
'@typescript-eslint/no-empty-object-type': [
'error',
{ allowObjectTypes: 'always' },
],
},
},
{
files: ['templates/angular-ts/src/**/*.ts'],
rules: {
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration',
message: 'Do not use enums; stick to JS-compatible types.',
},
{
selector: 'TSEnumDeclaration[const=true]',
message: 'Do not use const enum; use unions or objects.',
},
],
'react-hooks/rules-of-hooks': 'off',
'react-hooks/exhaustive-deps': 'off',
'react-refresh/only-export-components': 'off',
},
}
);