🚨 Removed linter warnings
This commit is contained in:
parent
14d8f75929
commit
803e1c0552
138 changed files with 1591 additions and 1250 deletions
packages/plugin-validate/src
|
@ -1,72 +1,86 @@
|
|||
const validate = {};
|
||||
|
||||
validate.point = function (point, partId, pointId, debug) {
|
||||
if(typeof point !== 'object') {
|
||||
validate.point = function(point, partId, pointId, debug) {
|
||||
if (typeof point !== "object") {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with point',
|
||||
label: "Problem with point",
|
||||
msg: points
|
||||
});
|
||||
throw new Error(`Point pattern.parts.${partId}.points.${pointId} is not an object`);
|
||||
} else if(typeof point.x !== 'number' || isNaN(point.x)) {
|
||||
throw new Error(
|
||||
`Point pattern.parts.${partId}.points.${pointId} is not an object`
|
||||
);
|
||||
} else if (typeof point.x !== "number" || isNaN(point.x)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with point X-value',
|
||||
label: "Problem with point X-value",
|
||||
msg: points
|
||||
});
|
||||
throw new Error(`X-value of point pattern.parts.${partId}.points.${pointId} is not a number`);
|
||||
} else if(typeof point.y !== 'number' || isNaN(point.y)) {
|
||||
throw new Error(
|
||||
`X-value of point pattern.parts.${partId}.points.${pointId} is not a number`
|
||||
);
|
||||
} else if (typeof point.y !== "number" || isNaN(point.y)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with point Y-value',
|
||||
label: "Problem with point Y-value",
|
||||
msg: points
|
||||
});
|
||||
debug(dbg, 'Problem with point Y-value:', point);
|
||||
throw new Error(`Y-value of point pattern.parts.${partId}.points.${pointId} is not a number`);
|
||||
} else if(typeof point.attributes !== 'object' || !point.attributes.clone instanceof Function) {
|
||||
debug(dbg, "Problem with point Y-value:", point);
|
||||
throw new Error(
|
||||
`Y-value of point pattern.parts.${partId}.points.${pointId} is not a number`
|
||||
);
|
||||
} else if (
|
||||
typeof point.attributes !== "object" ||
|
||||
!(point.attributes.clone instanceof Function)
|
||||
) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with point attributes',
|
||||
label: "Problem with point attributes",
|
||||
msg: points
|
||||
});
|
||||
throw new Error (dbg, `attributes property of point pattern.parts.${partId}.points.${pointId} is not an object`);
|
||||
} else if(!point.clone instanceof Function) {
|
||||
throw new Error(
|
||||
`attributes property of point pattern.parts.${partId}.points.${pointId} is not an object`
|
||||
);
|
||||
} else if (!(point.clone instanceof Function)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with point',
|
||||
label: "Problem with point",
|
||||
msg: points
|
||||
});
|
||||
throw new Error(`Point pattern.parts.${partId}.points.${pointId} is not a valid Point object`);
|
||||
throw new Error(
|
||||
`Point pattern.parts.${partId}.points.${pointId} is not a valid Point object`
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
validate.text = function (type, item, partId, itemId, debug) {
|
||||
let text = item.attributes.getAsArray('data-text');
|
||||
if(text === false) return true;
|
||||
validate.text = function(type, item, partId, itemId, debug) {
|
||||
let text = item.attributes.getAsArray("data-text");
|
||||
if (text === false) return true;
|
||||
else {
|
||||
if(item.attributes.get('data-validate-skip-text') !== false) {
|
||||
if (item.attributes.get("data-validate-skip-text") !== false) {
|
||||
debug({
|
||||
type: "warning",
|
||||
label: '🌐 Possible translation issue',
|
||||
label: "🌐 Possible translation issue",
|
||||
msg: `This text might be a translation problem:, ${item} However, the error was suppresed, so moving on.`
|
||||
});
|
||||
return true;
|
||||
}
|
||||
for (let t of text) {
|
||||
if(typeof t !== 'string' && typeof t !== 'number') {
|
||||
if (typeof t !== "string" && typeof t !== "number") {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'This text is not a string or number',
|
||||
label: "This text is not a string or number",
|
||||
msg: t
|
||||
});
|
||||
throw new Error(`${type} pattern.parts.${partId}.${type}s.${itemId} has text that is not a string nor a number. Set the 'data-validate-skip-text' attribute to true to suppress this error.`);
|
||||
|
||||
} else if(typeof t === 'string' && t.indexOf(' ') !== -1) {
|
||||
throw new Error(
|
||||
`${type} pattern.parts.${partId}.${type}s.${itemId} has text that is not a string nor a number. Set the 'data-validate-skip-text' attribute to true to suppress this error.`
|
||||
);
|
||||
} else if (typeof t === "string" && t.indexOf(" ") !== -1) {
|
||||
debug({
|
||||
type: "warning",
|
||||
label: '🌐 Possible translation issue',
|
||||
label: "🌐 Possible translation issue",
|
||||
msg: t
|
||||
});
|
||||
debug({
|
||||
|
@ -78,93 +92,111 @@ validate.text = function (type, item, partId, itemId, debug) {
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
validate.path = function(path, partId, pathId, debug) {
|
||||
if(typeof path !== 'object') {
|
||||
if (typeof path !== "object") {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path',
|
||||
label: "Problem with path",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`Path pattern.parts.${partId}.paths.${pathId} is not an object`);
|
||||
} else if(typeof path.ops !== 'object') {
|
||||
throw new Error(
|
||||
`Path pattern.parts.${partId}.paths.${pathId} is not an object`
|
||||
);
|
||||
} else if (typeof path.ops !== "object") {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path ops',
|
||||
label: "Problem with path ops",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`ops property of path pattern.parts.${partId}.paths.${pathId} is not an object`);
|
||||
} else if(path.ops.length < 2) {
|
||||
throw new Error(
|
||||
`ops property of path pattern.parts.${partId}.paths.${pathId} is not an object`
|
||||
);
|
||||
} else if (path.ops.length < 2) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path ops',
|
||||
label: "Problem with path ops",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`Path pattern.parts.${partId}.paths.${pathId} does not do anything`);
|
||||
} else if(typeof path.attributes !== 'object') {
|
||||
throw new Error(
|
||||
`Path pattern.parts.${partId}.paths.${pathId} does not do anything`
|
||||
);
|
||||
} else if (typeof path.attributes !== "object") {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path attributes',
|
||||
label: "Problem with path attributes",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`attributes property of path pattern.parts.${partId}.paths.${pathId} is not an object`);
|
||||
} else if(!path.clone instanceof Function) {
|
||||
throw new Error(
|
||||
`attributes property of path pattern.parts.${partId}.paths.${pathId} is not an object`
|
||||
);
|
||||
} else if (!(path.clone instanceof Function)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path',
|
||||
label: "Problem with path",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`Path pattern.parts.${partId}.paths.${pathId} is not a valid Path object`);
|
||||
} else if(!path.attributes.clone instanceof Function) {
|
||||
throw new Error(
|
||||
`Path pattern.parts.${partId}.paths.${pathId} is not a valid Path object`
|
||||
);
|
||||
} else if (!(path.attributes.clone instanceof Function)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path attributes',
|
||||
label: "Problem with path attributes",
|
||||
msg: path
|
||||
});
|
||||
throw new Error(`attributes property of path pattern.parts.${partId}.paths.${pathId} is not a valid Attributes object`);
|
||||
throw new Error(
|
||||
`attributes property of path pattern.parts.${partId}.paths.${pathId} is not a valid Attributes object`
|
||||
);
|
||||
}
|
||||
for (let o in path.ops) {
|
||||
let op = path.ops[o];
|
||||
if(op.type !== 'close') {
|
||||
if(!validate.point(op.to, partId, '_unknown_', debug)) {
|
||||
if (op.type !== "close") {
|
||||
if (!validate.point(op.to, partId, "_unknown_", debug)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path TO point',
|
||||
label: "Problem with path TO point",
|
||||
msg: op.to
|
||||
});
|
||||
throw new Error(`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].to is not a valid Point object`);
|
||||
throw new Error(
|
||||
`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].to is not a valid Point object`
|
||||
);
|
||||
}
|
||||
} else if (op.type === 'curve') {
|
||||
if(!validate.point(op.cp1, partId, '_unknown_', debug)) {
|
||||
} else if (op.type === "curve") {
|
||||
if (!validate.point(op.cp1, partId, "_unknown_", debug)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path CP1 point',
|
||||
label: "Problem with path CP1 point",
|
||||
msg: op.cp1
|
||||
});
|
||||
throw new Error(`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].cp1 is not a valid Point object`);
|
||||
} else if(!validate.point(op.cp2, partId, '_unknown_', debug)) {
|
||||
throw new Error(
|
||||
`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].cp1 is not a valid Point object`
|
||||
);
|
||||
} else if (!validate.point(op.cp2, partId, "_unknown_", debug)) {
|
||||
debug({
|
||||
type: "error",
|
||||
label: 'Problem with path CP2 point',
|
||||
label: "Problem with path CP2 point",
|
||||
msg: op.cp2
|
||||
});
|
||||
throw new Error(`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].cp2 is not a valid Point object`);
|
||||
throw new Error(
|
||||
`Point in pattern.parts.${partId}.paths.${pathId}.ops[o].cp2 is not a valid Point object`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
validate.snippet = function (snippet, partId, snippetId, debug) {
|
||||
if(typeof snippet !== 'object') return false;
|
||||
if(!validate.point(snippet.anchor, partId, '_unknown_', debug)) return false;
|
||||
if(typeof snippet.attributes !== 'object') return false;
|
||||
if(!snippet.clone instanceof Function) return false;
|
||||
if(!snippet.attributes.clone instanceof Function) return false;
|
||||
validate.snippet = function(snippet, partId, snippetId, debug) {
|
||||
if (typeof snippet !== "object") return false;
|
||||
if (!validate.point(snippet.anchor, partId, "_unknown_", debug)) return false;
|
||||
if (typeof snippet.attributes !== "object") return false;
|
||||
if (!(snippet.clone instanceof Function)) return false;
|
||||
if (!(snippet.attributes.clone instanceof Function)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
export default validate;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue