From 0bd94fce3b690ba9c2308125c4d89ff2fa6f320a Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 30 Aug 2024 04:14:20 -0500 Subject: [PATCH] chore: Add `oxlint` for linting (#947) --- package.json | 2 +- packages/auto-icons/package.json | 3 +- packages/i18n/package.json | 3 +- packages/i18n/src/utils.ts | 2 +- packages/module-react/package.json | 2 +- packages/module-solid/package.json | 2 +- packages/module-svelte/package.json | 2 +- packages/module-vue/package.json | 2 +- packages/wxt/.oxlintignore | 1 + packages/wxt/package.json | 3 +- packages/wxt/src/core/create-server.ts | 2 +- .../src/core/utils/building/resolve-config.ts | 2 +- packages/wxt/src/core/utils/entrypoints.ts | 2 +- .../core/utils/environments/environment.ts | 2 +- packages/wxt/src/core/utils/eslint.ts | 3 +- packages/wxt/src/core/utils/manifest.ts | 8 +- packages/wxt/src/core/utils/package.ts | 1 + packages/wxt/src/core/utils/transform.ts | 4 +- pnpm-lock.yaml | 127 +++++++++++++++--- 19 files changed, 133 insertions(+), 40 deletions(-) create mode 100644 packages/wxt/.oxlintignore diff --git a/package.json b/package.json index 08b0452a8..ad778eea8 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "devDependencies": { "@aklinker1/buildc": "^1.1.1", - "@aklinker1/check": "^1.3.1", + "@aklinker1/check": "^1.4.5", "@types/fs-extra": "^11.0.4", "@vitest/coverage-v8": "^2.0.4", "changelogen": "^0.5.5", diff --git a/packages/auto-icons/package.json b/packages/auto-icons/package.json index 58f88b746..dbfd09274 100644 --- a/packages/auto-icons/package.json +++ b/packages/auto-icons/package.json @@ -45,7 +45,8 @@ "wxt": ">=0.19.0" }, "devDependencies": { - "@aklinker1/check": "^1.3.1", + "@aklinker1/check": "^1.4.5", + "oxlint": "^0.9.1", "publint": "^0.2.9", "typescript": "^5.5.4", "unbuild": "^2.0.0", diff --git a/packages/i18n/package.json b/packages/i18n/package.json index cf7841766..653b8d54d 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -38,9 +38,10 @@ } }, "devDependencies": { - "@aklinker1/check": "^1.3.1", + "@aklinker1/check": "^1.4.5", "@types/chrome": "^0.0.268", "@types/node": "^20.14.2", + "oxlint": "^0.9.1", "publint": "^0.2.8", "typescript": "^5.4.5", "unbuild": "^2.0.0", diff --git a/packages/i18n/src/utils.ts b/packages/i18n/src/utils.ts index 496cb006c..905aa1c08 100644 --- a/packages/i18n/src/utils.ts +++ b/packages/i18n/src/utils.ts @@ -14,7 +14,7 @@ export function applyChromeMessagePlaceholders(message: ChromeMessage): string { export function getSubstitionCount(message: string): number { return ( 1 + - new Array(MAX_SUBSTITUTIONS).findLastIndex((_, i) => + Array.from({ length: MAX_SUBSTITUTIONS }).findLastIndex((_, i) => message.match(new RegExp(`(? { ); const { ESLint } = require('eslint'); return ESLint.version?.split('.') ?? []; - } catch (error) { + } catch { + // Return an empty version when there's an error importing ESLint return []; } } diff --git a/packages/wxt/src/core/utils/manifest.ts b/packages/wxt/src/core/utils/manifest.ts index d2554b4bf..17a9feb1f 100644 --- a/packages/wxt/src/core/utils/manifest.ts +++ b/packages/wxt/src/core/utils/manifest.ts @@ -272,14 +272,14 @@ function addEntrypoints( options.browser_style = popup.options.browserStyle; if (manifest.manifest_version === 3) { manifest.action = { - ...(manifest.action ?? {}), + ...manifest.action, ...options, default_popup, }; } else { const key = popup.options.mv2Key ?? 'browser_action'; manifest[key] = { - ...(manifest[key] ?? {}), + ...manifest[key], ...options, default_popup, }; @@ -434,8 +434,8 @@ function discoverIcons( /^icon@([0-9]+)w\.png$/, // icon@16w.png /^icon@([0-9]+)h\.png$/, // icon@16h.png /^icon@([0-9]+)\.png$/, // icon@16.png - /^icons?[\/\\]([0-9]+)\.png$/, // icon/16.png | icons/16.png - /^icons?[\/\\]([0-9]+)x[0-9]+\.png$/, // icon/16x16.png | icons/16x16.png + /^icons?[/\\]([0-9]+)\.png$/, // icon/16.png | icons/16.png + /^icons?[/\\]([0-9]+)x[0-9]+\.png$/, // icon/16x16.png | icons/16x16.png ]; // #endregion snippet diff --git a/packages/wxt/src/core/utils/package.ts b/packages/wxt/src/core/utils/package.ts index 3de10935f..a1acfad40 100644 --- a/packages/wxt/src/core/utils/package.ts +++ b/packages/wxt/src/core/utils/package.ts @@ -16,6 +16,7 @@ export async function getPackageJson(): Promise< } catch (err) { wxt.logger.debug( `Failed to read package.json at: ${file}. Returning undefined.`, + err, ); return {}; } diff --git a/packages/wxt/src/core/utils/transform.ts b/packages/wxt/src/core/utils/transform.ts index b3245af8f..f6951c614 100644 --- a/packages/wxt/src/core/utils/transform.ts +++ b/packages/wxt/src/core/utils/transform.ts @@ -162,9 +162,7 @@ function getSimpleAstJson(ast: any): any { } else if (typeof ast === 'object') { return Object.fromEntries( Object.entries(ast) - .filter( - ([key, value]) => key !== 'loc' && key !== 'start' && key !== 'end', - ) + .filter(([key]) => key !== 'loc' && key !== 'start' && key !== 'end') .map(([key, value]) => [key, getSimpleAstJson(value)]), ); } else { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 03d2acecd..0c5d17362 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: ^1.1.1 version: 1.1.1(typescript@5.5.4) '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 @@ -97,8 +97,11 @@ importers: version: 0.33.4 devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) + oxlint: + specifier: ^0.9.1 + version: 0.9.1 publint: specifier: ^0.2.9 version: 0.2.9 @@ -125,14 +128,17 @@ importers: version: 3.3.2 devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) '@types/chrome': specifier: ^0.0.268 version: 0.0.268 '@types/node': specifier: ^20.14.2 version: 20.14.12 + oxlint: + specifier: ^0.9.1 + version: 0.9.1 publint: specifier: ^0.2.8 version: 0.2.9 @@ -159,8 +165,8 @@ importers: version: 4.3.1(vite@5.3.5(@types/node@20.14.12)(sass@1.77.8)) devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) '@types/react': specifier: ^18.3.3 version: 18.3.3 @@ -193,8 +199,8 @@ importers: version: 2.10.2(solid-js@1.8.19)(vite@5.3.5(@types/node@20.14.12)(sass@1.77.8)) devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) publint: specifier: ^0.2.9 version: 0.2.9 @@ -218,8 +224,8 @@ importers: version: 3.1.1(svelte@4.2.18)(vite@5.3.5(@types/node@20.14.12)(sass@1.77.8)) devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) publint: specifier: ^0.2.9 version: 0.2.9 @@ -240,8 +246,8 @@ importers: version: 5.1.1(vite@5.3.5(@types/node@20.14.12)(sass@1.77.8))(vue@3.4.34(typescript@5.5.4)) devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) publint: specifier: ^0.2.9 version: 0.2.9 @@ -385,8 +391,8 @@ importers: version: 0.12.0 devDependencies: '@aklinker1/check': - specifier: ^1.3.1 - version: 1.3.1(typescript@5.5.4) + specifier: ^1.4.5 + version: 1.4.5(typescript@5.5.4) '@faker-js/faker': specifier: ^8.4.1 version: 8.4.1 @@ -420,6 +426,9 @@ importers: lodash.merge: specifier: ^4.6.2 version: 4.6.2 + oxlint: + specifier: ^0.9.1 + version: 0.9.1 p-map: specifier: ^7.0.2 version: 7.0.2 @@ -490,8 +499,8 @@ packages: peerDependencies: typescript: ^5.0.0 - '@aklinker1/check@1.3.1': - resolution: {integrity: sha512-EALKJzoojytjC6cYLIjRjC+nNpVdqSWYjJm8FTUtWneemKDs+Q46PaMyEx2EYTRbj4fO0OXj9igABwbpp/vV4g==} + '@aklinker1/check@1.4.5': + resolution: {integrity: sha512-whVpnpSK4qa4/83q22JAmxwRAEj35qYs8eIH/tX1C6rKbiwx7EL6kQVmSAhCe1NYqzoIWyOgsISdDPyHjC+h2A==} hasBin: true peerDependencies: typescript: ^5.0.0 @@ -1338,6 +1347,46 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@oxlint/darwin-arm64@0.9.1': + resolution: {integrity: sha512-SzYTggt2eJqMhemijEv9AszSdc8Vv1OBQbmAZpDNPHmwlDzPKEopSrDURwt/Jq56FYsJC/jhzBzrJLXSK55i1A==} + cpu: [arm64] + os: [darwin] + + '@oxlint/darwin-x64@0.9.1': + resolution: {integrity: sha512-IDgjpNdtt2XkEcWDIhFyZCkIIonqlBQf3jQ2L1voGQxQFwjl+cP9+hdpFp/m89qGO708MULeegCH+MGq28xWbg==} + cpu: [x64] + os: [darwin] + + '@oxlint/linux-arm64-gnu@0.9.1': + resolution: {integrity: sha512-kEGN/CNdUB11So4c3OpTIJi0YvPgu5i9gvUcWX+CxEkeACRPj8dq7/Rm1FgfIqky6oYY5QjXDioZ+yKt+Xw1rQ==} + cpu: [arm64] + os: [linux] + + '@oxlint/linux-arm64-musl@0.9.1': + resolution: {integrity: sha512-US5UVB7JDwNuQa2+RZyWzEtgjEOA9wAvwUy8oUmgqomo02cpCrZo3wOQAvAckE5KxJCskr7T6pGW9eA8y3IhsQ==} + cpu: [arm64] + os: [linux] + + '@oxlint/linux-x64-gnu@0.9.1': + resolution: {integrity: sha512-w2Sz/WevEa6FxDjwwg9xbmpebDmLXO9YCvUUs5K4emKhzh05xEwuXrD2kJuQUdFapiHHQUMTQ5/iBF0NOPb9Uw==} + cpu: [x64] + os: [linux] + + '@oxlint/linux-x64-musl@0.9.1': + resolution: {integrity: sha512-hSukTLTn+wKyJUbR3934bOmWNoDaJv4yJwumE6QqBQZWoFNyd3seiYJLPWD+7aMJx6nOnot8uqjnvYO1QZsccA==} + cpu: [x64] + os: [linux] + + '@oxlint/win32-arm64@0.9.1': + resolution: {integrity: sha512-9Y7RuvnulhZyxLdsDrGRaojxytzcBTGHpl7AxED41G/IXGPOs+dE1q2NFyHWB6Gfzi/MJZ6plXYIOKx/e/3t/g==} + cpu: [arm64] + os: [win32] + + '@oxlint/win32-x64@0.9.1': + resolution: {integrity: sha512-51wrzMDGFyCYZbhSczU9VS7EYe1N0tNlDfdne6VCKgpPPJX0+XLZHybgUFZNYVyf7/W5t1/gpyOTFErVYRP0pw==} + cpu: [x64] + os: [win32] + '@pkgjs/parseargs@0.11.0': resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -3508,6 +3557,11 @@ packages: resolution: {integrity: sha512-jd0cvB8qQ5uVt0lvCIexBaROw1KyKm5sbulg2fWOHjETisuCzWyt+eTZKEMs8v6HwzoGs8xik26jg7eCM6pS+A==} engines: {node: '>= 0.4.0'} + oxlint@0.9.1: + resolution: {integrity: sha512-77v9YVkaVOWguxUttiJ31yfWkG/Yo7kIzY0CrKHxM6p0xiUqN0LVF4IVgjcE6vevyd9bBVphtOgJOJUq4To/+w==} + engines: {node: '>=14.*'} + hasBin: true + p-cancelable@3.0.0: resolution: {integrity: sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==} engines: {node: '>=12.20'} @@ -4834,7 +4888,7 @@ snapshots: typescript: 5.5.4 yaml: 2.5.0 - '@aklinker1/check@1.3.1(typescript@5.5.4)': + '@aklinker1/check@1.4.5(typescript@5.5.4)': dependencies: '@antfu/utils': 0.7.7 ci-info: 4.0.0 @@ -5507,6 +5561,30 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 + '@oxlint/darwin-arm64@0.9.1': + optional: true + + '@oxlint/darwin-x64@0.9.1': + optional: true + + '@oxlint/linux-arm64-gnu@0.9.1': + optional: true + + '@oxlint/linux-arm64-musl@0.9.1': + optional: true + + '@oxlint/linux-x64-gnu@0.9.1': + optional: true + + '@oxlint/linux-x64-musl@0.9.1': + optional: true + + '@oxlint/win32-arm64@0.9.1': + optional: true + + '@oxlint/win32-x64@0.9.1': + optional: true + '@pkgjs/parseargs@0.11.0': optional: true @@ -7922,6 +8000,17 @@ snapshots: os-shim@0.1.3: {} + oxlint@0.9.1: + optionalDependencies: + '@oxlint/darwin-arm64': 0.9.1 + '@oxlint/darwin-x64': 0.9.1 + '@oxlint/linux-arm64-gnu': 0.9.1 + '@oxlint/linux-arm64-musl': 0.9.1 + '@oxlint/linux-x64-gnu': 0.9.1 + '@oxlint/linux-x64-musl': 0.9.1 + '@oxlint/win32-arm64': 0.9.1 + '@oxlint/win32-x64': 0.9.1 + p-cancelable@3.0.0: {} p-limit@5.0.0: