Skip to content

Commit 551ef55

Browse files
committed
style: reformat codebase with oxfmt
1 parent bec4160 commit 551ef55

File tree

8 files changed

+341
-295
lines changed

8 files changed

+341
-295
lines changed

package.json

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
11
{
22
"name": "github-copilot-usage",
33
"displayName": "GitHub Copilot Usage",
4-
"description": "Show GitHub Copilot Premium requests usage in the status bar.",
54
"version": "0.4.2",
6-
"author": "euxx",
7-
"license": "MIT",
8-
"repository": {
9-
"type": "git",
10-
"url": "https://github.com/euxx/github-copilot-usage"
11-
},
12-
"icon": "images/icon.png",
5+
"description": "Show GitHub Copilot Premium requests usage in the status bar.",
6+
"categories": [
7+
"Other"
8+
],
139
"keywords": [
14-
"github",
1510
"copilot",
16-
"usage",
11+
"github",
1712
"quota",
1813
"status-bar",
14+
"usage",
1915
"vscode",
2016
"vscode-extension"
2117
],
22-
"publisher": "euxx",
23-
"engines": {
24-
"vscode": "^1.85.0"
18+
"license": "MIT",
19+
"author": "euxx",
20+
"repository": {
21+
"type": "git",
22+
"url": "https://github.com/euxx/github-copilot-usage"
2523
},
26-
"categories": [
27-
"Other"
28-
],
29-
"activationEvents": [
30-
"onStartupFinished"
31-
],
24+
"publisher": "euxx",
3225
"main": "./src/extension.js",
26+
"scripts": {
27+
"vscode:prepublish": "npm run ci",
28+
"ci": "npm run test && npm run lint && npm run format:check",
29+
"test": "vitest run",
30+
"lint": "oxlint --deny-warnings src/ tests/",
31+
"lint:fix": "oxlint --deny-warnings src/ tests/ --fix",
32+
"format": "oxfmt --write .",
33+
"format:check": "oxfmt --check .",
34+
"package": "npx @vscode/vsce package --no-dependencies",
35+
"prepare": "husky"
36+
},
37+
"devDependencies": {
38+
"husky": "latest",
39+
"lint-staged": "latest",
40+
"oxfmt": "^0.42.0",
41+
"oxlint": "^1.57.0",
42+
"vitest": "latest"
43+
},
44+
"lint-staged": {
45+
"*.{js,html,css,md,yml,yaml,json}": [
46+
"oxfmt --write"
47+
],
48+
"*.js": [
49+
"oxlint --deny-warnings"
50+
]
51+
},
3352
"contributes": {
3453
"commands": [
3554
{
@@ -77,26 +96,11 @@
7796
}
7897
}
7998
},
80-
"scripts": {
81-
"vscode:prepublish": "npm run ci",
82-
"ci": "npm run test && npm run lint && npm run format:check",
83-
"test": "vitest run",
84-
"lint": "oxlint --deny-warnings src/ tests/",
85-
"lint:fix": "oxlint --deny-warnings src/ tests/ --fix",
86-
"format": "oxfmt --write .",
87-
"format:check": "oxfmt --check .",
88-
"package": "npx @vscode/vsce package --no-dependencies",
89-
"prepare": "husky"
90-
},
91-
"devDependencies": {
92-
"husky": "latest",
93-
"lint-staged": "latest",
94-
"oxfmt": "^0.42.0",
95-
"oxlint": "^1.57.0",
96-
"vitest": "latest"
97-
},
98-
"lint-staged": {
99-
"*.{js,html,css,md,yml,yaml,json}": ["oxfmt --write"],
100-
"*.js": ["oxlint --deny-warnings"]
99+
"activationEvents": [
100+
"onStartupFinished"
101+
],
102+
"icon": "images/icon.png",
103+
"engines": {
104+
"vscode": "^1.85.0"
101105
}
102106
}

src/api.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// @ts-nocheck
2-
'use strict';
2+
"use strict";
33

4-
const { version } = require('../package.json');
4+
const { version } = require("../package.json");
55

66
const PLAN_MAP = {
7-
free: 'Free',
8-
individual: 'Pro',
9-
individual_pro: 'Pro+',
10-
business: 'Business',
11-
enterprise: 'Enterprise',
7+
free: "Free",
8+
individual: "Pro",
9+
individual_pro: "Pro+",
10+
business: "Business",
11+
enterprise: "Enterprise",
1212
};
1313

1414
/**
@@ -34,43 +34,46 @@ async function fetchUsage(token) {
3434
const timeout = setTimeout(() => controller.abort(), 15_000);
3535
let res;
3636
try {
37-
res = await fetch('https://api.github.com/copilot_internal/user', {
37+
res = await fetch("https://api.github.com/copilot_internal/user", {
3838
signal: controller.signal,
3939
headers: {
4040
Authorization: `Bearer ${token}`,
41-
Accept: 'application/json',
42-
'User-Agent': `vscode-github-copilot-usage/${version}`,
41+
Accept: "application/json",
42+
"User-Agent": `vscode-github-copilot-usage/${version}`,
4343
},
4444
});
4545
} catch (e) {
4646
clearTimeout(timeout);
47-
const isTimeout = e?.name === 'AbortError';
48-
throw makeError(isTimeout ? 'TIMEOUT' : 'NETWORK_ERROR', isTimeout ? 'Request timed out' : 'Network error');
47+
const isTimeout = e?.name === "AbortError";
48+
throw makeError(
49+
isTimeout ? "TIMEOUT" : "NETWORK_ERROR",
50+
isTimeout ? "Request timed out" : "Network error",
51+
);
4952
}
5053
clearTimeout(timeout);
5154

5255
if (res.status === 401) {
53-
throw makeError('AUTH', 'Not signed in (401)');
56+
throw makeError("AUTH", "Not signed in (401)");
5457
}
5558
if (res.status === 403) {
56-
throw makeError('FORBIDDEN', `Forbidden (403)`);
59+
throw makeError("FORBIDDEN", `Forbidden (403)`);
5760
}
5861

5962
if (res.status === 429) {
60-
throw makeError('RATE_LIMIT', 'Rate limited');
63+
throw makeError("RATE_LIMIT", "Rate limited");
6164
}
6265

6366
if (!res.ok) {
64-
throw makeError(res.status >= 500 ? 'SERVER_ERROR' : 'API_ERROR', `API error: ${res.status}`);
67+
throw makeError(res.status >= 500 ? "SERVER_ERROR" : "API_ERROR", `API error: ${res.status}`);
6568
}
6669

6770
let data;
6871
try {
6972
data = await res.json();
7073
} catch {
71-
throw makeError('API_ERROR', 'Invalid JSON from GitHub API');
74+
throw makeError("API_ERROR", "Invalid JSON from GitHub API");
7275
}
73-
const plan = PLAN_MAP[data.copilot_plan] ?? data.copilot_plan ?? 'Unknown';
76+
const plan = PLAN_MAP[data.copilot_plan] ?? data.copilot_plan ?? "Unknown";
7477

7578
const pi = data?.quota_snapshots?.premium_interactions;
7679
if (!pi || pi.percent_remaining == null) {
@@ -91,13 +94,15 @@ async function fetchUsage(token) {
9194
const entitlement = pi.entitlement ?? 0;
9295
const percentRemaining = Number(pi.percent_remaining);
9396
if (!Number.isFinite(percentRemaining)) {
94-
throw makeError('API_ERROR', 'Invalid percent_remaining from GitHub API');
97+
throw makeError("API_ERROR", "Invalid percent_remaining from GitHub API");
9598
}
9699
const usedPct = Math.max(0, Math.round((100 - percentRemaining) * 10) / 10);
97-
const used = entitlement > 0 ? Math.max(0, Math.round((entitlement * (100 - percentRemaining)) / 100)) : 0;
100+
const used =
101+
entitlement > 0 ? Math.max(0, Math.round((entitlement * (100 - percentRemaining)) / 100)) : 0;
98102

99103
const rawResetDate = data.quota_reset_date ? new Date(data.quota_reset_date) : null;
100-
const resetDate = rawResetDate && !isNaN(rawResetDate.getTime()) ? rawResetDate : getNextMonthReset();
104+
const resetDate =
105+
rawResetDate && !isNaN(rawResetDate.getTime()) ? rawResetDate : getNextMonthReset();
101106

102107
return {
103108
used,

0 commit comments

Comments
 (0)