Fix lint issues.

This commit is contained in:
Paulo Gustavo Veiga 2021-10-05 19:08:42 -07:00
parent 181ca7b34e
commit c89d40758a
17 changed files with 153 additions and 151 deletions

View File

@ -7,5 +7,7 @@
"airbnb-base"
],
"plugins": ["only-warn"],
"rules": {}
"rules": {
"no-underscore-dangle": "off"
}
}

View File

@ -6,6 +6,12 @@
"extends": [
"airbnb-base"
],
"plugins": ["only-warn"],
"rules": {}
"plugins": [
"only-warn"
],
"rules": {
"no-underscore-dangle": "off",
"no-restricted-syntax": "off",
"max-len": [1,250]
}
}

View File

@ -30,7 +30,9 @@ const Arrow = new Class({
strokeOpacity: 1,
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},

View File

@ -26,7 +26,9 @@ const CurvedLine = new Class({
strokeColor: 'blue', strokeWidth: 1, strokeStyle: 'solid', strokeOpacity: 1,
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},
@ -36,15 +38,15 @@ const CurvedLine = new Class({
},
setFrom(x, y) {
$assert(!isNaN(x), 'x must be defined');
$assert(!isNaN(y), 'y must be defined');
$assert(!Number.isNaN(x), 'x must be defined');
$assert(!Number.isNaN(y), 'y must be defined');
this.peer.setFrom(x, y);
},
setTo(x, y) {
$assert(!isNaN(x), 'x must be defined');
$assert(!isNaN(y), 'y must be defined');
$assert(!Number.isNaN(x), 'x must be defined');
$assert(!Number.isNaN(y), 'y must be defined');
this.peer.setTo(x, y);
},

View File

@ -23,7 +23,7 @@ const Element = new Class({ // eslint-disable-line no-undef
throw new Error('Element peer can not be null');
}
if ($defined(attributes)) { // eslint-disable-line no-undef
if ($defined(attributes)) {
this._initialize(attributes);
}
},
@ -32,30 +32,39 @@ const Element = new Class({ // eslint-disable-line no-undef
const batchExecute = {};
// Collect arguments ...
for (var key in attributes) {
const funcName = this._attributeNameToFuncName(key, 'set');
let funcArgs = batchExecute[funcName];
if (!$defined(funcArgs)) { // eslint-disable-line no-undef
funcArgs = [];
}
for (const key in attributes) {
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
const funcName = this._attributeNameToFuncName(key, 'set');
let funcArgs = batchExecute[funcName];
if (!$defined(funcArgs)) {
funcArgs = [];
}
const signature = Element._propertyNameToSignature[key];
const argPositions = signature[1];
if (argPositions !== Element._SIGNATURE_MULTIPLE_ARGUMENTS) {
funcArgs[argPositions] = attributes[key];
} else {
funcArgs = attributes[key].split(' ');
}
batchExecute[funcName] = funcArgs;
const signature = Element._propertyNameToSignature[key];
const argPositions = signature[1];
if (argPositions != Element._SIGNATURE_MULTIPLE_ARGUMENTS) {
funcArgs[argPositions] = attributes[key];
} else {
funcArgs = attributes[key].split(' ');
}
batchExecute[funcName] = funcArgs;
}
// Call functions ...
for (var key in batchExecute) { // eslint-disable-line no-redeclare
const func = this[key];
if (!$defined(func)) { // eslint-disable-line no-undef
throw new Error(`Could not find function: ${key}`);
for (const key in batchExecute) {
if (Object.prototype.hasOwnProperty.call(batchExecute, key)) {
const func = this[key];
if (!$defined(func)) {
throw new Error(`Could not find function: ${key}`);
}
func.apply(this, batchExecute[key]);
}
func.apply(this, batchExecute[key]);
}
},
@ -72,7 +81,8 @@ const Element = new Class({ // eslint-disable-line no-undef
* type
* A string representing the event type to listen for.
* listener
* The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a function in JavaScript.
* The object that receives a notification when an event of the specified type occurs. This must be an object
* implementing the EventListener interface, or simply a function in JavaScript.
*
* The following events types are supported:
*
@ -146,13 +156,13 @@ const Element = new Class({ // eslint-disable-line no-undef
*/
setStroke(width, style, color, opacity) {
if (
style != null
&& style != undefined
&& style != 'dash'
&& style != 'dot'
&& style != 'solid'
&& style != 'longdash'
&& style != 'dashdot'
style !== null
&& style !== undefined
&& style !== 'dash'
&& style !== 'dot'
&& style !== 'solid'
&& style !== 'longdash'
&& style !== 'dashdot'
) {
throw new Error(`Unsupported stroke style: '${style}'`);
}
@ -161,8 +171,8 @@ const Element = new Class({ // eslint-disable-line no-undef
_attributeNameToFuncName(attributeKey, prefix) {
const signature = Element._propertyNameToSignature[attributeKey];
if (!$defined(signature)) { // eslint-disable-line no-undef
throw `Unsupported attribute: ${attributeKey}`;
if (!$defined(signature)) {
throw new Error(`Unsupported attribute: ${attributeKey}`);
}
const firstLetter = signature[0].charAt(0);
@ -175,11 +185,12 @@ const Element = new Class({ // eslint-disable-line no-undef
* fill, fillColor, fillOpacity, coordSize, coordSizeWidth, coordSizeHeight, coordOrigin, coordOriginX, coordOrigiY
*/
setAttribute(key, value) {
const funcName = this._attributeNameToFuncName(key, 'set');
const signature = Element._propertyNameToSignature[key];
if (signature == null) {
throw `Could not find the signature for:${key}`;
throw new Error(`Could not find the signature for:${key}`);
}
// Parse arguments ..
@ -187,7 +198,7 @@ const Element = new Class({ // eslint-disable-line no-undef
let args = [];
if (argPositions !== this._SIGNATURE_MULTIPLE_ARGUMENTS) {
args[argPositions] = value;
} else if (typeof value === 'array') { // eslint-disable-line valid-typeof
} else if (Array.isArray(value)) {
args = value;
} else {
const strValue = String(value);
@ -197,7 +208,7 @@ const Element = new Class({ // eslint-disable-line no-undef
// Look up method ...
const setter = this[funcName];
if (setter == null) {
throw `Could not find the function name:${funcName}`;
throw new Error(`Could not find the function name:${funcName}`);
}
setter.apply(this, args);
},
@ -207,23 +218,23 @@ const Element = new Class({ // eslint-disable-line no-undef
const signature = Element._propertyNameToSignature[key];
if (signature == null) {
throw `Could not find the signature for:${key}`;
throw new Error(`Could not find the signature for:${key}`);
}
const getter = this[funcName];
if (getter == null) {
throw `Could not find the function name:${funcName}`;
throw new Error(`Could not find the function name:${funcName}`);
}
const getterResult = getter.apply(this, []);
const attibuteName = signature[2];
if (!$defined(attibuteName)) { // eslint-disable-line no-undef
throw `Could not find attribute mapping for:${key}`;
if (!$defined(attibuteName)) {
throw new Error(`Could not find attribute mapping for:${key}`);
}
const result = getterResult[attibuteName];
if (!$defined(result)) { // eslint-disable-line no-undef
throw `Could not find attribute with name:${attibuteName}`;
if (!$defined(result)) {
throw new Error(`Could not find attribute with name:${attibuteName}`);
}
return result;

View File

@ -26,7 +26,9 @@ const Elipse = new Class({
width: 40, height: 40, x: 5, y: 5, stroke: '1 solid black', fillColor: 'blue',
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},

View File

@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const Toolkit = require('./Toolkit');
const TransformUtil = require('./peer/utils/TransformUtils').default;
const Font = new Class({

View File

@ -29,7 +29,9 @@ const Group = new Class({
width: 50, height: 50, x: 50, y: 50, coordOrigin: '0 0', coordSize: '50 50',
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},
@ -62,7 +64,7 @@ const Group = new Class({
throw Error('Child element can not be null');
}
if (element == this) {
if (element === this) {
throw new Error("It's not posible to add the group as a child of itself");
}
@ -71,7 +73,7 @@ const Group = new Class({
throw new Error(`It seems not to be an element ->${element}`);
}
if (elementType == 'Workspace') {
if (elementType === 'Workspace') {
throw new Error('A group can not have a workspace as a child');
}

View File

@ -24,7 +24,9 @@ const Line = new Class({
const peer = Toolkit.createLine();
const defaultAttributes = { strokeColor: '#495879', strokeWidth: 1, strokeOpacity: 1 };
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},

View File

@ -26,7 +26,9 @@ const PolyLine = new Class({
strokeColor: 'blue', strokeWidth: 1, strokeStyle: 'solid', strokeOpacity: 1,
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},

View File

@ -28,19 +28,17 @@ const Rect = new Class({
Extends: Element,
initialize(arc, attributes) {
if (arc && arc > 1) {
throw 'Arc must be 0<=arc<=1';
throw new Error('Arc must be 0<=arc<=1');
}
if (arguments.length <= 0) {
const rx = 0;
const ry = 0;
}
const peer = Toolkit.createRect(arc);
const defaultAttributes = {
width: 40, height: 40, x: 5, y: 5, stroke: '1 solid black', fillColor: 'green',
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
},

View File

@ -87,7 +87,7 @@ const Text = new Class({
},
getHeight() {
return parseInt(this.peer.getHeight());
return parseInt(this.peer.getHeight(), 10);
},
getFontHeight() {

View File

@ -33,7 +33,9 @@ const Workspace = new Class({
coordSize: '200 200',
};
for (const key in attributes) {
defaultAttributes[key] = attributes[key];
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
defaultAttributes[key] = attributes[key];
}
}
this.parent(peer, defaultAttributes);
this._htmlContainer.append(this.peer._native);
@ -48,15 +50,15 @@ const Workspace = new Class({
*/
append(element) {
if (!$defined(element)) {
throw 'Child element can not be null';
throw new Error('Child element can not be null');
}
const elementType = element.getType();
if (elementType == null) {
throw `It seems not to be an element ->${element}`;
throw new Error(`It seems not to be an element ->${element}`);
}
if (elementType == 'Workspace') {
throw 'A workspace can not have a workspace as a child';
if (elementType === 'Workspace') {
throw new Error('A workspace can not have a workspace as a child');
}
this.peer.append(element.peer);
@ -64,7 +66,7 @@ const Workspace = new Class({
addItAsChildTo(element) {
if (!$defined(element)) {
throw 'Workspace div container can not be null';
throw new Error('Workspace div container can not be null');
}
element.append(this._htmlContainer);
},
@ -157,13 +159,13 @@ const Workspace = new Class({
},
setStroke(width, style, color, opacity) {
if (style != 'solid') {
throw `Not supported style stroke style:${style}`;
if (style !== 'solid') {
throw new Error(`Not supported style stroke style:${style}`);
}
this._htmlContainer.css('border', `${width} ${style} ${color}`);
if (opacity || opacity === 0) {
throw 'Unsupported operation. Opacity not supported.';
throw new Error('Unsupported operation. Opacity not supported.');
}
},
@ -176,16 +178,16 @@ const Workspace = new Class({
*/
removeChild(element) {
if (!$defined(element)) {
throw 'Child element can not be null';
throw new Error('Child element can not be null');
}
if (element == this) {
throw "It's not possible to add the group as a child of itself";
if (element === this) {
throw new Error("It's not possible to add the group as a child of itself");
}
const elementType = element.getType();
if (elementType == null) {
throw `It seems not to be an element ->${element}`;
throw new Error(`It seems not to be an element ->${element}`);
}
this.peer.removeChild(element.peer);

View File

@ -1,23 +0,0 @@
/*
* Copyright [2015] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const web2d = {};
web2d.peer = {
svg: {},
};
web2d.peer.utils = {};

View File

@ -48,8 +48,8 @@ const CurvedLinePeer = new Class({
const change = this._control2.x != control.x || this._control2.y != control.y;
if ($defined(control.x)) {
this._control2 = control;
this._control2.x = parseInt(this._control2.x);
this._control2.y = parseInt(this._control2.y);
this._control2.x = parseInt(this._control2.x, 10);
this._control2.y = parseInt(this._control2.y, 10);
}
if (change) this._updatePath();
},
@ -75,16 +75,16 @@ const CurvedLinePeer = new Class({
},
setFrom(x1, y1) {
const change = this._x1 != parseInt(x1) || this._y1 != parseInt(y1);
this._x1 = parseInt(x1);
this._y1 = parseInt(y1);
const change = this._x1 != parseInt(x1, 10) || this._y1 != parseInt(y1, 10);
this._x1 = parseInt(x1, 10);
this._y1 = parseInt(y1, 10);
if (change) this._updatePath();
},
setTo(x2, y2) {
const change = this._x2 != parseInt(x2) || this._y2 != parseInt(y2);
this._x2 = parseInt(x2);
this._y2 = parseInt(y2);
const change = this._x2 !== parseInt(x2, 10) || this._y2 !== parseInt(y2, 10);
this._x2 = parseInt(x2, 10);
this._y2 = parseInt(y2, 10);
if (change) this._updatePath();
},
@ -149,14 +149,9 @@ const CurvedLinePeer = new Class({
if ($defined(this._x1) && $defined(this._y1) && $defined(this._x2) && $defined(this._y2)) {
this._calculateAutoControlPoints(avoidControlPointFix);
const path = `M${this._x1},${this._y1
} C${this._control1.x + this._x1},${this._control1.y + this._y1} ${
this._control2.x + this._x2},${this._control2.y + this._y2} ${
this._x2},${this._y2
}${this._lineStyle ? ` ${
this._control2.x + this._x2},${this._control2.y + this._y2 + 3} ${
this._control1.x + this._x1},${this._control1.y + this._y1 + 5} ${
this._x1},${this._y1 + 7} Z`
: ''}`;
} C${this._control1.x + this._x1},${this._control1.y + this._y1} ${this._control2.x + this._x2},${this._control2.y + this._y2} ${this._x2},${this._y2
}${this._lineStyle ? ` ${this._control2.x + this._x2},${this._control2.y + this._y2 + 3} ${this._control1.x + this._x1},${this._control1.y + this._y1 + 5} ${this._x1},${this._y1 + 7} Z`
: ''}`;
this._native.setAttribute('d', path);
}
},

View File

@ -27,8 +27,8 @@ const TransformUtil = {
const coordSize = current.getCoordSize();
const size = current.getSize();
width *= (parseInt(size.width) / coordSize.width);
height *= (parseInt(size.height) / coordSize.height);
width *= (parseInt(size.width,10) / coordSize.width);
height *= (parseInt(size.height,10) / coordSize.height);
current = current.getParent();
}
return { width, height };