Skip to content

Commit

Permalink
deps: Use biomejs instead of eslint for code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Oct 16, 2024
1 parent 161d573 commit ed811eb
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 835 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fmt:
lint:
@$'(ansi g)Start `lint` task...(ansi reset)'; \
$'(ansi p)───────────────────────────────────────(ansi reset)'; \
pnpm eslint src/**/*.ts; \
pnpm biome lint src/**/*.ts; \
$'(ansi g)The `lint` task finished!(ansi reset)(char nl)';

# Build dist/index.js
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"indentStyle": "space"
},
"linter": {
"enabled": false
"enabled": true
},
"javascript": {
"formatter": {
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pre-commit:
- rebase
stage_fixed: true
glob: "*.{ts,tsx,js,jsx,es,cjs,mjs}"
run: pnpm eslint --cache --fix --no-error-on-unmatched-pattern {staged_files}
run: pnpm biome lint --fix {staged_files}
fmt:
skip:
- merge
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"private": true,
"scripts": {
"fmt": "biome format . --write",
"lint": "eslint **/*.ts",
"lint": "biome lint **/*.ts",
"build": "rm -rf dist/ && ncc build src/index.ts --minify",
"run": "pnpm run build && RUNNER_TOOL_CACHE=./runner/cache RUNNER_TEMP=./runner/temp node dist/index.js"
},
Expand All @@ -33,10 +33,7 @@
"@types/node": "^22.7.5",
"@types/semver": "^7.5.8",
"@types/shelljs": "^0.8.15",
"@typescript-eslint/eslint-plugin": "^8.8.1",
"@typescript-eslint/parser": "^8.8.1",
"@vercel/ncc": "^0.38.2",
"eslint": "^8.57.1",
"lefthook": "^1.7.18",
"semver": "^7.6.3",
"typescript": "^5.6.3"
Expand Down
780 changes: 0 additions & 780 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/plugins-tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shell from 'shelljs';
import semver from 'semver';
import { promises as fs, constants as fs_constants } from 'fs';
import { promises as fs, constants as fs_constants } from 'node:fs';

const nu = String.raw;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import shell from 'shelljs';
import semver from 'semver';
import { promises as fs, constants as fs_constants } from 'fs';
import { promises as fs, constants as fs_constants } from 'node:fs';

const nu = String.raw;

Expand Down
100 changes: 56 additions & 44 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* Created: 2022/04/28 18:50:20
*/

import * as path from 'path';
import { globby } from 'globby';
import * as semver from 'semver';
import * as path from 'node:path';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import { Octokit } from '@octokit/rest';
import { promises as fs, constants as fs_constants } from 'fs';
import { promises as fs, constants as fs_constants } from 'node:fs';

type Platform = 'darwin_x64' | 'darwin_arm64' | 'win32_x64' | 'win32_arm64' | 'linux_x64' | 'linux_arm64';

Expand Down Expand Up @@ -103,23 +103,27 @@ interface Release {
* @param response the response to filter a release from with the given versionSpec.
* @returns {Release[]} a single GitHub release.
*/
// biome-ignore lint: Ignore
function filterMatch(response: any, versionSpec: string | undefined, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
return response.data
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
})
.filter((rel: { version: string | semver.SemVer }) =>
rel && versionSpec ? semver.satisfies(rel.version, versionSpec) : true
);
return (
response.data
// biome-ignore lint: Ignore
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
})
.filter((rel: { version: string | semver.SemVer }) =>
rel && versionSpec ? semver.satisfies(rel.version, versionSpec) : true
)
);
}

/**
Expand All @@ -128,23 +132,27 @@ function filterMatch(response: any, versionSpec: string | undefined, features: '
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
// biome-ignore lint: Ignore
function filterLatest(response: any, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
const versions = response.data.map((r: { tag_name: string }) => r.tag_name);
const latest = semver.rsort(versions)[0];
return response.data
.filter((rel: { tag_name: string | semver.SemVer | undefined }) => rel && rel.tag_name === latest)
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
});
return (
response.data
.filter((rel: { tag_name: string | semver.SemVer | undefined }) => rel && rel.tag_name === latest)
// biome-ignore lint: Ignore
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
})
);
}

/**
Expand All @@ -153,26 +161,30 @@ function filterLatest(response: any, features: 'default' | 'full'): Release[] {
* @param response the response to filter a latest release from.
* @returns {Release[]} a single GitHub release.
*/
// biome-ignore lint: Ignore
function filterLatestNightly(response: any, features: 'default' | 'full'): Release[] {
const targets = getTargets(features);
const publishedAt = response.data.map((r: { published_at: string }) => r.published_at);
const sortedDates = publishedAt.sort((a: string, b: string) => new Date(b).getTime() - new Date(a).getTime());
const latest = sortedDates[0];
core.info(`Try to get latest nightly version published at: ${latest}`);

return response.data
.filter((rel: { published_at: string | Date }) => rel && rel.published_at === latest)
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
});
return (
response.data
.filter((rel: { published_at: string | Date }) => rel && rel.published_at === latest)
// biome-ignore lint: Ignore
.map((rel: { assets: any[]; tag_name: string }) => {
const asset = rel.assets.find((ass: { name: string | string[] }) =>
targets.some((target) => ass.name.includes(target))
);
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ''),
downloadUrl: asset.browser_download_url,
};
}
})
);
}

/**
Expand Down Expand Up @@ -256,7 +268,7 @@ export async function checkOrInstallTool(tool: Tool): Promise<InstalledTool> {
const artifact = await tc.downloadTool(downloadUrl);
core.debug(`Successfully downloaded ${name} v${version}`);

let extractDir;
let extractDir: string;
if (downloadUrl.endsWith('.zip')) {
extractDir = await tc.extractZip(artifact);
} else {
Expand Down

0 comments on commit ed811eb

Please sign in to comment.