refactor: eliminate eslint errors (#920)
* refactor: eliminate eslint errors as many as I can * refactor: fix more eslint errors in the record module * LINT: fix @typescript-eslint/unbound-method * LINT: fix all eslint errors in source code * LINT: fix as many eslint warnings as possible Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
* 1. The css library was built for node.js which does not have tree-shaking supports.
|
||||
* 2. Rewrites into typescript give us a better type interface.
|
||||
*/
|
||||
|
||||
/* tslint:disable no-conditional-assignment interface-name no-shadowed-variable */
|
||||
/* eslint-disable tsdoc/syntax */
|
||||
|
||||
export interface ParserOptions {
|
||||
/** Silently fail on parse errors */
|
||||
@@ -288,7 +287,7 @@ export function parse(css: string, options: ParserOptions = {}) {
|
||||
|
||||
function error(msg: string) {
|
||||
const err = new Error(
|
||||
options.source + ':' + lineno + ':' + column + ': ' + msg,
|
||||
`${options.source || ''}:${lineno}:${column}: ${msg}`,
|
||||
) as ParserError;
|
||||
err.reason = msg;
|
||||
err.filename = options.source;
|
||||
@@ -457,6 +456,7 @@ export function parse(css: string, options: ParserOptions = {}) {
|
||||
const pos = position();
|
||||
|
||||
// prop
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
const propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
|
||||
if (!propMatch) {
|
||||
return;
|
||||
@@ -469,6 +469,7 @@ export function parse(css: string, options: ParserOptions = {}) {
|
||||
}
|
||||
|
||||
// val
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
|
||||
|
||||
const ret = pos({
|
||||
@@ -889,6 +890,7 @@ function addParent(obj: Stylesheet, parent?: Stylesheet) {
|
||||
const value = obj[k as keyof Stylesheet];
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((v) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
addParent(v, childParent);
|
||||
});
|
||||
} else if (value && typeof value === 'object') {
|
||||
|
||||
@@ -134,7 +134,7 @@ function buildNode(
|
||||
n.publicId,
|
||||
n.systemId,
|
||||
);
|
||||
case NodeType.Element:
|
||||
case NodeType.Element: {
|
||||
const tagName = getTagName(n);
|
||||
let node: Element;
|
||||
if (n.isSVG) {
|
||||
@@ -143,7 +143,7 @@ function buildNode(
|
||||
node = doc.createElement(tagName);
|
||||
}
|
||||
for (const name in n.attributes) {
|
||||
if (!n.attributes.hasOwnProperty(name)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(n.attributes, name)) {
|
||||
continue;
|
||||
}
|
||||
let value = n.attributes[name];
|
||||
@@ -290,6 +290,7 @@ function buildNode(
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
case NodeType.Text:
|
||||
return doc.createTextNode(
|
||||
n.isStyle && hackCss
|
||||
@@ -417,7 +418,12 @@ function handleScroll(node: Node, mirror: Mirror) {
|
||||
}
|
||||
const el = node as HTMLElement;
|
||||
for (const name in n.attributes) {
|
||||
if (!(n.attributes.hasOwnProperty(name) && name.startsWith('rr_'))) {
|
||||
if (
|
||||
!(
|
||||
Object.prototype.hasOwnProperty.call(n.attributes, name) &&
|
||||
name.startsWith('rr_')
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const value = n.attributes[name];
|
||||
|
||||
@@ -102,7 +102,14 @@ export function absoluteToStylesheet(
|
||||
): string {
|
||||
return (cssText || '').replace(
|
||||
URL_IN_CSS_REF,
|
||||
(origin, quote1, path1, quote2, path2, path3) => {
|
||||
(
|
||||
origin: string,
|
||||
quote1: string,
|
||||
path1: string,
|
||||
quote2: string,
|
||||
path2: string,
|
||||
path3: string,
|
||||
) => {
|
||||
const filePath = path1 || path2 || path3;
|
||||
const maybeQuote = quote1 || quote2 || '';
|
||||
if (!filePath) {
|
||||
@@ -136,7 +143,9 @@ export function absoluteToStylesheet(
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/; // Don't use \s, to avoid matching non-breaking space
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
|
||||
function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
||||
/*
|
||||
@@ -165,6 +174,7 @@ function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
||||
}
|
||||
|
||||
const output = [];
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
collectCharacters(SRCSET_COMMAS_OR_SPACES);
|
||||
if (pos >= attributeValue.length) {
|
||||
@@ -182,6 +192,7 @@ function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
||||
let descriptorsStr = '';
|
||||
url = absoluteToDoc(doc, url);
|
||||
let inParens = false;
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const c = attributeValue.charAt(pos);
|
||||
if (c === '') {
|
||||
@@ -554,7 +565,7 @@ function serializeTextNode(
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
`Cannot get CSS styles from text's parentNode. Error: ${err}`,
|
||||
`Cannot get CSS styles from text's parentNode. Error: ${err as string}`,
|
||||
n,
|
||||
);
|
||||
}
|
||||
@@ -740,7 +751,7 @@ function serializeElementNode(
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
`Cannot inline img src=${image.currentSrc}! Error: ${err}`,
|
||||
`Cannot inline img src=${image.currentSrc}! Error: ${err as string}`,
|
||||
);
|
||||
}
|
||||
oldValue
|
||||
|
||||
@@ -122,6 +122,7 @@ export function is2DCanvasBlank(canvas: HTMLCanvasElement): boolean {
|
||||
// get chunks of the canvas and check if it is blank
|
||||
for (let x = 0; x < canvas.width; x += chunkSize) {
|
||||
for (let y = 0; y < canvas.height; y += chunkSize) {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
const getImageData = ctx.getImageData as PatchedGetImageData;
|
||||
const originalGetImageData =
|
||||
ORIGINAL_ATTRIBUTE_NAME in getImageData
|
||||
@@ -132,6 +133,7 @@ export function is2DCanvasBlank(canvas: HTMLCanvasElement): boolean {
|
||||
// even if we can already tell from the first chunk(s) that
|
||||
// the canvas isn't blank
|
||||
const pixelBuffer = new Uint32Array(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
||||
originalGetImageData.call(
|
||||
ctx,
|
||||
x,
|
||||
|
||||
Reference in New Issue
Block a user