Skip to content

Commit d53a32d

Browse files
refactor: fix lint and type errors
1 parent 4316c2a commit d53a32d

16 files changed

Lines changed: 82 additions & 37 deletions

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default defineConfig([
3939
...globals.node,
4040
},
4141
parserOptions: {
42-
project: ['tsconfig.json', 'tsconfig.test.json'],
42+
project: ['tsconfig.build.json', 'tsconfig.test.json'],
4343
tsconfigRootDir: import.meta.dirname,
4444
},
4545
},

karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/**
22
* @see https://karma-runner.github.io/6.4/config/configuration-file.html
3+
*
4+
* @param {{LOG_INFO: string; set: () => void}} config
35
*/
46
module.exports = (config) => {
57
config.set({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"scripts": {
3636
"build": "run-s build:*",
37-
"build:cjs": "tsc",
37+
"build:cjs": "tsc --project tsconfig.build.json",
3838
"build:esm": "rollup --config --failAfterWarnings --environment ESM:true && scripts/fix-esm.sh",
3939
"build:umd": "rollup --config --failAfterWarnings --environment UMD:true",
4040
"clean": "rm -rf .nyc_output coverage dist esm lib",

rollup.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import typescript from '@rollup/plugin-typescript';
88

99
const require = createRequire(import.meta.url);
1010

11-
const getPlugins = ({ browser = false, minify = false, outDir }) =>
11+
const getPlugins = ({ browser = false, minify = false, outDir = '' }) =>
1212
[
1313
browser &&
1414
alias({
@@ -20,6 +20,7 @@ const getPlugins = ({ browser = false, minify = false, outDir }) =>
2020
],
2121
}),
2222
typescript({
23+
tsconfig: 'tsconfig.build.json',
2324
compilerOptions: {
2425
module: 'esnext',
2526
outDir,

src/client/utilities.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,20 @@ export function formatDOM(
121121
}
122122

123123
case 3:
124-
current = new Text(revertEscapedCharacters(node.nodeValue!));
124+
current = new Text(revertEscapedCharacters(node.nodeValue ?? ''));
125125
break;
126126

127127
case 8:
128-
current = new Comment(node.nodeValue!);
128+
current = new Comment(node.nodeValue ?? '');
129129
break;
130130

131131
default:
132132
continue;
133133
}
134134

135135
// set previous node next
136-
const prev = domNodes[index - 1] || null;
136+
const prev = domNodes[index - 1] ?? null;
137+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
137138
if (prev) {
138139
prev.next = current;
139140
}
@@ -152,7 +153,7 @@ export function formatDOM(
152153
directive,
153154
);
154155

155-
current.next = domNodes[0] || null;
156+
current.next = domNodes[0] ?? null;
156157
current.parent = parent as Element;
157158
domNodes.unshift(current);
158159

test/cases/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require('node:fs');
2+
const path = require('node:path');
3+
4+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
35
const { minify } = require('html-minifier');
6+
47
const htmlCases = require('./html');
58

69
/**
@@ -17,6 +20,7 @@ const html = [
1720
...htmlCases,
1821
{
1922
name: 'complex html',
23+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
2024
data: minify(read('./complex.html'), {
2125
collapseWhitespace: true,
2226
}),

test/client/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
const htmlCases = require('../cases/html');
24
const serverParser = require('../../dist/htmlparser2').parseDOM;
35
const clientParser = require('../../dist/html-dom-parser');

test/helpers/cycle.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
/**
24
* @see {@link https://github.com/douglascrockford/JSON-js/blob/master/cycle.js}
35
*/
@@ -142,7 +144,7 @@ if (typeof JSON.retrocycle !== 'function') {
142144
// produces an array containing a single element which is the array itself.
143145

144146
var px =
145-
/^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\(?:[\\"/bfnrt]|u[0-9a-zA-Z]{4}))*")\])*$/; // eslint-disable-line no-control-regex
147+
/^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\(?:[\\"/bfnrt]|u[0-9a-zA-Z]{4}))*")\])*$/;
146148

147149
(function rez(value) {
148150
// The rez function walks recursively through the object looking for $ref

test/helpers/run-tests.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const isKarma =
66
/**
77
* Runs tests.
88
*
9-
* @param {Function} assert - Assert.
10-
* @param {Object} testCases - Test cases.
11-
* @param {Function} actualParser - Actual parser.
12-
* @param {Function} expectedParser - Expected parser.
9+
* @param {{deepEqual: () => void}} assert
10+
* @param {Record<string, string>[]} testCases
11+
* @param {() => object} actualParser
12+
* @param {() => object} expectedParser
1313
*/
1414
module.exports = function runTests(
1515
assert,
@@ -27,7 +27,9 @@ module.exports = function runTests(
2727
// use `JSON.decycle` since `assert.deepEqual` fails
2828
// when instance types are different in the browser
2929
if (isKarma) {
30+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
3031
actualOutput = JSON.decycle(actualOutput);
32+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
3133
expectedOutput = JSON.decycle(expectedOutput);
3234
}
3335

test/helpers/test-case-sensitive-tags.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const constants = require('../../lib/client/constants');
33
/**
44
* Tests case-sensitive tags (SVG) to make sure their case is preserved.
55
*
6-
* @param {Function} parser - The parser.
6+
* @param {{equal: () => void}} assert
7+
* @param {() => object[]} parser
78
*/
89
module.exports = function testCaseSensitiveTags(assert, parser) {
910
it('preserves case of case-sensitive SVG tags', () => {

0 commit comments

Comments
 (0)