fixed linter errors

This commit is contained in:
Bartosz Sypytkowski 2023-08-17 20:20:49 +02:00
parent 10cf4b44f8
commit d25307c355
10 changed files with 300 additions and 285 deletions

View File

@ -8,10 +8,9 @@ import {
readYXmlFragment,
readYXmlHook,
readYXmlText,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType, // eslint-disable-line
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType, ID, // eslint-disable-line
readYWeakLink,
unlinkFrom,
ID
unlinkFrom
} from '../internals.js'
import * as error from 'lib0/error'
@ -113,7 +112,7 @@ export class ContentType {
if (this.type.constructor === WeakLink) {
// when removing weak links, remove references to them
// from type they're pointing to
const type = /** @type {WeakLink<any>} */ (this.type);
const type = /** @type {WeakLink<any>} */ (this.type)
const end = /** @type {ID} */ (type._quoteEnd.item)
for (let item = type._firstItem; item !== null; item = item.right) {
if (item.linked) {
@ -121,7 +120,7 @@ export class ContentType {
}
const lastId = item.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
}
type._firstItem = null

View File

@ -581,7 +581,7 @@ export class Item extends AbstractStruct {
// notify links about changes
const linkedBy = transaction.doc.store.linkedBy.get(this)
if (linkedBy !== undefined) {
for (let link of linkedBy) {
for (const link of linkedBy) {
addChangedTypeToTransaction(transaction, link, this.parentSub)
}
}
@ -695,7 +695,7 @@ export class Item extends AbstractStruct {
const allLinks = transaction.doc.store.linkedBy
const linkedBy = allLinks.get(this)
if (linkedBy !== undefined) {
for (let link of linkedBy) {
for (const link of linkedBy) {
addChangedTypeToTransaction(transaction, link, this.parentSub)
}
allLinks.delete(this)

View File

@ -246,7 +246,7 @@ export const callTypeObservers = (type, transaction, event, visitedLinks = null)
} else if (type._item.linked) {
const linkedBy = transaction.doc.store.linkedBy.get(type._item)
if (linkedBy !== undefined) {
for (let link of linkedBy) {
for (const link of linkedBy) {
if (visitedLinks === null || !visitedLinks.has(link)) {
visitedLinks = visitedLinks !== null ? visitedLinks : new Set()
visitedLinks.add(link)

View File

@ -16,8 +16,7 @@ import {
YArrayRefID,
callTypeObservers,
transact,
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
YWeakLink,
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, YWeakLink, // eslint-disable-line
arrayWeakLink
} from '../internals.js'
import { typeListSlice } from './AbstractType.js'

View File

@ -14,8 +14,7 @@ import {
YMapRefID,
callTypeObservers,
transact,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
YWeakLink,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, YWeakLink, // eslint-disable-line
mapWeakLink
} from '../internals.js'

View File

@ -27,14 +27,13 @@ import {
typeMapGetAll,
updateMarkerChanges,
ContentType,
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction, // eslint-disable-line
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction, YWeakLink, // eslint-disable-line
quoteText
} from '../internals.js'
import * as object from 'lib0/object'
import * as map from 'lib0/map'
import * as error from 'lib0/error'
import { WeakLink } from 'yjs'
/**
* @param {any} a
@ -1067,7 +1066,7 @@ export class YText extends AbstractType {
*
* @param {number} index The index where quoted range should start
* @param {number} length Number of quoted elements
* @return {WeakLink<string>}
* @return {YWeakLink<string>}
*
* @public
*/
@ -1263,6 +1262,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
// startOffset represents offset at current block from which we're intersted in picking string
// if it's -1 it means, we're out of scope and we should break at this point
let startOffset = start === null ? 0 : -1
// eslint-disable-next-line no-labels
loop: while (n !== null) {
if (startOffset < 0 && start !== null) {
if (start.client === n.id.client && start.clock >= n.id.clock && start.clock < n.id.clock + n.length) {
@ -1287,7 +1287,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
packStr()
currentAttributes.delete('ychange')
}
let s = /** @type {ContentString} */ (n.content).str
const s = /** @type {ContentString} */ (n.content).str
if (startOffset > 0) {
str += s.slice(startOffset)
startOffset = 0
@ -1296,8 +1296,9 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
const endOffset = n.id.clock + n.length - end.clock - 1
str += s.slice(0, s.length + endOffset) // scope is negative
packStr()
// eslint-disable-next-line no-labels
break loop
} else if (startOffset == 0) {
} else if (startOffset === 0) {
str += s
}
break
@ -1330,7 +1331,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
}
} else if (end !== null && end.client === n.id.client && end.clock >= n.id.clock && end.clock < n.id.clock + n.length) {
// block may not passed visibility check, but we still need to verify boundaries
break;
break
}
n = n.right
}

View File

@ -1,8 +1,8 @@
import { decoding, encoding, error } from "lib0"
import { decoding, encoding, error } from 'lib0'
import * as map from 'lib0/map'
import * as set from 'lib0/set'
import {
YEvent, Transaction, ID, GC, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item,
YEvent, AbstractType,
transact,
getItemCleanEnd,
createID,
@ -12,14 +12,13 @@ import {
writeID,
readID,
RelativePosition,
ItemTextListPosition,
ContentString,
rangeDelta,
formatXmlString,
Snapshot,
YText,
YXmlText
} from "../internals.js"
YXmlText,
Transaction, Item, Doc, ID, Snapshot, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ItemTextListPosition // eslint-disable-line
} from '../internals.js'
/**
* @template T extends AbstractType<any>
@ -31,6 +30,7 @@ export class YWeakLinkEvent extends YEvent {
* @param {YWeakLink<T>} ylink The YWeakLink to which this event was propagated to.
* @param {Transaction} transaction
*/
// eslint-disable-next-line no-useless-constructor
constructor (ylink, transaction) {
super(ylink, transaction)
}
@ -84,7 +84,7 @@ export class YWeakLink extends AbstractType {
}
}
return undefined;
return undefined
}
/**
@ -103,7 +103,7 @@ export class YWeakLink extends AbstractType {
}
const lastId = item.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
item = item.right
}
@ -139,12 +139,12 @@ export class YWeakLink extends AbstractType {
/** @type {Item|null} */
let item = firstItem
let end = /** @type {ID} */ (this._quoteEnd.item)
const end = /** @type {ID} */ (this._quoteEnd.item)
for (;item !== null; item = item.right) {
createLink(transaction, item, this)
const lastId = item.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
}
})
@ -198,7 +198,7 @@ export class YWeakLink extends AbstractType {
toString () {
if (this._firstItem !== null) {
switch (/** @type {AbstractType<any>} */ (this._firstItem.parent).constructor) {
case YText:
case YText: {
let str = ''
/**
* @type {Item|null}
@ -211,12 +211,12 @@ export class YWeakLink extends AbstractType {
}
const lastId = n.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
n = n.right
}
return str
}
case YXmlText:
return this.toDelta().map(delta => formatXmlString(delta)).join('')
}
@ -243,7 +243,6 @@ export class YWeakLink extends AbstractType {
}
}
/**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @return {YWeakLink<any>}
@ -280,7 +279,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
if (index > 0) {
startItem = getItemCleanStart(transaction, createID(startItem.id.client, startItem.id.clock + index))
}
break;
break
}
index -= startItem.length
}
@ -293,7 +292,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
remaining -= endItem.length
} else {
endItem = getItemCleanEnd(transaction, transaction.doc.store, createID(endItem.id.client, endItem.id.clock + remaining - 1))
break;
break
}
}
}
@ -308,7 +307,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
createLink(transaction, item, link)
const lastId = item.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
}
})
@ -350,7 +349,7 @@ export const quoteText = (transaction, parent, pos, length) => {
createLink(transaction, item, link)
const lastId = item.lastId
if (lastId.client === end.client && lastId.clock === end.clock) {
break;
break
}
}
})
@ -438,12 +437,12 @@ export const joinLinkedRange = (transaction, item) => {
const rightLinks = allLinks.get(/** @type {Item} */ (item.right))
if (leftLinks && rightLinks) {
const common = new Set()
for (let link of leftLinks) {
for (const link of leftLinks) {
if (rightLinks.has(link)) {
common.add(link)
}
}
if (common.size != 0) {
if (common.size !== 0) {
allLinks.set(item, common)
}
}

View File

@ -2,8 +2,7 @@
import {
GC,
splitItem,
Transaction, ID, Item, DSDecoderV2, // eslint-disable-line
YWeakLink
Transaction, ID, Item, DSDecoderV2, YWeakLink // eslint-disable-line
} from '../internals.js'
import * as math from 'lib0/math'

View File

@ -1,6 +1,6 @@
import * as Y from '../src/index.js'
import * as t from 'lib0/testing'
import { init, compare } from './testHelper.js'
import { init } from './testHelper.js'
/**
* @param {t.TestCase} tc
@ -63,11 +63,11 @@ export const testArrayQuoteMultipleElements = tc => {
const link1 = array1.get(0)
let unquoted = link1.unquote()
t.compare(unquoted[0], 2)
t.compare(unquoted[1].toJSON(), {'key':'value'})
t.compare(unquoted[1].toJSON(), { key: 'value' })
t.compare(unquoted[2], 3)
t.compare(array1.get(1), 1)
t.compare(array1.get(2), 2)
t.compare(array1.get(3).toJSON(), {'key':'value'})
t.compare(array1.get(3).toJSON(), { key: 'value' })
t.compare(array1.get(4), 3)
array1.insert(3, ['A', 'B'])
@ -75,7 +75,7 @@ export const testArrayQuoteMultipleElements = tc => {
t.compare(unquoted[0], 2)
t.compare(unquoted[1], 'A')
t.compare(unquoted[2], 'B')
t.compare(unquoted[3].toJSON(), {'key':'value'})
t.compare(unquoted[3].toJSON(), { key: 'value' })
t.compare(unquoted[4], 3)
testConnector.flushAllMessages()
@ -102,7 +102,7 @@ export const testSelfQuotation = tc => {
testConnector.flushAllMessages()
const link1 = array1.get(1)
let unquoted = link1.unquote()
const unquoted = link1.unquote()
t.compare(unquoted, [1, link1, 2, 3])
t.compare(array1.get(0), 1)
t.compare(array1.get(1), link1)
@ -115,7 +115,7 @@ export const testSelfQuotation = tc => {
* @param {t.TestCase} tc
*/
export const testUpdate = tc => {
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
const { testConnector, map0, map1 } = init(tc, { users: 2 })
map0.set('a', new Y.Map([['a1', 'hello']]))
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
map0.set('b', link0)
@ -139,7 +139,7 @@ export const testUpdate = tc => {
* @param {t.TestCase} tc
*/
export const testDeleteWeakLink = tc => {
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
const { testConnector, map0, map1 } = init(tc, { users: 2 })
map0.set('a', new Y.Map([['a1', 'hello']]))
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
map0.set('b', link0)
@ -164,15 +164,15 @@ export const testDeleteWeakLink = tc => {
* @param {t.TestCase} tc
*/
export const testDeleteSource = tc => {
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
const { testConnector, map0, map1 } = init(tc, { users: 2 })
map0.set('a', new Y.Map([['a1', 'hello']]))
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
map0.set('b', link0)
testConnector.flushAllMessages()
const link1 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map1.get('b'))
let l1 = /** @type {Y.Map<any>} */ (link1.deref())
let l0 = /** @type {Y.Map<any>} */ (link0.deref())
const l1 = /** @type {Y.Map<any>} */ (link1.deref())
const l0 = /** @type {Y.Map<any>} */ (link0.deref())
t.compare(l1.get('a1'), l0.get('a1'))
map1.delete('a') // delete source of the link
@ -188,7 +188,7 @@ export const testDeleteSource = tc => {
* @param {t.TestCase} tc
*/
export const testObserveMapUpdate = tc => {
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
const { testConnector, map0, map1 } = init(tc, { users: 2 })
map0.set('a', 'value')
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
map0.set('b', link0)
@ -196,17 +196,21 @@ export const testObserveMapUpdate = tc => {
* @type {any}
*/
let target0
link0.observe((e) => target0 = e.target)
link0.observe((e) => {
target0 = e.target
})
testConnector.flushAllMessages()
let link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
const link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
t.compare(link1.deref(), 'value')
/**
* @type {any}
*/
let target1
link1.observe((e) => target1 = e.target)
link1.observe((e) => {
target1 = e.target
})
map0.set('a', 'value2')
t.compare(target0.deref(), 'value2')
@ -219,7 +223,7 @@ export const testObserveMapUpdate = tc => {
* @param {t.TestCase} tc
*/
export const testObserveMapDelete = tc => {
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
const { testConnector, map0, map1 } = init(tc, { users: 2 })
map0.set('a', 'value')
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
map0.set('b', link0)
@ -227,17 +231,21 @@ export const testObserveMapDelete = tc => {
* @type {any}
*/
let target0
link0.observe((e) => target0 = e.target)
link0.observe((e) => {
target0 = e.target
})
testConnector.flushAllMessages()
let link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
const link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
t.compare(link1.deref(), 'value')
/**
* @type {any}
*/
let target1
link1.observe((e) => target1 = e.target)
link1.observe((e) => {
target1 = e.target
})
map0.delete('a')
t.compare(target0.deref(), undefined)
@ -257,17 +265,21 @@ export const testObserveArray = tc => {
* @type {any}
*/
let target0
link0.observe((e) => target0 = e.target)
link0.observe((e) => {
target0 = e.target
})
testConnector.flushAllMessages()
let link1 = /** @type {Y.WeakLink<String>} */ (array1.get(0))
const link1 = /** @type {Y.WeakLink<String>} */ (array1.get(0))
t.compare(link1.unquote(), ['B', 'C'])
/**
* @type {any}
*/
let target1
link1.observe((e) => target1 = e.target)
link1.observe((e) => {
target1 = e.target
})
array0.delete(2)
t.compare(target0.unquote(), ['C'])
@ -315,7 +327,9 @@ export const testDeepObserveTransitive = tc => {
* @type {Array<any>}
*/
let events = []
link2.observeDeep((e) => events = e)
link2.observeDeep((e) => {
events = e
})
map2.set('key', 'value2')
const values = events.map((e) => e.target.deref())
t.compare(values, ['value2'])
@ -354,7 +368,9 @@ export const testDeepObserveTransitive2 = tc => {
* @type {Array<any>}
*/
let events = []
link3.observeDeep((e) => events = e)
link3.observeDeep((e) => {
events = e
})
map2.set('key', 'value2')
const values = events.map((e) => e.target.deref())
t.compare(values, ['value2'])
@ -381,7 +397,9 @@ export const testDeepObserveMap = tc => {
* @type {Array<any>}
*/
let events = []
map.observeDeep((e) => events = e)
map.observeDeep((e) => {
events = e
})
const nested = new Y.Map()
array.insert(0, [nested])
@ -436,14 +454,14 @@ export const testDeepObserveArray = tc => { //FIXME
let events = []
array.observeDeep((evts) => {
events = []
for (let e of evts) {
for (const e of evts) {
switch (e.constructor) {
case Y.YMapEvent:
events.push({ target: e.target, keys: e.keys })
break;
break
case Y.YWeakLinkEvent:
events.push({ target: e.target })
break;
break
default: throw new Error('unexpected event type ' + e.constructor)
}
}
@ -477,7 +495,7 @@ export const testDeepObserveArray = tc => { //FIXME
* @param {t.TestCase} tc
*/
export const testDeepObserveNewElementWithinQuotedRange = tc => {
const { testConnector, users, array0, array1 } = init(tc, { users: 2 })
const { testConnector, array0, array1 } = init(tc, { users: 2 })
const m1 = new Y.Map()
const m3 = new Y.Map()
array0.insert(0, [1, m1, m3, 2])
@ -492,14 +510,14 @@ export const testDeepObserveNewElementWithinQuotedRange = tc => {
let e0 = []
link0.observeDeep((evts) => {
e0 = []
for (let e of evts) {
for (const e of evts) {
switch (e.constructor) {
case Y.YMapEvent:
e0.push({ target: e.target, keys: e.keys })
break;
break
case Y.YWeakLinkEvent:
e0.push({ target: e.target })
break;
break
default: throw new Error('unexpected event type ' + e.constructor)
}
}
@ -512,14 +530,14 @@ export const testDeepObserveNewElementWithinQuotedRange = tc => {
let e1 = []
link1.observeDeep((evts) => {
e1 = []
for (let e of evts) {
for (const e of evts) {
switch (e.constructor) {
case Y.YMapEvent:
e1.push({ target: e.target, keys: e.keys })
break;
break
case Y.YWeakLinkEvent:
e1.push({ target: e.target })
break;
break
default: throw new Error('unexpected event type ' + e.constructor)
}
}
@ -556,20 +574,19 @@ export const testMapDeepObserve = tc => { //FIXME
let events = []
outer.observeDeep((evts) => {
events = []
for (let e of evts) {
for (const e of evts) {
switch (e.constructor) {
case Y.YMapEvent:
events.push({ target: e.target, keys: e.keys })
break;
break
case Y.YWeakLinkEvent:
events.push({ target: e.target })
break;
break
default: throw new Error('unexpected event type ' + e.constructor)
}
}
})
inner.set('key', 'value1')
t.compare(events.length, 1)
t.compare(events[0].target, inner)
@ -629,7 +646,9 @@ export const testDeepObserveRecursive = tc => {
* @type {Array<any>}
*/
let events = []
m0.observeDeep((e) => events = e)
m0.observeDeep((e) => {
events = e
})
m1.set('test-key1', 'value1')
t.compare(events.length, 1)
@ -750,6 +769,6 @@ export const testQuoteFormattedText = tc => {
t.compare(delta, [
{ insert: l1 },
{ insert: l2 },
{insert: l3},
{ insert: l3 }
])
}