Skip to content

Commit

Permalink
Merge pull request #11 from retejs/new-linter
Browse files Browse the repository at this point in the history
fix: update cli and fix linting errors
  • Loading branch information
Ni55aN authored Aug 30, 2024
2 parents d847605 + 5d3d1e2 commit 7337e65
Show file tree
Hide file tree
Showing 13 changed files with 2,255 additions and 1,844 deletions.
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
.svelte-kit
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import tseslint from 'typescript-eslint';
import configs from 'rete-cli/configs/eslint.mjs';
import gloals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...gloals.browser
}
},
rules: {
'@typescript-eslint/unbound-method': 'off'
}
}
)
4,002 changes: 2,191 additions & 1,811 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@sveltejs/package": "^2.1.0",
"globals": "^15.9.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"rete-cli": "~2.0.1",
"rete-render-utils": "^2.0.0",
"rollup-plugin-scss": "^4.0.0",
"rollup-plugin-svelte": "^7.1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class SveltePlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> ex
element,
result.component,
result.props,
() => parent?.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)
() => void parent.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The '{ type: 'rendered', data: (context as Requires<Schemes>).data } as T' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The 'context as Requires<Schemes>' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The '{ type: 'rendered', data: (context as Requires<Schemes>).data } as T' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / release / publish

The 'context as Requires<Schemes>' has unsafe 'as' type assertion
)

this.owners.set(element, preset)
Expand Down
47 changes: 30 additions & 17 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */

import { ClassicPreset, Scope } from 'rete'
import { classicConnectionPath, getDOMSocketPosition, loopConnectionPath, SocketPositionWatcher } from 'rete-render-utils'
import type { ComponentType, SvelteComponent } from 'svelte'
Expand All @@ -24,22 +24,20 @@ type CustomizationProps<Schemes extends ClassicScheme> = {
connection?: (data: ExtractPayload<Schemes, 'connection'>) => Component<any> | null
socket?: (data: ExtractPayload<Schemes, 'socket'>) => Component<any> | null
control?: <N extends ClassicPreset.Control>(data: ExtractPayload<Schemes, 'control'>)
=> Component<{ data: N }> | null
=> Component<{ data: N }> | null
}
type ClassicProps<Schemes extends ClassicScheme, K> = {
socketPositionWatcher?: SocketPositionWatcher<Scope<never, [K]>>,
socketPositionWatcher?: SocketPositionWatcher<Scope<never, [K]>>
customize?: CustomizationProps<Schemes>
}

/**
* Classic preset for rendering nodes, connections, controls and sockets.
*/
export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Schemes>>(
props?: ClassicProps<Schemes, K>
): RenderPreset<Schemes, K> {
export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Schemes>>(props?: ClassicProps<Schemes, K>): RenderPreset<Schemes, K> {
const positionWatcher = typeof props?.socketPositionWatcher === 'undefined'
? getDOMSocketPosition<Schemes, K>()
: props?.socketPositionWatcher
: props.socketPositionWatcher
const { node, connection, socket, control } = props?.customize || {}

return {
Expand All @@ -60,8 +58,12 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche

return {
data: payload,
...(start ? { start } : {}),
...(end ? { end } : {})
...start
? { start }
: {},
...end
? { end }
: {}
}
}
return { data: payload }
Expand All @@ -72,21 +74,27 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
const emit = parent.emit.bind(parent)

if (context.data.type === 'node') {
const component = node ? node(context.data) : Node
const component = node
? node(context.data)
: Node

return component && {
component, props: {
component,
props: {
data: context.data.payload,
emit
}
}
} else if (context.data.type === 'connection') {
const component = connection ? connection(context.data) : Connection
const component = connection
? connection(context.data)
: Connection
const { payload } = context.data
const { source, target, sourceOutput, targetInput } = payload

return component && {
component: ConnectionWrapper, props: {
component: ConnectionWrapper,
props: {
data: context.data.payload,
component,
start: context.data.start || ((change: any) => positionWatcher.listen(source, 'output', sourceOutput, change)),
Expand All @@ -110,10 +118,13 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
}
} else if (context.data.type === 'socket') {
const { payload } = context.data
const component = socket ? socket(context.data) : Socket
const component = socket
? socket(context.data)
: Socket

return component && {
component, props: {
component,
props: {
data: payload
}
}
Expand All @@ -124,15 +135,17 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
const component = control(context.data)

return component && {
component, props: {
component,
props: {
data: payload
}
}
}

return context.data.payload instanceof ClassicPreset.InputControl
? {
component: Control, props: {
component: Control,
props: {
data: payload
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/presets/context-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import type { ContextMenuRender } from './types'
* Preset for rendering context menu.
*/
export function setup<Schemes extends BaseSchemes, K extends ContextMenuRender>(props?: { delay?: number }): RenderPreset<Schemes, K> {
const delay = typeof props?.delay === 'undefined' ? 1000 : props.delay
const delay = typeof props?.delay === 'undefined'
? 1000
: props.delay

return {
update(context) {
Expand Down
2 changes: 1 addition & 1 deletion src/presets/minimap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RenderSignal } from '../../types'
export type Rect = {
width: number
height: number
left: number,
left: number
top: number
}
export type Transform = {
Expand Down
6 changes: 3 additions & 3 deletions src/presets/reroute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type Props = {
*/
export function setup<Schemes extends BaseSchemes, K extends PinsRender>(props?: Props): RenderPreset<Schemes, K> {
const getProps = () => ({
menu: props?.contextMenu || (() => null),
translate: props?.translate || (() => null),
down: props?.pointerdown || (() => null)
menu: props?.contextMenu ?? (() => null),
translate: props?.translate ?? (() => null),
down: props?.pointerdown ?? (() => null)
})

return {
Expand Down
1 change: 1 addition & 0 deletions src/presets/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */
import type { BaseSchemes } from 'rete'
import type { ComponentType } from 'svelte'

Expand Down
1 change: 1 addition & 0 deletions src/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */
import type { ComponentType, SvelteComponent } from 'svelte'

import Root from './Root.svelte'
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "rete-cli/configs/tsconfig.json",
"compilerOptions": {
"strict": true,
"lib": [
"DOM"
]
Expand Down

0 comments on commit 7337e65

Please sign in to comment.