fix lgtm warnings and other minor fixes

This commit is contained in:
JFH
2021-12-30 23:18:43 -03:00
parent 88207acc98
commit ff34764955
17 changed files with 62 additions and 84 deletions

View File

@@ -24,10 +24,6 @@ const pathMap = [
* @function module:coords.EditorContext#getGridSnapping
* @returns {boolean}
*/
/**
* @function module:coords.EditorContext#getDrawing
* @returns {module:draw.Drawing}
*/
/**
* @function module:coords.EditorContext#getSvgRoot
* @returns {SVGSVGElement}
@@ -84,7 +80,7 @@ export const remapElement = function (selected, changes, m) {
newgrad.setAttribute('y1', -(y1 - 1))
newgrad.setAttribute('y2', -(y2 - 1))
}
newgrad.id = svgCanvas.getDrawing().getNextId()
newgrad.id = svgCanvas.getCurrentDrawing().getNextId()
findDefs().append(newgrad)
selected.setAttribute(type, 'url(#' + newgrad.id + ')')
}

View File

@@ -18,7 +18,7 @@ const dataStorage = {
},
remove: function (element, key) {
const ret = this._storage.get(element).delete(key)
if (!this._storage.get(element).size === 0) {
if (this._storage.get(element).size === 0) {
this._storage.delete(element)
}
return ret

View File

@@ -6,7 +6,7 @@
* @copyright 2010 Jeff Schiller
*/
import { getHref, setHref, getRotationAngle, isNullish, getBBox } from './utilities.js'
import { getHref, setHref, getRotationAngle, getBBox } from './utilities.js'
/**
* Group: Undo/Redo history management.
@@ -255,7 +255,7 @@ export class RemoveElementCommand extends Command {
*/
unapply (handler) {
super.unapply(handler, () => {
if (isNullish(this.nextSibling) && window.console) {
if (!this.nextSibling && window.console) {
console.error('Reference element was lost')
}
this.parent.insertBefore(this.elem, this.nextSibling) // Don't use `before` or `prepend` as `this.nextSibling` may be `null`
@@ -581,7 +581,7 @@ export class UndoManager {
const oldValues = new Array(i); const elements = new Array(i)
while (i--) {
const elem = elems[i]
if (isNullish(elem)) { continue }
if (!elem) { continue }
elements[i] = elem
oldValues[i] = elem.getAttribute(attrName)
}
@@ -606,7 +606,7 @@ export class UndoManager {
let i = changeset.elements.length
while (i--) {
const elem = changeset.elements[i]
if (isNullish(elem)) { continue }
if (!elem) { continue }
const changes = {}
changes[attrName] = changeset.oldValues[i]
if (changes[attrName] !== elem.getAttribute(attrName)) {

View File

@@ -7,7 +7,7 @@
*/
import { NS } from './namespaces.js'
import { toXml, walkTree, isNullish } from './utilities.js'
import { toXml, walkTree } from './utilities.js'
/**
* This class encapsulates the concept of a layer in the drawing. It can be constructed with
@@ -114,7 +114,7 @@ class Layer {
*/
getOpacity () {
const opacity = this.group_.getAttribute('opacity')
if (isNullish(opacity)) {
if (!opacity) {
return 1
}
return Number.parseFloat(opacity)
@@ -218,7 +218,7 @@ Layer.CLASS_REGEX = new RegExp('(\\s|^)' + Layer.CLASS_NAME + '(\\s|$)')
*/
function addLayerClass (elem) {
const classes = elem.getAttribute('class')
if (isNullish(classes) || !classes.length) {
if (!classes || !classes.length) {
elem.setAttribute('class', Layer.CLASS_NAME)
} else if (!Layer.CLASS_REGEX.test(classes)) {
elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME)

View File

@@ -14,7 +14,7 @@ import {
transformListToTransform
} from './math.js'
import {
assignAttributes, getElement, getRotationAngle, snapToGrid, isNullish,
assignAttributes, getElement, getRotationAngle, snapToGrid,
getBBox
} from './utilities.js'
@@ -541,7 +541,7 @@ export const pathActionsMethod = (function () {
// Start selection box
if (!path.dragging) {
let rubberBox = svgCanvas.getRubberBox()
if (isNullish(rubberBox)) {
if (!rubberBox) {
rubberBox = svgCanvas.setRubberBox(
svgCanvas.selectorManager.getRubberBandBox()
)
@@ -875,7 +875,7 @@ export const pathActionsMethod = (function () {
* @returns {false|void}
*/
resetOrientation (pth) {
if (isNullish(pth) || pth.nodeName !== 'path') { return false }
if (pth?.nodeName !== 'path') { return false }
const tlist = pth.transform.baseVal
const m = transformListToTransform(tlist).matrix
tlist.clear()
@@ -1007,7 +1007,7 @@ export const pathActionsMethod = (function () {
return true
})
if (isNullish(openPt)) {
if (!openPt) {
// Single path, so close last seg
openPt = path.segs.length - 1
}

View File

@@ -12,7 +12,7 @@ import {
transformPoint, getMatrix
} from './math.js'
import {
assignAttributes, getRotationAngle, isNullish,
assignAttributes, getRotationAngle,
getElement
} from './utilities.js'
@@ -635,7 +635,7 @@ export class Path {
seg.next.prev = seg
seg.mate = segs[startI]
seg.addGrip()
if (isNullish(this.first_seg)) {
if (!this.first_seg) {
this.first_seg = seg
}
} else if (!nextSeg) {
@@ -907,7 +907,7 @@ export class Path {
*/
selectPt (pt, ctrlNum) {
this.clearSelection()
if (isNullish(pt)) {
if (!pt) {
this.eachSeg(function (i) {
// 'this' is the segment here.
if (this.prev) {

View File

@@ -10,7 +10,7 @@ import { shortFloat } from '../common/units.js'
import { transformPoint } from './math.js'
import {
getRotationAngle, getBBox,
getRefElem, findDefs, isNullish,
getRefElem, findDefs,
getBBox as utilsGetBBox
} from './utilities.js'
import {
@@ -209,10 +209,6 @@ export let path = null
* @param {string} cm The mode
* @returns {string} The same mode as passed in
*/
/**
* @function module:path.EditorContext#getDrawnPath
* @returns {SVGPathElement|null}
*/
/**
* @function module:path.EditorContext#setDrawnPath
* @param {SVGPathElement|null} dp
@@ -501,7 +497,7 @@ export const recalcRotatedPath = () => {
const rvals = getRotVals(seg.x, seg.y)
const points = [rvals.x, rvals.y]
if (!isNullish(seg.x1) && !isNullish(seg.x2)) {
if (seg.x1 && seg.x2) {
const cVals1 = getRotVals(seg.x1, seg.y1)
const cVals2 = getRotVals(seg.x2, seg.y2)
points.splice(points.length, 0, cVals1.x, cVals1.y, cVals2.x, cVals2.y)

View File

@@ -6,7 +6,7 @@
import { NS } from './namespaces.js'
import { convertToNum } from '../common/units.js'
import { getRotationAngle, getHref, getBBox, getRefElem, isNullish } from './utilities.js'
import { getRotationAngle, getHref, getBBox, getRefElem } from './utilities.js'
import { BatchCommand, ChangeElementCommand } from './history.js'
import { remapElement } from './coords.js'
import {
@@ -231,7 +231,7 @@ export const recalculateDimensions = function (selected) {
// if we haven't created an initial array in polygon/polyline/path, then
// make a copy of initial values and include the transform
if (isNullish(initial)) {
if (!initial) {
initial = mergeDeep({}, changes)
for (const [attr, val] of Object.entries(initial)) {
initial[attr] = convertToNum(attr, val)

View File

@@ -7,7 +7,7 @@
*/
import { isTouch, isWebkit } from '../common/browser.js' // , isOpera
import { getRotationAngle, getBBox, getStrokedBBox, isNullish } from './utilities.js'
import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js'
import { transformListToTransform, transformBox, transformPoint } from './math.js'
let svgCanvas
@@ -439,7 +439,7 @@ export class SelectorManager {
* @returns {void}
*/
releaseSelector (elem) {
if (isNullish(elem)) { return }
if (!elem) { return }
const N = this.selectors.length
const sel = this.selectorMap[elem.id]
if (sel && !sel.locked) {