Linting fixes

This commit is contained in:
Jos de Jong 2020-09-02 11:39:50 +02:00
parent d3c3d47ec0
commit 023c57f492
24 changed files with 360 additions and 386 deletions

View File

@ -26,6 +26,6 @@ export const SIMPLE_MODAL_OPTIONS = {
},
styleContent: {
padding: '0px',
overflow: 'visible', // needed for select box dropdowns which are larger than the modal
overflow: 'visible' // needed for select box dropdowns which are larger than the modal
}
}

View File

@ -24,9 +24,9 @@ describe('documentState', () => {
const expectedState = {}
expectedState[STATE_EXPANDED] = true
expectedState[STATE_PROPS] = [
{ 'id': state[STATE_PROPS][0].id, 'key': 'array' },
{ 'id': state[STATE_PROPS][1].id, 'key': 'object' },
{ 'id': state[STATE_PROPS][2].id, 'key': 'value' }
{ id: state[STATE_PROPS][0].id, key: 'array' },
{ id: state[STATE_PROPS][1].id, key: 'object' },
{ id: state[STATE_PROPS][2].id, key: 'value' }
]
expectedState.array = []
expectedState.array[STATE_EXPANDED] = true
@ -34,13 +34,13 @@ describe('documentState', () => {
expectedState.array[2] = {}
expectedState.array[2][STATE_EXPANDED] = false
expectedState.array[2][STATE_PROPS] = [
{ 'id': state.array[2][STATE_PROPS][0].id, 'key': 'c' } // FIXME: props should not be created because node is not expanded
{ id: state.array[2][STATE_PROPS][0].id, key: 'c' } // FIXME: props should not be created because node is not expanded
]
expectedState.object = {}
expectedState.object[STATE_EXPANDED] = true
expectedState.object[STATE_PROPS] = [
{ 'id': state.object[STATE_PROPS][0].id, 'key': 'a' },
{ 'id': state.object[STATE_PROPS][1].id, 'key': 'b' }
{ id: state.object[STATE_PROPS][0].id, key: 'a' },
{ id: state.object[STATE_PROPS][1].id, key: 'b' }
]
assert.deepStrictEqual(state, expectedState)

View File

@ -33,8 +33,7 @@ export function insertBefore (json, path, values, nextKeys) { // TODO: find a b
path: compileJSONPointer(parentPath.concat(offset + index)),
value: entry.value
}))
}
else { // 'object'
} else { // 'object'
return [
// insert new values
...values.map(entry => {
@ -75,8 +74,7 @@ export function append (json, path, values) { // TODO: find a better name and d
path: compileJSONPointer(path.concat(offset + index)),
value: entry.value
}))
}
else { // 'object'
} else { // 'object'
return values.map(entry => {
const newProp = findUniqueName(entry.key, parent)
return {
@ -149,8 +147,7 @@ export function replace (json, paths, values, nextKeys) { // TODO: find a bette
value: entry.value
}))
]
}
else { // parent is Object
} else { // parent is Object
// if we're going to replace an existing object with key "a" with a new
// key "a", we must not create a new unique name "a (copy)".
const removeKeys = new Set(paths.map(path => last(path)))

View File

@ -3,7 +3,6 @@ import { STATE_SEARCH_PROPERTY, STATE_SEARCH_VALUE } from '../constants.js'
import { existsIn, setIn } from '../utils/immutabilityHelpers.js'
import { valueType } from '../utils/typeUtils.js'
/**
* @typedef {{path: Path, what: Symbol}} SearchItem
*/
@ -101,7 +100,7 @@ export function searchPrevious (searchResult) {
}
function searchRecursive (key, doc, searchText) {
let results = undefined
let results
if (typeof key === 'string' && containsCaseInsensitive(key, searchText)) {
results = createOrAdd(results, STATE_SEARCH_PROPERTY, 'search')
@ -110,14 +109,14 @@ function searchRecursive (key, doc, searchText) {
const type = valueType(doc)
if (type === 'array') {
doc.forEach((item, index) => {
let childResults = searchRecursive(index, item, searchText)
const childResults = searchRecursive(index, item, searchText)
if (childResults) {
results = createOrAdd(results, index, childResults)
}
})
} else if (type === 'object') {
Object.keys(doc).forEach(prop => {
let childResults = searchRecursive(prop, doc[prop], searchText)
const childResults = searchRecursive(prop, doc[prop], searchText)
if (childResults) {
results = createOrAdd(results, prop, childResults)
}

View File

@ -10,7 +10,7 @@ import { existsIn, setIn } from '../utils/immutabilityHelpers.js'
* @return {Object.<string, string> | undefined} Returns a nested object containing
*/
export function mapValidationErrors (validationErrors) {
let object = undefined
let object
validationErrors.forEach(validationError => {
const errorPath = validationError.path.concat([VALIDATION_ERROR])

View File

@ -1,4 +1,4 @@
import assert from "assert"
import assert from 'assert'
import { compareArrays, getNestedPaths } from './arrayUtils.js'
describe('arrayUtils', () => {

View File

@ -26,8 +26,7 @@ export function setPlainText(element, text) {
export function escapeHTML (text, escapeUnicode = false) {
if (typeof text !== 'string') {
return String(text)
}
else {
} else {
let htmlEscaped = String(text)
if (escapeUnicode === true) {
// FIXME: should not unescape the just created non-breaking spaces \u00A0 ?
@ -88,8 +87,7 @@ export function escapeJSON (text) {
let c = text.charAt(i)
if (c === '\n') {
escaped += '\\n'
}
else if (c === '\\') {
} else if (c === '\\') {
escaped += c
i++
@ -98,11 +96,9 @@ export function escapeJSON (text) {
escaped += '\\' // no valid escape character
}
escaped += c
}
else if (c === '"') {
} else if (c === '"') {
escaped += '\\"'
}
else {
} else {
escaped += c
}
i++

View File

@ -23,20 +23,22 @@ export function shallowClone (value) {
const copy = value.slice()
// copy all symbols
Object.getOwnPropertySymbols(value).forEach(symbol => copy[symbol] = value[symbol])
Object.getOwnPropertySymbols(value).forEach(symbol => {
copy[symbol] = value[symbol]
})
return copy
}
else if (typeof value === 'object') {
} else if (typeof value === 'object') {
// copy object properties
const copy = { ...value }
// copy all symbols
Object.getOwnPropertySymbols(value).forEach(symbol => copy[symbol] = value[symbol])
Object.getOwnPropertySymbols(value).forEach(symbol => {
copy[symbol] = value[symbol]
})
return copy
}
else {
} else {
return value
}
}
@ -53,8 +55,7 @@ export function applyProp (object, key, value) {
if (object[key] === value) {
// return original object unchanged when the new value is identical to the old one
return object
}
else {
} else {
const updatedObject = shallowClone(object)
updatedObject[key] = value
return updatedObject
@ -76,8 +77,7 @@ export function getIn (object, path) {
while (i < path.length) {
if (isObjectOrArray(value)) {
value = value[path[i]]
}
else {
} else {
value = undefined
}
@ -171,14 +171,12 @@ export function deleteIn (object, path) {
if (!(key in object)) {
// key doesn't exist. return object unchanged
return object
}
else {
} else {
const updatedObject = shallowClone(object)
if (Array.isArray(updatedObject)) {
updatedObject.splice(key, 1)
}
else {
} else {
delete updatedObject[key]
}
@ -230,7 +228,7 @@ export function transform (json, callback, path = []) {
const updated1 = callback(json, path)
if (Array.isArray(json)) { // array
let updated2 = undefined
let updated2
for (let i = 0; i < updated1.length; i++) {
const before = updated1[i]
@ -246,13 +244,12 @@ export function transform (json, callback, path = []) {
}
}
return updated2 ? updated2 : updated1
}
else if (json && typeof json === 'object') { // object
let updated2 = undefined
return updated2 || updated1
} else if (json && typeof json === 'object') { // object
let updated2
for (let key in updated1) {
if (updated1.hasOwnProperty(key)) {
for (const key in updated1) {
if (Object.hasOwnProperty.call(updated1, key)) {
const before = updated1[key]
const after = transform(before, callback, path.concat(key))
if (after !== before) {
@ -264,9 +261,8 @@ export function transform (json, callback, path = []) {
}
}
return updated2 ? updated2 : updated1
}
else { // number, string, boolean, null
return updated2 || updated1
} else { // number, string, boolean, null
return updated1
}
}

View File

@ -353,12 +353,12 @@ describe('immutabilityHelpers', () => {
it('existsIn', () => {
const json = {
"obj": {
"arr": [1,2, {"first":3,"last":4}]
obj: {
arr: [1, 2, { first: 3, last: 4 }]
},
"str": "hello world",
"nill": null,
"bool": false
str: 'hello world',
nill: null,
bool: false
}
assert.deepStrictEqual(existsIn(json, ['obj', 'arr', 2, 'first']), true)
@ -368,15 +368,6 @@ describe('immutabilityHelpers', () => {
})
it('existsIn should find symbols', () => {
const json = {
"obj": {
"arr": [1,2, {"first":3,"last":4}]
},
"str": "hello world",
"nill": null,
"bool": false
}
const symbol = Symbol('mySymbol')
const arrWithSymbol = [1, 2, 3]

View File

@ -22,8 +22,8 @@ export function immutableJSONPatch (json, operations) {
for (let i = 0; i < operations.length; i++) {
const operation = operations[i]
const path = operation.path != undefined ? parseJSONPointer(operation.path) : null
const from = operation.from != undefined ? parseJSONPointer(operation.from) : null
const path = operation.path !== undefined ? parseJSONPointer(operation.path) : null
const from = operation.from !== undefined ? parseJSONPointer(operation.from) : null
switch (operation.op) {
case 'add': {
@ -176,8 +176,7 @@ export function add (json, path, value) {
value: oldValue
}]
}
}
else {
} else {
return {
json: updatedJson,
revert: [{
@ -239,8 +238,7 @@ export function move (json, path, from) {
}
]
}
}
else {
} else {
return {
json: updatedJson,
revert: [

View File

@ -87,7 +87,7 @@ describe('immutableJSONPatch', () => {
const patch = [
{ op: 'remove', path: '/obj/a' },
{op: 'remove', path: '/arr/1'},
{ op: 'remove', path: '/arr/1' }
]
const result = immutableJSONPatch(json, patch)
@ -119,7 +119,7 @@ describe('immutableJSONPatch', () => {
const patch = [
{ op: 'replace', path: '/obj/a', value: 400 },
{op: 'replace', path: '/arr/1', value: 200},
{ op: 'replace', path: '/arr/1', value: 200 }
]
const result = immutableJSONPatch(json, patch)
@ -164,7 +164,7 @@ describe('immutableJSONPatch', () => {
}
const patch = [
{op: 'copy', from: '/obj', path: '/arr/2'},
{ op: 'copy', from: '/obj', path: '/arr/2' }
]
const result = immutableJSONPatch(json, patch)
@ -196,7 +196,7 @@ describe('immutableJSONPatch', () => {
}
const patch = [
{op: 'move', from: '/obj', path: '/arr/2'},
{ op: 'move', from: '/obj', path: '/arr/2' }
]
const result = immutableJSONPatch(json, patch)
@ -223,7 +223,7 @@ describe('immutableJSONPatch', () => {
const json = { a: 2, b: 3 }
const patch = [
{op: 'move', from: '/a', path: '/b'},
{ op: 'move', from: '/a', path: '/b' }
]
const result = immutableJSONPatch(json, patch)
@ -252,7 +252,7 @@ describe('immutableJSONPatch', () => {
}
const patch = [
{op: 'move', from: '/obj', path: '/arr'},
{ op: 'move', from: '/obj', path: '/arr' }
]
const result = immutableJSONPatch(json, patch)

View File

@ -23,7 +23,7 @@ export function nameFromKeyCode(code) {
* @return {string}
*/
export function keyComboFromEvent (event) {
let combi = []
const combi = []
if (event.ctrlKey) { combi.push('Ctrl') }
if (event.metaKey) { combi.push('Command') }
@ -48,7 +48,9 @@ export function createFindKeyBinding (keyBindings) {
// turn the map with key bindings by name (multiple per binding) into a map by key combo
const keyCombos = {}
Object.keys(keyBindings).forEach((name) => {
keyBindings[name].forEach(combo => keyCombos[normalizeKeyCombo(combo)] = name)
keyBindings[name].forEach(combo => {
keyCombos[normalizeKeyCombo(combo)] = name
})
})
return function findKeyBinding (event) {
@ -81,112 +83,112 @@ function normalizeKeyCombo (combo) {
const isMac = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0
const metaCodes = {
'Ctrl': true,
'Command': true,
'Alt': true,
'Option': true,
'Shift': true
Ctrl: true,
Command: true,
Alt: true,
Option: true,
Shift: true
}
const codes = {
'8': 'Backspace',
'9': 'Tab',
'13': 'Enter',
'16': 'Shift',
'17': 'Ctrl',
'18': 'Alt',
'19': 'Pause_Break',
'20': 'Caps_Lock',
'27': 'Escape',
'33': 'Page_Up',
'34': 'Page_Down',
'35': 'End',
'36': 'Home',
'37': 'Left',
'38': 'Up',
'39': 'Right',
'40': 'Down',
'45': 'Insert',
'46': 'Delete',
'48': '0',
'49': '1',
'50': '2',
'51': '3',
'52': '4',
'53': '5',
'54': '6',
'55': '7',
'56': '8',
'57': '9',
'65': 'A',
'66': 'B',
'67': 'C',
'68': 'D',
'69': 'E',
'70': 'F',
'71': 'G',
'72': 'H',
'73': 'I',
'74': 'J',
'75': 'K',
'76': 'L',
'77': 'M',
'78': 'N',
'79': 'O',
'80': 'P',
'81': 'Q',
'82': 'R',
'83': 'S',
'84': 'T',
'85': 'U',
'86': 'V',
'87': 'W',
'88': 'X',
'89': 'Y',
'90': 'Z',
'91': 'Left_Window_Key',
'92': 'Right_Window_Key',
'93': 'Select_Key',
'96': 'Numpad_0',
'97': 'Numpad_1',
'98': 'Numpad_2',
'99': 'Numpad_3',
'100': 'Numpad_4',
'101': 'Numpad_5',
'102': 'Numpad_6',
'103': 'Numpad_7',
'104': 'Numpad_8',
'105': 'Numpad_9',
'106': 'Numpad_*',
'107': 'Numpad_+',
'109': 'Numpad_-',
'110': 'Numpad_.',
'111': 'Numpad_/',
'112': 'F1',
'113': 'F2',
'114': 'F3',
'115': 'F4',
'116': 'F5',
'117': 'F6',
'118': 'F7',
'119': 'F8',
'120': 'F9',
'121': 'F10',
'122': 'F11',
'123': 'F12',
'144': 'Num_Lock',
'145': 'Scroll_Lock',
'186': ';',
'187': '=',
'188': ',',
'189': '-',
'190': '.',
'191': '/',
'192': '`',
'219': '[',
'220': '\\',
'221': ']',
'222': '\''
8: 'Backspace',
9: 'Tab',
13: 'Enter',
16: 'Shift',
17: 'Ctrl',
18: 'Alt',
19: 'Pause_Break',
20: 'Caps_Lock',
27: 'Escape',
33: 'Page_Up',
34: 'Page_Down',
35: 'End',
36: 'Home',
37: 'Left',
38: 'Up',
39: 'Right',
40: 'Down',
45: 'Insert',
46: 'Delete',
48: '0',
49: '1',
50: '2',
51: '3',
52: '4',
53: '5',
54: '6',
55: '7',
56: '8',
57: '9',
65: 'A',
66: 'B',
67: 'C',
68: 'D',
69: 'E',
70: 'F',
71: 'G',
72: 'H',
73: 'I',
74: 'J',
75: 'K',
76: 'L',
77: 'M',
78: 'N',
79: 'O',
80: 'P',
81: 'Q',
82: 'R',
83: 'S',
84: 'T',
85: 'U',
86: 'V',
87: 'W',
88: 'X',
89: 'Y',
90: 'Z',
91: 'Left_Window_Key',
92: 'Right_Window_Key',
93: 'Select_Key',
96: 'Numpad_0',
97: 'Numpad_1',
98: 'Numpad_2',
99: 'Numpad_3',
100: 'Numpad_4',
101: 'Numpad_5',
102: 'Numpad_6',
103: 'Numpad_7',
104: 'Numpad_8',
105: 'Numpad_9',
106: 'Numpad_*',
107: 'Numpad_+',
109: 'Numpad_-',
110: 'Numpad_.',
111: 'Numpad_/',
112: 'F1',
113: 'F2',
114: 'F3',
115: 'F4',
116: 'F5',
117: 'F6',
118: 'F7',
119: 'F8',
120: 'F9',
121: 'F10',
122: 'F11',
123: 'F12',
144: 'Num_Lock',
145: 'Scroll_Lock',
186: ';',
187: '=',
188: ',',
189: '-',
190: '.',
191: '/',
192: '`',
219: '[',
220: '\\',
221: ']',
222: '\''
}
// all secondary characters of the keyboard buttons (used via Shift)
@ -195,14 +197,14 @@ const aliases = {
'!': '1',
'@': '2',
'#': '3',
'$': '4',
$: '4',
'%': '5',
'^': '6',
'&': '7',
'*': '8',
'(': '9',
')': '0',
'_': '-',
_: '-',
'+': '=',
'{': '[',
'}': ']',

View File

@ -3,7 +3,7 @@ import { stringifyPath } from './pathUtils.js'
describe('pathUtils', () => {
it('stringifyPath', () => {
assert.strictEqual(stringifyPath(["data", 2, "nested", "property"]), '.data[2].nested.property')
assert.strictEqual(stringifyPath(['data', 2, 'nested', 'property']), '.data[2].nested.property')
assert.strictEqual(stringifyPath(['']), '.')
assert.strictEqual(stringifyPath([]), '')
})

View File

@ -9,13 +9,13 @@ import {
describe('stringUtils', () => {
it('findUniqueName', () => {
assert.deepStrictEqual(findUniqueName('other', {'a': true, 'b': true, 'c': true}), 'other')
assert.deepStrictEqual(findUniqueName('b', {'a': true, 'b': true, 'c': true}), 'b (copy)')
assert.deepStrictEqual(findUniqueName('b', {'a': true, 'b': true, 'c': true, 'b (copy)': true}), 'b (copy 2)')
assert.deepStrictEqual(findUniqueName('b (copy)', {'a': true, 'b': true, 'c': true, 'b (copy)': true}), 'b (copy 2)')
assert.deepStrictEqual(findUniqueName('b', {'a': true, 'b': true, 'c': true, 'b (copy)': true, 'b (copy 2)': true}), 'b (copy 3)')
assert.deepStrictEqual(findUniqueName('b (copy)', {'a': true, 'b': true, 'c': true, 'b (copy)': true, 'b (copy 2)': true}), 'b (copy 3)')
assert.deepStrictEqual(findUniqueName('b (copy 2)', {'a': true, 'b': true, 'c': true, 'b (copy)': true, 'b (copy 2)': true}), 'b (copy 3)')
assert.deepStrictEqual(findUniqueName('other', { a: true, b: true, c: true }), 'other')
assert.deepStrictEqual(findUniqueName('b', { a: true, b: true, c: true }), 'b (copy)')
assert.deepStrictEqual(findUniqueName('b', { a: true, b: true, c: true, 'b (copy)': true }), 'b (copy 2)')
assert.deepStrictEqual(findUniqueName('b (copy)', { a: true, b: true, c: true, 'b (copy)': true }), 'b (copy 2)')
assert.deepStrictEqual(findUniqueName('b', { a: true, b: true, c: true, 'b (copy)': true, 'b (copy 2)': true }), 'b (copy 3)')
assert.deepStrictEqual(findUniqueName('b (copy)', { a: true, b: true, c: true, 'b (copy)': true, 'b (copy 2)': true }), 'b (copy 3)')
assert.deepStrictEqual(findUniqueName('b (copy 2)', { a: true, b: true, c: true, 'b (copy)': true, 'b (copy 2)': true }), 'b (copy 3)')
})
it('toCapital', () => {

View File

@ -90,20 +90,15 @@ export function stringConvert (str) {
if (str === '') {
return ''
}
else if (str === 'null') {
} else if (str === 'null') {
return null
}
else if (str === 'true') {
} else if (str === 'true') {
return true
}
else if (str === 'false') {
} else if (str === 'false') {
return false
}
else if (!isNaN(num) && !isNaN(numFloat)) {
} else if (!isNaN(num) && !isNaN(numFloat)) {
return num
}
else {
} else {
return str
}
}