Skip to content

Commit

Permalink
Merge pull request #36 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 537cc94 + 2a844fe commit 634d65b
Show file tree
Hide file tree
Showing 10 changed files with 2,124 additions and 1,643 deletions.
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
}
}
}
)
3,690 changes: 2,080 additions & 1,610 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 @@ -28,9 +28,10 @@
"rete-render-utils": "^2.0.0"
},
"devDependencies": {
"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",
"typescript": "4.8.4"
},
Expand Down
5 changes: 2 additions & 3 deletions src/extensions/selectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ReroutePlugin } from '..'
* @listens pintranslated
*/
export function selectablePins<S extends BaseSchemes>(reroutePlugin: ReroutePlugin<S>, selector: Selector, accumulating: { active(): boolean }) {

Check warning on line 17 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / release / publish

This line has a length of 145. Maximum allowed is 120

Check warning on line 17 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / release / publish

This line has a length of 145. Maximum allowed is 120
// eslint-disable-next-line max-statements
reroutePlugin.addPipe(context => {
if (!('type' in context)) return context

Expand All @@ -26,10 +25,10 @@ export function selectablePins<S extends BaseSchemes>(reroutePlugin: ReroutePlug
id,
label: 'pin',
translate(dx, dy) {
reroutePlugin.translate(id, dx, dy)
void reroutePlugin.translate(id, dx, dy)
},
unselect() {
reroutePlugin.unselect(id)
void reroutePlugin.unselect(id)
}
}, accumulating.active())
selector.pick({ id, label: 'pin' })
Expand Down
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<ReroutePro
if (!this.pinParents.has(element)) {
const pinContainer = document.createElement('div')

pinContainer.dataset['type'] = 'pin-container'
pinContainer.dataset.type = 'pin-container'
this.pinContainers.set(id, { element: pinContainer })
this.pinParents.set(element, { id, pinContainer })
area.area.content.add(pinContainer)
Expand All @@ -78,7 +78,7 @@ export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<ReroutePro
if (record) {
this.pinParents.delete(element)
this.pinContainers.delete(record.id)
area.emit({ type: 'unmount', data: { element: record.pinContainer } })
void area.emit({ type: 'unmount', data: { element: record.pinContainer } })
area.area.content.remove(record.pinContainer)
}
}
Expand All @@ -101,8 +101,9 @@ export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<ReroutePro
const pins = this.pins.getPins(id)

if (container) {
area.emit({
type: 'render', data: {
void area.emit({
type: 'render',
data: {
type: 'reroute-pins',
element: container.element,
data: { id, pins }
Expand Down Expand Up @@ -169,7 +170,7 @@ export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<ReroutePro
const pin = { id: getUID(), position }

this.pins.add(connectionId, pin, index)
area.update('connection', connectionId)
void area.update('connection', connectionId)
}

/**
Expand Down Expand Up @@ -235,10 +236,12 @@ export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<ReroutePro
public update(pin: string | PinStorageRecord) {
type Base = BaseAreaPlugin<Schemes, BaseArea<Schemes> | RerouteExtra>

const pinRecord = typeof pin === 'object' ? pin : this.pins.getPin(pin)
const pinRecord = typeof pin === 'object'
? pin
: this.pins.getPin(pin)
const area = this.parentScope().parentScope<Base>(BaseAreaPlugin)

if (!pinRecord) return
area.update('connection', pinRecord.connectionId)
void area.update('connection', pinRecord.connectionId)
}
}
6 changes: 4 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export function getPinsStorage() {
if (pins.has(pin.id)) throw new Error('already exists')
const data = { ...pin, connectionId }
const list = [...connectionPins.get(connectionId) || []]

Check warning on line 15 in src/storage.ts

View workflow job for this annotation

GitHub Actions / release / publish

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

Check warning on line 15 in src/storage.ts

View workflow job for this annotation

GitHub Actions / release / publish

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
// eslint-disable-next-line @typescript-eslint/naming-convention
const _index = typeof index === 'number' ? index : list.length

const _index = typeof index === 'number'
? index
: list.length

list.splice(_index, 0, data)
connectionPins.set(connectionId, list)
Expand Down
19 changes: 8 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export function distance(point0: Position, point1: Position) {
return Math.sqrt(Math.pow(point1.x - point0.x, 2) + Math.pow(point1.y - point0.y, 2))
}

// eslint-disable-next-line max-statements
export function findRightIndex(point: Position, line: Position[] = []) {
let minIdx = -1
let minDist = Infinity
Expand All @@ -57,7 +56,7 @@ export function findRightIndex(point: Position, line: Position[] = []) {
return minIdx
}

// eslint-disable-next-line max-statements, complexity
// eslint-disable-next-line complexity
export function pointInBound(p0: Position, p1: Position, p2: Position) {
const { x: x1, y: y1 } = p1
const { x: x2, y: y2 } = p2
Expand All @@ -81,10 +80,10 @@ export function pointInBound(p0: Position, p1: Position, p2: Position) {

export function distanceToLine(p0: Position, p1: Position, p2: Position) {
const top = (p2.y - p1.y) * p0.x
- (p2.x - p1.x) * p0.y
+ p2.x * p1.y
- p2.y * p1.x
const bot = Math.pow((p2.y - p1.y), 2) + Math.pow((p2.x - p1.x), 2)
- (p2.x - p1.x) * p0.y
+ p2.x * p1.y
- p2.y * p1.x
const bot = Math.pow(p2.y - p1.y, 2) + Math.pow(p2.x - p1.x, 2)

return Math.abs(top) / Math.sqrt(bot)
}
Expand All @@ -106,10 +105,8 @@ export function alignEndsHorizontally(points: [number, number][], curvature: num

type Root = Element | DocumentFragment

/* eslint-disable no-undef */
type TagMap = HTMLElementTagNameMap
type SVGMap = SVGElementTagNameMap
/* eslint-enable no-undef */

export function deepQuerySelector<K extends keyof TagMap>(root: Root, selectors: K): TagMap[K] | null
export function deepQuerySelector<K extends keyof SVGMap>(root: Root, selectors: K): SVGMap[K] | null
Expand All @@ -119,10 +116,10 @@ export function deepQuerySelector(root: Root, selector: string): Element | null

if (element) return element

const childNodes = root.querySelectorAll('*')
const childNodes = Array.from(root.querySelectorAll('*'))

for (let i = 0; i < childNodes.length; i++) {
const shadowRoot = (childNodes[i] as Element).shadowRoot
for (const node of childNodes) {
const shadowRoot = node.shadowRoot

if (shadowRoot) {
const found = deepQuerySelector(shadowRoot, selector)
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"compilerOptions": {
"strict": true
},
"extends": "rete-cli/configs/tsconfig.json",
"include": ["src"]
}

0 comments on commit 634d65b

Please sign in to comment.