From ab3f68b1e5679cb65241b1b94708b61f7ae4d994 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Mon, 30 Dec 2024 03:22:13 -0300 Subject: [PATCH] fix: eslint rules after enabling eslint-plugin-unicorn (#724) --- .gitignore | 116 ++++- .prettierrc | 3 - .vscode/settings.json | 4 + eslint.config.js | 13 +- index.js | 8 +- lib/prepare.js | 12 +- lib/publish.js | 4 +- lib/utils.js | 4 +- lib/verify-ovsx-auth.js | 4 +- lib/{verify-pkg.js => verify-package.js} | 6 +- lib/verify-target.js | 3 +- lib/verify-vsce-auth.js | 10 +- lib/verify.js | 4 +- package-lock.json | 467 ++++++++++++++++++ package.json | 1 + prettier.config.js | 9 + test/index.test.js | 10 +- test/publish.test.js | 8 +- ...ify-pkg.test.js => verify-package.test.js} | 24 +- test/verify.test.js | 36 +- 20 files changed, 667 insertions(+), 79 deletions(-) delete mode 100644 .prettierrc create mode 100644 .vscode/settings.json rename lib/{verify-pkg.js => verify-package.js} (86%) create mode 100644 prettier.config.js rename test/{verify-pkg.test.js => verify-package.test.js} (72%) diff --git a/.gitignore b/.gitignore index 7417d481..1361c662 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,18 @@ +# Created by https://www.toptal.com/developers/gitignore/api/node,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=node,visualstudiocode + +### Node ### # Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids @@ -16,11 +25,12 @@ lib-cov # Coverage directory used by tools like istanbul coverage +*.lcov # nyc test coverage .nyc_output -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) @@ -29,15 +39,18 @@ bower_components # node-waf configuration .lock-wscript -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ -# Typescript v1 declaration files -typings/ +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo # Optional npm cache directory .npm @@ -45,6 +58,15 @@ typings/ # Optional eslint cache .eslintcache +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + # Optional REPL history .node_repl_history @@ -54,8 +76,88 @@ typings/ # Yarn Integrity file .yarn-integrity -# dotenv environment variables file +# dotenv environment variable files .env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide -# Editor configs -.vscode +# End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 544138be..00000000 --- a/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "singleQuote": true -} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b1a89502 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode", + "eslint.useFlatConfig": true +} diff --git a/eslint.config.js b/eslint.config.js index 8c911e2c..471617f2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,7 +1,12 @@ // @ts-check -import neostandard from 'neostandard'; +import neostandard, { resolveIgnoresFromGitignore } from 'neostandard'; +import eslintPluginUnicorn from 'eslint-plugin-unicorn'; -export default neostandard({ - noStyle: true, -}); +export default [ + ...neostandard({ + ignores: resolveIgnoresFromGitignore(), + noStyle: true, + }), + eslintPluginUnicorn.configs['flat/recommended'], +]; diff --git a/index.js b/index.js index 7d696671..51482baf 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ // @ts-check -import { join } from 'node:path'; +import path from 'node:path'; import { prepare as vscePrepare } from './lib/prepare.js'; import { publish as vscePublish } from './lib/publish.js'; import { verify as vsceVerify } from './lib/verify.js'; @@ -60,7 +60,7 @@ export async function publish( if (pluginConfig?.publishPackagePath) { // Expand glob - const glob = (await import('glob')).glob; + const { glob } = await import('glob'); packagePath = await glob(pluginConfig.publishPackagePath, { cwd }); } @@ -68,5 +68,7 @@ export async function publish( } function getPackageRoot(pluginConfig, cwd) { - return pluginConfig.packageRoot ? join(cwd, pluginConfig.packageRoot) : cwd; + return pluginConfig.packageRoot + ? path.join(cwd, pluginConfig.packageRoot) + : cwd; } diff --git a/lib/prepare.js b/lib/prepare.js index 07e360a5..f1071611 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -2,7 +2,7 @@ import { execa } from 'execa'; import { readJson } from 'fs-extra/esm'; -import { join } from 'node:path'; +import path from 'node:path'; import process from 'node:process'; import { isOvsxPublishEnabled, isTargetEnabled } from './utils.js'; @@ -25,12 +25,10 @@ export async function prepare(version, packageVsix, logger, cwd) { if (typeof packageVsix === 'string') { packagePath = packageVsix; } else { - const { name } = await readJson(join(cwd, './package.json')); - if (isTargetEnabled()) { - packagePath = `${name}-${process.env.VSCE_TARGET}-${version}.vsix`; - } else { - packagePath = `${name}-${version}.vsix`; - } + const { name } = await readJson(path.join(cwd, './package.json')); + packagePath = isTargetEnabled() + ? `${name}-${process.env.VSCE_TARGET}-${version}.vsix` + : `${name}-${version}.vsix`; } logger.log(`Packaging version ${version} to ${packagePath}`); diff --git a/lib/publish.js b/lib/publish.js index 0bd4cb6e..a0f2c119 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -2,7 +2,7 @@ import { execa } from 'execa'; import { readJson } from 'fs-extra/esm'; -import { join } from 'node:path'; +import path from 'node:path'; import process from 'node:process'; import { isAzureCredentialEnabled, @@ -12,7 +12,7 @@ import { } from './utils.js'; export async function publish(version, packagePath, logger, cwd) { - const { publisher, name } = await readJson(join(cwd, './package.json')); + const { publisher, name } = await readJson(path.join(cwd, './package.json')); const options = ['publish']; diff --git a/lib/utils.js b/lib/utils.js index 0d62ad4e..71885fae 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -2,7 +2,7 @@ import process from 'node:process'; -function envToBoolean(name) { +function environmentToBoolean(name) { return process.env[name] === 'true' || process.env[name] === '1'; } @@ -11,7 +11,7 @@ export function isOvsxPublishEnabled() { } export function isAzureCredentialEnabled() { - return envToBoolean('VSCE_AZURE_CREDENTIAL'); + return environmentToBoolean('VSCE_AZURE_CREDENTIAL'); } export function isVscePublishEnabled() { diff --git a/lib/verify-ovsx-auth.js b/lib/verify-ovsx-auth.js index 2cd0df3c..1da5571e 100644 --- a/lib/verify-ovsx-auth.js +++ b/lib/verify-ovsx-auth.js @@ -16,9 +16,9 @@ export async function verifyOvsxAuth(logger, cwd) { try { await execa('ovsx', ['verify-pat'], { preferLocal: true, cwd }); - } catch (e) { + } catch (error) { throw new SemanticReleaseError( - `Invalid ovsx personal access token. Additional information:\n\n${e}`, + `Invalid ovsx personal access token. Additional information:\n\n${error}`, 'EINVALIDOVSXPAT', ); } diff --git a/lib/verify-pkg.js b/lib/verify-package.js similarity index 86% rename from lib/verify-pkg.js rename to lib/verify-package.js index ade00f00..739039d4 100644 --- a/lib/verify-pkg.js +++ b/lib/verify-package.js @@ -2,10 +2,10 @@ import SemanticReleaseError from '@semantic-release/error'; import { pathExists, readJson } from 'fs-extra/esm'; -import { join } from 'node:path'; +import path from 'node:path'; -export async function verifyPkg(cwd) { - const packagePath = join(cwd, './package.json'); +export async function verifyPackage(cwd) { + const packagePath = path.join(cwd, './package.json'); if (!(await pathExists(packagePath))) { throw new SemanticReleaseError( diff --git a/lib/verify-target.js b/lib/verify-target.js index a9d81c09..260e8fcd 100644 --- a/lib/verify-target.js +++ b/lib/verify-target.js @@ -17,7 +17,8 @@ export async function verifyTarget() { } if (process.env.VSCE_TARGET !== 'universal') { - const targets = (await import('@vscode/vsce/out/package.js')).Targets; + const vscePackage = await import('@vscode/vsce/out/package.js'); + const targets = vscePackage.Targets; // Throw if the target is not supported if (!targets.has(process.env.VSCE_TARGET)) { diff --git a/lib/verify-vsce-auth.js b/lib/verify-vsce-auth.js index ea0097b2..3adfba2c 100644 --- a/lib/verify-vsce-auth.js +++ b/lib/verify-vsce-auth.js @@ -23,16 +23,16 @@ export async function verifyVsceAuth(logger, cwd) { ); } - const vsceArgs = ['verify-pat']; + const vsceArguments = ['verify-pat']; if (azureCredential) { - vsceArgs.push('--azure-credential'); + vsceArguments.push('--azure-credential'); } try { - await execa('vsce', vsceArgs, { preferLocal: true, cwd }); - } catch (e) { + await execa('vsce', vsceArguments, { preferLocal: true, cwd }); + } catch (error) { throw new SemanticReleaseError( - `Invalid vsce personal access token or azure credential. Additional information:\n\n${e}`, + `Invalid vsce personal access token or azure credential. Additional information:\n\n${error}`, 'EINVALIDVSCEPAT', ); } diff --git a/lib/verify.js b/lib/verify.js index 522b0f8e..515d42bd 100644 --- a/lib/verify.js +++ b/lib/verify.js @@ -3,12 +3,12 @@ import SemanticReleaseError from '@semantic-release/error'; import { isOvsxPublishEnabled, isVscePublishEnabled } from './utils.js'; import { verifyOvsxAuth } from './verify-ovsx-auth.js'; -import { verifyPkg } from './verify-pkg.js'; +import { verifyPackage } from './verify-package.js'; import { verifyTarget } from './verify-target.js'; import { verifyVsceAuth } from './verify-vsce-auth.js'; export async function verify(pluginConfig, { logger, cwd }) { - await verifyPkg(cwd); + await verifyPackage(cwd); await verifyTarget(); if (pluginConfig?.publish !== false) { diff --git a/package-lock.json b/package-lock.json index 3749da50..aa12378b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "c8": "^10.1.3", "conventional-changelog-conventionalcommits": "^8.0.0", "eslint": "^9.12.0", + "eslint-plugin-unicorn": "^56.0.1", "esmock": "^2.6.9", "husky": "^9.0.11", "installed-check": "^9.0.0", @@ -2330,6 +2331,39 @@ "node": ">=8" } }, + "node_modules/browserslist": { + "version": "4.24.3", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.3.tgz", + "integrity": "sha512-1CPmv8iobE2fyRMV97dAcMVegvvWKxmq94hkLiAkUGwKVTyDLw33K+ZxiFrREKmmps4rIw6grcCFCnTMSZ/YiA==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "caniuse-lite": "^1.0.30001688", + "electron-to-chromium": "^1.5.73", + "node-releases": "^2.0.19", + "update-browserslist-db": "^1.1.1" + }, + "bin": { + "browserslist": "cli.js" + }, + "engines": { + "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + } + }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", @@ -2380,6 +2414,19 @@ "node": ">=18.6.0" } }, + "node_modules/builtin-modules": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/c8": { "version": "10.1.3", "resolved": "https://registry.npmjs.org/c8/-/c8-10.1.3.tgz", @@ -2577,6 +2624,27 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/caniuse-lite": { + "version": "1.0.30001690", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz", + "integrity": "sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "CC-BY-4.0" + }, "node_modules/cbor": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/cbor/-/cbor-9.0.2.tgz", @@ -2708,6 +2776,19 @@ "dev": true, "license": "MIT" }, + "node_modules/clean-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clean-regexp/-/clean-regexp-1.0.0.tgz", + "integrity": "sha512-GfisEZEJvzKrmGWkvfhgzcz/BllN1USeqD2V6tg14OAOgaCD2Z/PUEuxnAZ/nPvmaHRG7a8y77p1T/IRQ4D1Hw==", + "dev": true, + "license": "MIT", + "dependencies": { + "escape-string-regexp": "^1.0.5" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/clean-stack": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-5.2.0.tgz", @@ -3452,6 +3533,20 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" } }, + "node_modules/core-js-compat": { + "version": "3.39.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.39.0.tgz", + "integrity": "sha512-VgEUx3VwlExr5no0tXlBt+silBvhTryPwCXRI2Id1PN8WTKu7MreethvddqOubrYxkFdv/RnYrqlv1sFNAUelw==", + "dev": true, + "license": "MIT", + "dependencies": { + "browserslist": "^4.24.2" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -3930,6 +4025,13 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/electron-to-chromium": { + "version": "1.5.76", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.76.tgz", + "integrity": "sha512-CjVQyG7n7Sr+eBXE86HIulnL5N8xZY1sgmOPGuq/F0Rr0FJq63lg0kEtOIDfZBk44FnDLf6FUJ+dsJcuiUDdDQ==", + "dev": true, + "license": "ISC" + }, "node_modules/emittery": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/emittery/-/emittery-1.0.3.tgz", @@ -4721,6 +4823,63 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-unicorn": { + "version": "56.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.1.tgz", + "integrity": "sha512-FwVV0Uwf8XPfVnKSGpMg7NtlZh0G0gBarCaFcMUOoqPxXryxdYxTRRv4kH6B9TFCVIrjRXG+emcxIk2ayZilog==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/helper-validator-identifier": "^7.24.7", + "@eslint-community/eslint-utils": "^4.4.0", + "ci-info": "^4.0.0", + "clean-regexp": "^1.0.0", + "core-js-compat": "^3.38.1", + "esquery": "^1.6.0", + "globals": "^15.9.0", + "indent-string": "^4.0.0", + "is-builtin-module": "^3.2.1", + "jsesc": "^3.0.2", + "pluralize": "^8.0.0", + "read-pkg-up": "^7.0.1", + "regexp-tree": "^0.1.27", + "regjsparser": "^0.10.0", + "semver": "^7.6.3", + "strip-indent": "^3.0.0" + }, + "engines": { + "node": ">=18.18" + }, + "funding": { + "url": "https://github.com/sindresorhus/eslint-plugin-unicorn?sponsor=1" + }, + "peerDependencies": { + "eslint": ">=8.56.0" + } + }, + "node_modules/eslint-plugin-unicorn/node_modules/globals": { + "version": "15.14.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.14.0.tgz", + "integrity": "sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-plugin-unicorn/node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", @@ -6156,6 +6315,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-builtin-module": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", + "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", + "dev": true, + "license": "MIT", + "dependencies": { + "builtin-modules": "^3.3.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-bun-module": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/is-bun-module/-/is-bun-module-1.3.0.tgz", @@ -6772,6 +6947,19 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsesc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", + "dev": true, + "license": "MIT", + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -7693,6 +7881,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/min-indent": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", + "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -8041,6 +8239,13 @@ "node-gyp-build-test": "build-test.js" } }, + "node_modules/node-releases": { + "version": "2.0.19", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz", + "integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==", + "dev": true, + "license": "MIT" + }, "node_modules/nofilter": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/nofilter/-/nofilter-3.1.0.tgz", @@ -11237,6 +11442,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/package-config": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/package-config/-/package-config-5.0.0.tgz", @@ -11667,6 +11882,16 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/pony-cause": { "version": "2.1.11", "resolved": "https://registry.npmjs.org/pony-cause/-/pony-cause-2.1.11.tgz", @@ -11957,6 +12182,162 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/read-pkg-up": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", + "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^4.1.0", + "read-pkg": "^5.2.0", + "type-fest": "^0.8.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/read-pkg-up/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "dev": true, + "license": "MIT", + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg-up/node_modules/hosted-git-info": { + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", + "dev": true, + "license": "ISC" + }, + "node_modules/read-pkg-up/node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true, + "license": "MIT" + }, + "node_modules/read-pkg-up/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg-up/node_modules/normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "node_modules/read-pkg-up/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/read-pkg-up/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg-up/node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/read-pkg-up/node_modules/read-pkg": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", + "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^2.5.0", + "parse-json": "^5.0.0", + "type-fest": "^0.6.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg-up/node_modules/read-pkg/node_modules/type-fest": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg-up/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver" + } + }, "node_modules/read-pkg/node_modules/type-fest": { "version": "4.31.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.31.0.tgz", @@ -12052,6 +12433,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/regexp-tree": { + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", + "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", + "dev": true, + "license": "MIT", + "bin": { + "regexp-tree": "bin/regexp-tree" + } + }, "node_modules/regexp.prototype.flags": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", @@ -12084,6 +12475,28 @@ "node": ">=14" } }, + "node_modules/regjsparser": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.10.0.tgz", + "integrity": "sha512-qx+xQGZVsy55CH0a1hiVwHmqjLryfh7wQyF5HO07XJ9f7dQMY/gPQHhlyDkIzJKC+x2fUCpCcUODUUUFrm7SHA==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "jsesc": "~0.5.0" + }, + "bin": { + "regjsparser": "bin/parser" + } + }, + "node_modules/regjsparser/node_modules/jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==", + "dev": true, + "bin": { + "jsesc": "bin/jsesc" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -13097,6 +13510,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strip-indent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", + "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "min-indent": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -13543,6 +13969,16 @@ "node": ">=4" } }, + "node_modules/type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=8" + } + }, "node_modules/typed-array-buffer": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.3.tgz", @@ -13779,6 +14215,37 @@ "node": ">= 10.0.0" } }, + "node_modules/update-browserslist-db": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", + "integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "escalade": "^3.2.0", + "picocolors": "^1.1.0" + }, + "bin": { + "update-browserslist-db": "cli.js" + }, + "peerDependencies": { + "browserslist": ">= 4.21.0" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 00a325e5..013a17c2 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "c8": "^10.1.3", "conventional-changelog-conventionalcommits": "^8.0.0", "eslint": "^9.12.0", + "eslint-plugin-unicorn": "^56.0.1", "esmock": "^2.6.9", "husky": "^9.0.11", "installed-check": "^9.0.0", diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 00000000..0e8830c2 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,9 @@ +// @ts-check + +/** + * @see https://prettier.io/docs/en/configuration.html + * @type {import("prettier").Config} + */ +export default { + singleQuote: true, +}; diff --git a/test/index.test.js b/test/index.test.js index 3fc4d26e..ecf848e4 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,6 +1,6 @@ import avaTest from 'ava'; import esmock from 'esmock'; -import { resolve } from 'path'; +import path from 'node:path'; import { fake, stub } from 'sinon'; // Run tests serially to avoid env pollution @@ -29,9 +29,9 @@ test.beforeEach((t) => { }); test.afterEach((t) => { - Object.keys(t.context.stubs).forEach((key) => { + for (const key of Object.keys(t.context.stubs)) { t.context.stubs[key].resetHistory(); - }); + } }); test('verifyConditions', async (t) => { @@ -305,7 +305,9 @@ test('publishes an extension in a non-root folder', async (t) => { const pluginConfig = { packageRoot: './vscode-extension', }; - const resolvedCwd = resolve(`${semanticReleasePayload.cwd}/vscode-extension`); + const resolvedCwd = path.resolve( + `${semanticReleasePayload.cwd}/vscode-extension`, + ); await publish(pluginConfig, semanticReleasePayload); diff --git a/test/publish.test.js b/test/publish.test.js index b28a556e..a55614c1 100644 --- a/test/publish.test.js +++ b/test/publish.test.js @@ -81,8 +81,8 @@ test('publish to vs marketplace with VSCE_AZURE_CREDENTIAL=true', async (t) => { name: 'Visual Studio Marketplace', url: `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`, }); - const args0 = execaStub.getCall(0).args; - t.deepEqual(args0, [ + const arguments0 = execaStub.getCall(0).args; + t.deepEqual(arguments0, [ 'vsce', ['publish', '--packagePath', packagePath, '--azure-credential'], { stdio: 'inherit', preferLocal: true, cwd }, @@ -116,8 +116,8 @@ test('publish to vs marketplace with VSCE_AZURE_CREDENTIAL=1', async (t) => { name: 'Visual Studio Marketplace', url: `https://marketplace.visualstudio.com/items?itemName=${publisher}.${name}`, }); - const args0 = execaStub.getCall(0).args; - t.deepEqual(args0, [ + const arguments0 = execaStub.getCall(0).args; + t.deepEqual(arguments0, [ 'vsce', ['publish', '--packagePath', packagePath, '--azure-credential'], { stdio: 'inherit', preferLocal: true, cwd }, diff --git a/test/verify-pkg.test.js b/test/verify-package.test.js similarity index 72% rename from test/verify-pkg.test.js rename to test/verify-package.test.js index 73b0d97b..868bc7ee 100644 --- a/test/verify-pkg.test.js +++ b/test/verify-package.test.js @@ -12,7 +12,7 @@ test('package.json is found', async (t) => { const name = 'test'; const publisher = 'tester'; - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(true), readJson: stub().resolves({ @@ -22,14 +22,14 @@ test('package.json is found', async (t) => { }, }); - await t.notThrowsAsync(() => verifyPkg(cwd)); + await t.notThrowsAsync(() => verifyPackage(cwd)); }); test('package.json is not found', async (t) => { const name = 'test'; const publisher = 'tester'; - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(false), readJson: stub().resolves({ @@ -39,7 +39,7 @@ test('package.json is not found', async (t) => { }, }); - await t.throwsAsync(() => verifyPkg(cwd), { + await t.throwsAsync(() => verifyPackage(cwd), { instanceOf: SemanticReleaseError, code: 'ENOPKG', }); @@ -48,7 +48,7 @@ test('package.json is not found', async (t) => { test('package is valid', async (t) => { const name = 'test'; const publisher = 'tester'; - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(true), readJson: stub().resolves({ @@ -58,18 +58,18 @@ test('package is valid', async (t) => { }, }); - await t.notThrowsAsync(() => verifyPkg(cwd)); + await t.notThrowsAsync(() => verifyPackage(cwd)); }); test('package is invalid', async (t) => { - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(true), readJson: stub().rejects(), }, }); - await t.throwsAsync(() => verifyPkg(cwd), { + await t.throwsAsync(() => verifyPackage(cwd), { instanceOf: SemanticReleaseError, code: 'EINVALIDPKG', }); @@ -77,7 +77,7 @@ test('package is invalid', async (t) => { test('package is missing name', async (t) => { const publisher = 'tester'; - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(true), readJson: stub().resolves({ @@ -86,7 +86,7 @@ test('package is missing name', async (t) => { }, }); - await t.throwsAsync(() => verifyPkg(cwd), { + await t.throwsAsync(() => verifyPackage(cwd), { instanceOf: SemanticReleaseError, code: 'ENOPKGNAME', }); @@ -94,7 +94,7 @@ test('package is missing name', async (t) => { test('package is missing publisher', async (t) => { const name = 'test'; - const { verifyPkg } = await esmock('../lib/verify-pkg.js', { + const { verifyPackage } = await esmock('../lib/verify-package.js', { 'fs-extra/esm': { pathExists: stub().resolves(true), readJson: stub().resolves({ @@ -103,7 +103,7 @@ test('package is missing publisher', async (t) => { }, }); - await t.throwsAsync(() => verifyPkg(cwd), { + await t.throwsAsync(() => verifyPackage(cwd), { instanceOf: SemanticReleaseError, code: 'ENOPUBLISHER', }); diff --git a/test/verify.test.js b/test/verify.test.js index e05bf0f2..f11f6643 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -10,8 +10,8 @@ const cwd = process.cwd(); test('resolves', async (t) => { const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stub().resolves(), + '../lib/verify-package.js': { + verifyPackage: stub().resolves(), }, '../lib/verify-target.js': { verifyTarget: stub().resolves(), @@ -33,8 +33,8 @@ test('resolves', async (t) => { test('rejects with verify-pkg', async (t) => { const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stub().rejects(), + '../lib/verify-package.js': { + verifyPackage: stub().rejects(), }, '../lib/verify-target.js': { verifyTarget: stub().resolves(), @@ -52,8 +52,8 @@ test('rejects with verify-pkg', async (t) => { test('rejects with verify-target', async (t) => { const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stub().resolves(), + '../lib/verify-package.js': { + verifyPackage: stub().resolves(), }, '../lib/verify-target.js': { verifyTarget: stub().rejects(), @@ -71,8 +71,8 @@ test('rejects with verify-target', async (t) => { test('rejects with verify-auth', async (t) => { const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stub().resolves(), + '../lib/verify-package.js': { + verifyPackage: stub().resolves(), }, '../lib/verify-target.js': { verifyTarget: stub().resolves(), @@ -90,8 +90,8 @@ test('rejects with verify-auth', async (t) => { test('rejects with verify-ovsx-auth', async (t) => { const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stub().resolves(), + '../lib/verify-package.js': { + verifyPackage: stub().resolves(), }, '../lib/verify-target.js': { verifyTarget: stub().resolves(), @@ -115,8 +115,8 @@ test('it does not verify the auth tokens if publishing is disabled', async (t) = verifyOvsxAuthStub: stub().resolves(), }; const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stubs.verifyPkgStub, + '../lib/verify-package.js': { + verifyPackage: stubs.verifyPkgStub, }, '../lib/verify-target.js': { verifyTarget: stubs.verifyTargetStub, @@ -147,8 +147,8 @@ test('errors when neither vsce nor ovsx personal access token is configured', as }, }; const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stubs.verifyPkgStub, + '../lib/verify-package.js': { + verifyPackage: stubs.verifyPkgStub, }, '../lib/verify-target.js': { verifyTarget: stubs.verifyTargetStub, @@ -185,8 +185,8 @@ test('verify vsce only', async (t) => { }, }; const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stubs.verifyPkgStub, + '../lib/verify-package.js': { + verifyPackage: stubs.verifyPkgStub, }, '../lib/verify-target.js': { verifyTarget: stubs.verifyTargetStub, @@ -221,8 +221,8 @@ test('verify ovsx only', async (t) => { }, }; const { verify } = await esmock('../lib/verify.js', { - '../lib/verify-pkg.js': { - verifyPkg: stubs.verifyPkgStub, + '../lib/verify-package.js': { + verifyPackage: stubs.verifyPkgStub, }, '../lib/verify-target.js': { verifyTarget: stubs.verifyTargetStub,