Tldraw/.eslintrc.js

250 wiersze
6.5 KiB
JavaScript

2023-04-25 11:01:25 +00:00
module.exports = {
extends: [
'prettier',
'eslint:recommended',
'plugin:react/recommended',
2023-04-25 11:01:25 +00:00
'plugin:@typescript-eslint/recommended',
'plugin:@next/next/core-web-vitals',
],
ignorePatterns: [],
plugins: [
'@typescript-eslint',
'no-only-tests',
'import',
'local',
'@next/next',
'react',
'react-hooks',
'deprecation',
],
2023-04-25 11:01:25 +00:00
settings: {
next: {
rootDir: ['apps/*/', 'packages/*/'],
},
},
rules: {
'deprecation/deprecation': 'error',
2023-04-25 11:01:25 +00:00
'@next/next/no-html-link-for-pages': 'off',
'no-non-null-assertion': 'off',
'no-fallthrough': 'off',
'react/jsx-no-target-blank': 'error',
'react/react-in-jsx-scope': 'off',
2023-04-25 11:01:25 +00:00
'@typescript-eslint/no-fallthrough': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
Move from function properties to methods (#4288) Things left to do - [x] Update docs (things like the [tools page](https://tldraw-docs-fqnvru1os-tldraw.vercel.app/docs/tools), possibly more) - [x] Write a list of breaking changes and how to upgrade. - [x] Do another pass and check if we can update any lines that have `@typescript-eslint/method-signature-style` and `local/prefer-class-methods` disabled - [x] Thinks about what to do with `TLEventHandlers`. Edit: Feels like keeping them is the best way to go. - [x] Remove `override` keyword where it's not needed. Not sure if it's worth the effort. Edit: decided not to spend time here. - [ ] What about possible detached / destructured uses? Fixes https://github.com/tldraw/tldraw/issues/2799 ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [x] `api` - [ ] `other` ### Test plan 1. Create a shape... 2. - [ ] Unit tests - [ ] End to end tests ### Release notes - Adds eslint rules for enforcing the use of methods instead of function properties and fixes / disables all the resulting errors. # Breaking changes This change affects the syntax of how the event handlers for shape tools and utils are defined. ## Shape utils **Before** ```ts export class CustomShapeUtil extends ShapeUtil<CustomShape> { // Defining flags override canEdit = () => true // Defining event handlers override onResize: TLOnResizeHandler<CustomShape> = (shape, info) => { ... } } ``` **After** ```ts export class CustomShapeUtil extends ShapeUtil<CustomShape> { // Defining flags override canEdit() { return true } // Defining event handlers override onResize(shape: CustomShape, info: TLResizeInfo<CustomShape>) { ... } } ``` ## Tools **Before** ```ts export class CustomShapeTool extends StateNode { // Defining child states static override children = (): TLStateNodeConstructor[] => [Idle, Pointing] // Defining event handlers override onKeyDown: TLEventHandlers['onKeyDown'] = (info) => { ... } } ``` **After** ```ts export class CustomShapeTool extends StateNode { // Defining child states static override children(): TLStateNodeConstructor[] { return [Idle, Pointing] } // Defining event handlers override onKeyDown(info: TLKeyboardEventInfo) { ... } } ``` --------- Co-authored-by: David Sheldrick <d.j.sheldrick@gmail.com> Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-07-29 13:40:18 +00:00
'@typescript-eslint/method-signature-style': ['error', 'method'],
2023-04-25 11:01:25 +00:00
'react/display-name': 'off',
'@next/next/no-img-element': 'off',
'react/prop-types': 'off',
2023-04-25 11:01:25 +00:00
'@typescript-eslint/no-extra-semi': 'off',
'no-mixed-spaces-and-tabs': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'no-throw-literal': 'error',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'error',
'import/no-extraneous-dependencies': 'error',
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
'local/no-export-star': 'error',
'local/no-internal-imports': 'error',
'local/tagged-components': 'error',
Move from function properties to methods (#4288) Things left to do - [x] Update docs (things like the [tools page](https://tldraw-docs-fqnvru1os-tldraw.vercel.app/docs/tools), possibly more) - [x] Write a list of breaking changes and how to upgrade. - [x] Do another pass and check if we can update any lines that have `@typescript-eslint/method-signature-style` and `local/prefer-class-methods` disabled - [x] Thinks about what to do with `TLEventHandlers`. Edit: Feels like keeping them is the best way to go. - [x] Remove `override` keyword where it's not needed. Not sure if it's worth the effort. Edit: decided not to spend time here. - [ ] What about possible detached / destructured uses? Fixes https://github.com/tldraw/tldraw/issues/2799 ### Change type - [ ] `bugfix` - [ ] `improvement` - [ ] `feature` - [x] `api` - [ ] `other` ### Test plan 1. Create a shape... 2. - [ ] Unit tests - [ ] End to end tests ### Release notes - Adds eslint rules for enforcing the use of methods instead of function properties and fixes / disables all the resulting errors. # Breaking changes This change affects the syntax of how the event handlers for shape tools and utils are defined. ## Shape utils **Before** ```ts export class CustomShapeUtil extends ShapeUtil<CustomShape> { // Defining flags override canEdit = () => true // Defining event handlers override onResize: TLOnResizeHandler<CustomShape> = (shape, info) => { ... } } ``` **After** ```ts export class CustomShapeUtil extends ShapeUtil<CustomShape> { // Defining flags override canEdit() { return true } // Defining event handlers override onResize(shape: CustomShape, info: TLResizeInfo<CustomShape>) { ... } } ``` ## Tools **Before** ```ts export class CustomShapeTool extends StateNode { // Defining child states static override children = (): TLStateNodeConstructor[] => [Idle, Pointing] // Defining event handlers override onKeyDown: TLEventHandlers['onKeyDown'] = (info) => { ... } } ``` **After** ```ts export class CustomShapeTool extends StateNode { // Defining child states static override children(): TLStateNodeConstructor[] { return [Idle, Pointing] } // Defining event handlers override onKeyDown(info: TLKeyboardEventInfo) { ... } } ``` --------- Co-authored-by: David Sheldrick <d.j.sheldrick@gmail.com> Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-07-29 13:40:18 +00:00
'local/prefer-class-methods': 'error',
'no-only-tests/no-only-tests': 'error',
'no-restricted-syntax': [
'error',
{ selector: "MethodDefinition[kind='set']", message: 'Property setters are not allowed' },
{ selector: "MethodDefinition[kind='get']", message: 'Property getters are not allowed' },
{
selector: 'Identifier[name=localStorage]',
message: 'Use the getFromLocalStorage/setInLocalStorage helpers instead',
},
{
selector: 'Identifier[name=sessionStorage]',
message: 'Use the getFromSessionStorage/setInSessionStorage helpers instead',
},
],
use native structuredClone on node, cloudflare workers, and in tests (#3166) Currently, we only use native `structuredClone` in the browser, falling back to `JSON.parse(JSON.stringify(...))` elsewhere, despite Node supporting `structuredClone` [since v17](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) and Cloudflare Workers supporting it [since 2022](https://blog.cloudflare.com/standards-compliant-workers-api/). This PR adjusts our shim to use the native `structuredClone` on all platforms, if available. Additionally, `jsdom` doesn't implement `structuredClone`, a bug [open since 2022](https://github.com/jsdom/jsdom/issues/3363). This PR patches `jsdom` environment in all packages/apps that use it for tests. Also includes a driveby removal of `deepCopy`, a function that is strictly inferior to `structuredClone`. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [x] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [x] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. A smoke test would be enough - [ ] Unit Tests - [x] End to end tests
2024-03-18 17:16:09 +00:00
'no-restricted-globals': [
'error',
{ name: 'structuredClone', message: 'Use structuredClone from @tldraw/util instead' },
],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
2023-04-25 11:01:25 +00:00
},
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
},
overrides: [
{
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': [0],
'no-console': ['error', { allow: ['warn', 'error'] }],
},
},
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
{
files: ['packages/editor/**/*', 'packages/tldraw/**/*', 'packages/utils/**/*'],
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
rules: {
'no-restricted-globals': [
'error',
{
name: 'fetch',
message: 'Use the fetch from @tldraw/util instead.',
},
{
name: 'Image',
message: 'Use the Image from @tldraw/util instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
{
name: 'setTimeout',
message: 'Use the timers from editor.timers instead.',
},
{
name: 'setInterval',
message: 'Use the timers from editor.timers instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
{
name: 'requestAnimationFrame',
message: 'Use the timers from editor.timers instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
{ name: 'structuredClone', message: 'Use structuredClone from @tldraw/util instead' },
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
],
'no-restricted-properties': [
'error',
{
object: 'window',
property: 'fetch',
message: 'Use the fetch from @tldraw/util instead.',
},
{
object: 'window',
property: 'Image',
message: 'Use the Image from @tldraw/util instead.',
},
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
{
object: 'window',
property: 'setTimeout',
message: 'Use the timers from editor.timers instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
{
object: 'window',
property: 'setInterval',
message: 'Use the timers from editor.timers instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
{
object: 'window',
property: 'requestAnimationFrame',
message: 'Use the timers from editor.timers instead.',
},
],
'no-restricted-syntax': [
'error',
{ selector: "MethodDefinition[kind='set']", message: 'Property setters are not allowed' },
{ selector: "MethodDefinition[kind='get']", message: 'Property getters are not allowed' },
{
selector: 'Identifier[name=localStorage]',
message: 'Use the getFromLocalStorage/setInLocalStorage helpers instead',
},
{
selector: 'Identifier[name=sessionStorage]',
message: 'Use the getFromSessionStorage/setInSessionStorage helpers instead',
},
{
selector:
"JSXElement[openingElement.name.name='img']:not(:has(JSXAttribute[name.name='referrerPolicy']))",
message: 'You must pass `referrerPolicy` when creating an <img>.',
},
],
},
},
// This overrides the default config for the given matching paths.
{
files: ['apps/dotcom/**/*'],
rules: {
'no-restricted-globals': [
'error',
{
name: 'fetch',
message: 'Use the fetch from @tldraw/util instead.',
},
{
name: 'Image',
message: 'Use the Image from @tldraw/util instead.',
},
{ name: 'structuredClone', message: 'Use structuredClone from @tldraw/util instead' },
],
'no-restricted-properties': [
'error',
{
object: 'window',
property: 'fetch',
message: 'Use the fetch from @tldraw/util instead.',
},
{
object: 'window',
property: 'Image',
message: 'Use the Image from @tldraw/util instead.',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
],
},
},
2023-04-25 11:01:25 +00:00
{
files: ['e2e/**/*'],
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
},
{
files: 'scripts/**/*',
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
{
files: ['*.test.ts', '*.test.tsx', '*.spec.ts'],
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
rules: {
'no-restricted-properties': 'off',
'no-restricted-globals': 'off',
'react/jsx-key': 'off',
'react/no-string-refs': 'off',
editor: register timeouts/intervals/rafs for disposal (#3852) We have a lot of events that fire in the editor and, technically, they can fire after the Editor is long gone. This adds a registry/manager to track those timeout/interval/raf IDs (and some eslint rules to enforce it). Some other cleanups: - `requestAnimationFrame.polyfill.ts` looks like it's unused now (it used to be used in a prev. revision) - @ds300 I could use your feedback on the `EffectScheduler` tweak. in `useReactor` we do: `() => new EffectScheduler(name, reactFn, { scheduleEffect: (cb) => requestAnimationFrame(cb) }),` and that looks like it doesn't currently get disposed of properly. thoughts? happy to do that separately from this PR if you think that's a trickier thing. ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [x] `sdk` — Changes the tldraw SDK - [ ] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Test async operations and make sure they don't fire after disposal. ### Release Notes - Editor: add registry of timeouts/intervals/rafs --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
2024-06-04 08:50:40 +00:00
},
},
2023-04-25 11:01:25 +00:00
{
files: ['apps/examples/**/*'],
rules: {
'no-restricted-syntax': 'off',
'local/no-at-internal': 'error',
2023-04-25 11:01:25 +00:00
},
},
{
files: ['apps/huppy/**/*', 'scripts/**/*', 'apps/simple-server-example/**/*'],
rules: {
'no-console': 'off',
},
},
{
files: ['apps/dotcom/**/*'],
rules: {
'no-restricted-properties': [
2,
{
object: 'crypto',
property: 'randomUUID',
message: 'Please use the makeUUID util instead.',
},
],
},
},
2023-04-25 11:01:25 +00:00
],
}