diff --git a/biome.json b/biome.json index 7457bd2..4f29eab 100644 --- a/biome.json +++ b/biome.json @@ -20,91 +20,10 @@ "linter": { "enabled": true, "rules": { - "recommended": false, - "complexity": { - "noBannedTypes": "error", - "noExtraBooleanCast": "error", - "noMultipleSpacesInRegularExpressionLiterals": "error", - "noUselessCatch": "error", - "noUselessConstructor": "error", - "noUselessLoneBlockStatements": "error", - "noUselessRename": "error", - "noUselessTernary": "error", - "noUselessTypeConstraint": "error", - "noUselessUndefinedInitialization": "error", - "noVoid": "error", - "noWith": "error", - "useLiteralKeys": "error", - "useRegexLiterals": "error" - }, - "correctness": { - "noConstAssign": "error", - "noConstantCondition": "error", - "noEmptyCharacterClassInRegex": "error", - "noEmptyPattern": "error", - "noGlobalObjectCalls": "error", - "noInvalidConstructorSuper": "error", - "noInvalidUseBeforeDeclaration": "error", - "noNewSymbol": "error", - "noPrecisionLoss": "error", - "noSelfAssign": "error", - "noSwitchDeclarations": "error", - "noUndeclaredVariables": "error", - "noUnreachable": "error", - "noUnreachableSuper": "error", - "noUnsafeFinally": "error", - "noUnusedVariables": "warn", - "useArrayLiterals": "error", - "useIsNan": "error" - }, - "security": { "noGlobalEval": "error" }, - "style": { - "noCommaOperator": "error", - "noInferrableTypes": "error", - "noNamespace": "error", - "noNonNullAssertion": "warn", - "noVar": "warn", - "noYodaExpression": "error", - "useAsConstAssertion": "error", - "useBlockStatements": "error", - "useConsistentBuiltinInstantiation": "error", - "useConst": "error", - "useSingleVarDeclarator": "error" - }, - "suspicious": { - "noAsyncPromiseExecutor": "error", - "noCatchAssign": "error", - "noClassAssign": "error", - "noCompareNegZero": "error", - "noConsole": "off", - "noControlCharactersInRegex": "error", - "noDebugger": "error", - "noDoubleEquals": "error", - "noDuplicateCase": "error", - "noDuplicateClassMembers": "error", - "noDuplicateObjectKeys": "error", - "noDuplicateParameters": "error", - "noEmptyBlockStatements": "error", - "noExplicitAny": "off", - "noExtraNonNullAssertion": "error", - "noFallthroughSwitchClause": "error", - "noFunctionAssign": "error", - "noGlobalAssign": "error", - "noImportAssign": "error", - "noMisleadingCharacterClass": "error", - "noMisleadingInstantiator": "error", - "noPrototypeBuiltins": "error", - "noRedeclare": "error", - "noSelfCompare": "error", - "noShadowRestrictedNames": "error", - "noSparseArray": "error", - "noUnsafeNegation": "error", - "useDefaultSwitchClauseLast": "error", - "useNamespaceKeyword": "error", - "useValidTypeof": "error" - } - }, - "ignore": [] + "recommended": true, + "complexity": { "noForEach": "off" }, + "suspicious": { "noExplicitAny": "off" } + } }, "javascript": { "formatter": { @@ -113,64 +32,10 @@ "trailingCommas": "none", "semicolons": "always", "arrowParentheses": "always", - "bracketSameLine": false, + "bracketSameLine": true, "quoteStyle": "single", "attributePosition": "auto", "bracketSpacing": true - }, - "globals": [ - "document", - "window", - "navigator", - "beforeEach", - "jest", - "expect", - "it", - "afterEach", - "describe" - ] - }, - "overrides": [ - { - "include": ["*.ts", "*.tsx", "*.mts", "*.cts"], - "linter": { - "rules": { - "correctness": { - "noConstAssign": "off", - "noGlobalObjectCalls": "off", - "noInvalidConstructorSuper": "off", - "noNewSymbol": "off", - "noSetterReturn": "off", - "noUndeclaredVariables": "off", - "noUnreachable": "off", - "noUnreachableSuper": "off" - }, - "style": { - "noArguments": "error", - "noVar": "error", - "useConst": "error" - }, - "suspicious": { - "noDuplicateClassMembers": "off", - "noDuplicateObjectKeys": "off", - "noDuplicateParameters": "off", - "noFunctionAssign": "off", - "noImportAssign": "off", - "noRedeclare": "off", - "noUnsafeNegation": "off", - "useGetterReturn": "off", - "useValidTypeof": "off" - } - } - } - }, - { - "include": ["*.md"], - "javascript": { - "formatter": { "semicolons": "always", "quoteStyle": "single" } - }, - "formatter": { "indentStyle": "space", "indentWidth": 2 } - }, - { "include": ["*.html"], "formatter": { "lineWidth": 320 } } - ] + } + } } diff --git a/example/svgo.config.js b/example/svgo.config.js index d2d2518..95fe753 100644 --- a/example/svgo.config.js +++ b/example/svgo.config.js @@ -1,4 +1,4 @@ -import crypto from 'crypto'; +import crypto from 'node:crypto'; export default { multipass: true, diff --git a/example/webpack.config.js b/example/webpack.config.js index 254684b..d05a607 100644 --- a/example/webpack.config.js +++ b/example/webpack.config.js @@ -1,5 +1,5 @@ -import path from 'path'; -import { fileURLToPath } from 'url'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; import TerserJSPlugin from 'terser-webpack-plugin'; import SvgChunkWebpackPlugin from '../lib/index.js'; diff --git a/src/index.ts b/src/index.ts index 654d032..5391f5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,13 @@ -import path from 'path'; +import path from 'node:path'; import extend from 'extend'; import { validate } from 'schema-utils'; -import { Schema } from 'schema-utils/declarations/validate.js'; +import type { Schema } from 'schema-utils/declarations/validate.js'; import svgstore from 'svgstore'; import webpack from 'webpack'; import type { Chunk, Compilation, Compiler, Module, NormalModule, sources } from 'webpack'; import templatePreview from './preview.js'; import unTypedSchemaOptions from './schemas/plugin-options.json' with { type: 'json' }; -import { +import type { EntryCache, PluginOptions, Sprite, @@ -237,7 +237,7 @@ class SvgChunkWebpackPlugin { ) ); for (const module of modules) { - if (module.buildInfo && module.buildInfo.SVG_CHUNK_WEBPACK_PLUGIN) { + if (module.buildInfo?.SVG_CHUNK_WEBPACK_PLUGIN) { listSvgsDependencies.push(module as NormalModule); // Mark module as not side effect free after processing in graph diff --git a/src/loader.ts b/src/loader.ts index 7ec3dfe..b9d53bb 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -1,8 +1,8 @@ import { validate } from 'schema-utils'; -import { Schema } from 'schema-utils/declarations/validate.js'; +import type { Schema } from 'schema-utils/declarations/validate.js'; import { loadConfig, optimize } from 'svgo'; import unTypedSchemaOptions from './schemas/loader-options.json' with { type: 'json' }; -import { LoaderOptions, LoaderThis } from './types.js'; +import type { LoaderOptions, LoaderThis } from './types.js'; import { PACKAGE_NAME } from './utils.js'; const schemaOptions = unTypedSchemaOptions as Schema; @@ -49,7 +49,7 @@ export default async function SvgChunkWebpackLoader( try { const { configFile } = options; - let config; + let config = null; if (typeof configFile === 'string') { try { config = await loadConfig(configFile, this.context); diff --git a/src/preview.ts b/src/preview.ts index d9b60eb..09f0b05 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -1,4 +1,4 @@ -import { Sprite } from './types.js'; +import type { Sprite } from './types.js'; export default function templatePreview(sprites: Sprite[]): string { return ` diff --git a/src/utils.ts b/src/utils.ts index 4e3e1ba..5fdd285 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ -import path from 'path'; -import { fileURLToPath } from 'url'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; export const PACKAGE_NAME = 'svg-chunk-webpack-plugin' as const; diff --git a/tests/index.test.js b/tests/index.test.js index 7b4ed20..cde9f0a 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -1,4 +1,4 @@ -import path from 'path'; +import path from 'node:path'; import SvgChunkWebpackPlugin from '@src/index'; import templatePreview from '@src/preview'; import schemaOptions from '@src/schemas/plugin-options.json'; diff --git a/tests/loader.test.js b/tests/loader.test.js index 036d8db..a0bb87e 100644 --- a/tests/loader.test.js +++ b/tests/loader.test.js @@ -1,5 +1,3 @@ -'use strict'; - import loader from '@src/loader'; import schemaOptions from '@src/schemas/loader-options.json'; import { PACKAGE_NAME } from '@src/utils'; @@ -86,7 +84,7 @@ describe('Loader', () => { }); it('Should call the loader function without factoryMeta object data', async () => { - delete _this._module.factoryMeta; + _this._module.factoryMeta = undefined; await loader.call(_this, ''); }); }); diff --git a/tests/preview.test.js b/tests/preview.test.js index beba237..d0346de 100644 --- a/tests/preview.test.js +++ b/tests/preview.test.js @@ -1,5 +1,3 @@ -'use strict'; - import preview from '@src/preview'; let previewSprite;