Skip to content

Commit 6ededf3

Browse files
refactor: fix lint
1 parent 7757083 commit 6ededf3

8 files changed

Lines changed: 43 additions & 41 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
strategy:
6868
matrix:
6969
os: [ubuntu-latest, windows-latest, macos-latest]
70-
node-version: [18.x, 20.x, 22.x, 24.x]
70+
node-version: [20.x, 22.x, 24.x, 25.x]
7171
webpack-version: [latest]
7272

7373
runs-on: ${{ matrix.os }}

src/index.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const {
2929
/** @typedef {import("postcss").Stringifier} Stringifier */
3030
/** @typedef {import("@jridgewell/trace-mapping").TraceMap} TraceMap */
3131

32+
// eslint-disable-next-line jsdoc/reject-any-type
33+
/** @typedef {any} EXPECTED_ANY */
34+
3235
/**
3336
* @typedef {Record<string, unknown>} CssNanoOptions
3437
* @property {string=} configFile Configuration file path
@@ -58,8 +61,8 @@ const {
5861
* @typedef {object} MinimizedResult
5962
* @property {string} code Minimized code
6063
* @property {RawSourceMap=} map Source map
61-
* @property {Array<Error | ErrorObject| string>=} errors Errors
62-
* @property {Array<Warning | WarningObject | string>=} warnings Warnings
64+
* @property {(Error | ErrorObject | string)[]=} errors Errors
65+
* @property {(Warning | WarningObject | string)[]=} warnings Warnings
6366
*/
6467

6568
/**
@@ -77,7 +80,7 @@ const {
7780

7881
/**
7982
* @template T
80-
* @typedef {T extends any[] ? { [P in keyof T]?: InferDefaultType<T[P]> } : InferDefaultType<T>} MinimizerOptions
83+
* @typedef {T extends EXPECTED_ANY[] ? { [P in keyof T]?: InferDefaultType<T[P]> } : InferDefaultType<T>} MinimizerOptions
8184
*/
8285

8386
/**
@@ -96,7 +99,7 @@ const {
9699

97100
/**
98101
* @template T
99-
* @typedef {T extends any[] ? { [P in keyof T]: BasicMinimizerImplementation<T[P]> & MinimizeFunctionHelpers; } : BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
102+
* @typedef {T extends EXPECTED_ANY[] ? { [P in keyof T]: BasicMinimizerImplementation<T[P]> & MinimizeFunctionHelpers } : BasicMinimizerImplementation<T> & MinimizeFunctionHelpers} MinimizerImplementation
100103
*/
101104

102105
/**
@@ -110,9 +113,9 @@ const {
110113

111114
/**
112115
* @typedef InternalResult
113-
* @property {Array<{ code: string, map: RawSourceMap | undefined }>} outputs - Outputs
114-
* @property {Array<Warning | WarningObject | string>} warnings - Warnings
115-
* @property {Array<Error | ErrorObject | string>} errors - Errors
116+
* @property {{ code: string, map: RawSourceMap | undefined }[]} outputs - Outputs
117+
* @property {(Warning | WarningObject | string)[]} warnings - Warnings
118+
* @property {(Error | ErrorObject | string)[]} errors - Errors
116119
*/
117120

118121
/** @typedef {undefined | boolean | number} Parallel */
@@ -137,7 +140,7 @@ const {
137140
*/
138141

139142
/**
140-
* @typedef {ProcessOptions | { from?: string, to?: string, parser?: string | Syntax | Parser, stringifier?: string | Syntax | Stringifier, syntax?: string | Syntax } } ProcessOptionsExtender
143+
* @typedef {ProcessOptions | { from?: string, to?: string, parser?: string | Syntax | Parser, stringifier?: string | Syntax | Stringifier, syntax?: string | Syntax }} ProcessOptionsExtender
141144
*/
142145

143146
/**
@@ -209,13 +212,13 @@ class CssMinimizerPlugin {
209212
// https://github.com/mozilla/source-map#new-sourcemapconsumerrawsourcemap
210213
return Boolean(
211214
input &&
212-
typeof input === "object" &&
213-
input !== null &&
214-
"version" in input &&
215-
"sources" in input &&
216-
Array.isArray(input.sources) &&
217-
"mappings" in input &&
218-
typeof input.mappings === "string",
215+
typeof input === "object" &&
216+
input !== null &&
217+
"version" in input &&
218+
"sources" in input &&
219+
Array.isArray(input.sources) &&
220+
"mappings" in input &&
221+
typeof input.mappings === "string",
219222
);
220223
}
221224

@@ -391,10 +394,8 @@ class CssMinimizerPlugin {
391394
// https://github.com/nodejs/node/issues/19022
392395

393396
const cpus =
394-
// eslint-disable-next-line n/no-unsupported-features/node-builtins
395397
typeof os.availableParallelism === "function"
396-
? // eslint-disable-next-line n/no-unsupported-features/node-builtins
397-
{ length: os.availableParallelism() }
398+
? { length: os.availableParallelism() }
398399
: os.cpus() || { length: 1 };
399400

400401
return parallel === true || typeof parallel === "undefined"
@@ -419,7 +420,7 @@ class CssMinimizerPlugin {
419420
* @param {Compiler} compiler Compiler
420421
* @param {Compilation} compilation Compilation
421422
* @param {Record<string, import("webpack").sources.Source>} assets Assets
422-
* @param {{availableNumberOfCores: number}} optimizeOptions Optimize options
423+
* @param {{ availableNumberOfCores: number }} optimizeOptions Optimize options
423424
* @returns {Promise<void>} Promise
424425
*/
425426
async optimize(compiler, compilation, assets, optimizeOptions) {

src/utils.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/** @typedef {import("./index.js").RawSourceMap} RawSourceMap */
33
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
44
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
5+
/** @typedef {import("./index.js").EXPECTED_ANY} EXPECTED_ANY */
56
/** @typedef {import("postcss").ProcessOptions} ProcessOptions */
67
/** @typedef {import("postcss").Postcss} Postcss */
78

@@ -88,7 +89,7 @@ async function cssnanoMinify(
8889
}
8990

9091
if (
91-
/** @type {Error & {code: string}} */
92+
/** @type {Error & { code: string }} */
9293
(err).code === "ERR_REQUIRE_ESM" &&
9394
importESM
9495
) {
@@ -119,6 +120,7 @@ async function cssnanoMinify(
119120
`Loading PostCSS "${postcssOptions.parser}" parser failed: ${
120121
/** @type {Error} */ (error).message
121122
}\n\n(@${name})`,
123+
{ cause: error },
122124
);
123125
}
124126
}
@@ -131,6 +133,7 @@ async function cssnanoMinify(
131133
`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${
132134
/** @type {Error} */ (error).message
133135
}\n\n(@${name})`,
136+
{ cause: error },
134137
);
135138
}
136139
}
@@ -143,6 +146,7 @@ async function cssnanoMinify(
143146
`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${
144147
/** @type {Error} */ (error).message
145148
}\n\n(@${name})`,
149+
{ cause: error },
146150
);
147151
}
148152
}
@@ -224,8 +228,7 @@ async function cleanCssMinify(input, sourceMap, minimizerOptions) {
224228

225229
const generatedSourceMap = result.sourceMap
226230
? /** @type {RawSourceMap} */ (
227-
// eslint-disable-next-line jsdoc/no-restricted-syntax
228-
/** @type {any} */ (result.sourceMap).toJSON()
231+
/** @type {EXPECTED_ANY} */ (result.sourceMap).toJSON()
229232
)
230233
: undefined;
231234

@@ -349,10 +352,10 @@ esbuildMinify.supportsWorkerThreads = () => false;
349352
*/
350353
async function parcelCssMinify(input, sourceMap, minimizerOptions) {
351354
const [[filename, code]] = Object.entries(input);
352-
// eslint-disable-next-line jsdoc/no-restricted-syntax
355+
353356
/**
354-
* @param {Partial<import("@parcel/css").TransformOptions<any>>=} parcelCssOptions Parcel CSS options
355-
* @returns {import("@parcel/css").TransformOptions<any>} Built Parcel CSS options
357+
* @param {Partial<import("@parcel/css").TransformOptions<EXPECTED_ANY>>=} parcelCssOptions Parcel CSS options
358+
* @returns {import("@parcel/css").TransformOptions<EXPECTED_ANY>} Built Parcel CSS options
356359
*/
357360
const buildParcelCssOptions = (parcelCssOptions = {}) =>
358361
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
@@ -394,10 +397,10 @@ parcelCssMinify.supportsWorkerThreads = () => false;
394397
*/
395398
async function lightningCssMinify(input, sourceMap, minimizerOptions) {
396399
const [[filename, code]] = Object.entries(input);
397-
// eslint-disable-next-line jsdoc/no-restricted-syntax
400+
398401
/**
399-
* @param {Partial<import("lightningcss").TransformOptions<any>>=} lightningCssOptions Lightning CSS options
400-
* @returns {import("lightningcss").TransformOptions<any>} Built Lightning CSS options
402+
* @param {Partial<import("lightningcss").TransformOptions<EXPECTED_ANY>>=} lightningCssOptions Lightning CSS options
403+
* @returns {import("lightningcss").TransformOptions<EXPECTED_ANY>} Built Lightning CSS options
401404
*/
402405
const buildLightningCssOptions = (lightningCssOptions = {}) =>
403406
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
@@ -470,11 +473,10 @@ async function swcMinify(input, sourceMap, minimizerOptions) {
470473
? result.errors.map((diagnostic) => {
471474
const error = new Error(diagnostic.message);
472475

473-
// eslint-disable-next-line jsdoc/no-restricted-syntax
474-
/** @type {any} */ (error).span = diagnostic.span;
475-
476-
// eslint-disable-next-line jsdoc/no-restricted-syntax
477-
/** @type {any} */ (error).level = diagnostic.level;
476+
/** @type {EXPECTED_ANY} */
477+
(error).span = diagnostic.span;
478+
/** @type {EXPECTED_ANY} */
479+
(error).level = diagnostic.level;
478480

479481
return error;
480482
})

test/helpers/getErrors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import normalizeErrors from "./normalizeErrors";
22

3-
export default (stats) => normalizeErrors(stats.compilation.errors).sort();
3+
export default (stats) => normalizeErrors(stats.compilation.errors).toSorted();

test/helpers/getWarnings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import normalizeErrors from "./normalizeErrors";
22

3-
export default (stats) => normalizeErrors(stats.compilation.warnings).sort();
3+
export default (stats) =>
4+
normalizeErrors(stats.compilation.warnings).toSorted();

test/helpers/normalizeErrors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function removeCWD(str) {
1616
}
1717

1818
/**
19-
* @param {Array<Error>} errors Array of errors
20-
* @returns {Array<string>} Normalized error messages
19+
* @param {Error[]} errors Array of errors
20+
* @returns {string[]} Normalized error messages
2121
*/
2222
export default (errors) =>
2323
errors.map((error) =>

test/minimizerOptions-option.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ describe('when applied with "minimizerOptions" option', () => {
102102
});
103103
new CssMinimizerPlugin({
104104
minimizerOptions: {
105-
// eslint-disable-next-line n/no-extraneous-require
106105
preset: require.resolve("cssnano-preset-default"),
107106
},
108107
}).apply(compiler);
@@ -119,7 +118,6 @@ describe('when applied with "minimizerOptions" option', () => {
119118
});
120119
new CssMinimizerPlugin({
121120
minimizerOptions: {
122-
// eslint-disable-next-line n/no-extraneous-require
123121
preset: require.resolve("cssnano-preset-default"),
124122
},
125123
}).apply(compiler2);

test/parallel-option.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("parallel option", () => {
9797

9898
const stats = await compile(compiler);
9999

100-
expect(Worker).toHaveBeenCalledTimes(0);
100+
expect(Worker).not.toHaveBeenCalled();
101101

102102
expect(readAssets(compiler, stats, /\.css$/)).toMatchSnapshot("assets");
103103
expect(getErrors(stats)).toMatchSnapshot("errors");

0 commit comments

Comments
 (0)