Skip to content

Commit

Permalink
fix: eslint rules after enabling eslint-plugin-unicorn (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs authored Dec 30, 2024
1 parent 7881885 commit ab3f68b
Show file tree
Hide file tree
Showing 20 changed files with 667 additions and 79 deletions.
116 changes: 109 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/)
Expand All @@ -29,22 +39,34 @@ 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

# 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

Expand All @@ -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
3 changes: 0 additions & 3 deletions .prettierrc

This file was deleted.

4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.useFlatConfig": true
}
13 changes: 9 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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'],
];
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -60,13 +60,15 @@ 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 });
}

return vscePublish(version, packagePath, logger, cwd);
}

function getPackageRoot(pluginConfig, cwd) {
return pluginConfig.packageRoot ? join(cwd, pluginConfig.packageRoot) : cwd;
return pluginConfig.packageRoot
? path.join(cwd, pluginConfig.packageRoot)
: cwd;
}
12 changes: 5 additions & 7 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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}`);
Expand Down
4 changes: 2 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'];

Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import process from 'node:process';

function envToBoolean(name) {
function environmentToBoolean(name) {
return process.env[name] === 'true' || process.env[name] === '1';
}

Expand All @@ -11,7 +11,7 @@ export function isOvsxPublishEnabled() {
}

export function isAzureCredentialEnabled() {
return envToBoolean('VSCE_AZURE_CREDENTIAL');
return environmentToBoolean('VSCE_AZURE_CREDENTIAL');
}

export function isVscePublishEnabled() {
Expand Down
4 changes: 2 additions & 2 deletions lib/verify-ovsx-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/verify-pkg.js → lib/verify-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion lib/verify-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
10 changes: 5 additions & 5 deletions lib/verify-vsce-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit ab3f68b

Please sign in to comment.