Skip to content

Commit f3c80c8

Browse files
committed
feat: add biome for linting and formatting
Add Biome.js as a dev dependency for improved code quality and consistency Add lint and format scripts to package.json Add biome.json configuration file Update CI workflow to include Biome checks Update various files to fix formatting issues
1 parent 9125411 commit f3c80c8

16 files changed

Lines changed: 366 additions & 71 deletions

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ jobs:
2626
- name: Install dependencies
2727
run: npm ci
2828

29+
- name: Run Biome lint
30+
run: npm run lint
31+
32+
- name: Run Biome format check
33+
run: npm run format
34+
2935
- name: Run type check
3036
run: npm run type-check
3137

.releaserc.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
[
2626
"@semantic-release/git",
2727
{
28-
"assets": [
29-
"CHANGELOG.md",
30-
"package.json",
31-
"package-lock.json",
32-
"jsr.json"
33-
],
28+
"assets": ["CHANGELOG.md", "package.json", "package-lock.json", "jsr.json"],
3429
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
3530
}
3631
],
@@ -66,4 +61,4 @@
6661
}
6762
]
6863
]
69-
}
64+
}

api/telegram-badge.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as crypto from 'crypto';
1+
import * as crypto from 'node:crypto';
22
import { VercelRequest, VercelResponse } from '@vercel/node';
33
import { generateBadgeSVG } from './badge-generator';
44

@@ -69,8 +69,6 @@ const getMemberCount = async (token: string, channelId: string): Promise<number>
6969
}
7070
});
7171

72-
clearTimeout(timeoutId);
73-
7472
if (!response.ok) {
7573
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
7674
}
@@ -90,6 +88,8 @@ const getMemberCount = async (token: string, channelId: string): Promise<number>
9088
}
9189
logger.error('Error fetching member count', error);
9290
throw error;
91+
} finally {
92+
clearTimeout(timeoutId);
9393
}
9494
};
9595

biome.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"includes": ["src/**", "tests/**", "*.ts", "*.js", "*.json"],
11+
"experimentalScannerIgnores": [
12+
"node_modules/**",
13+
"dist/**",
14+
"build/**",
15+
"coverage/**",
16+
"*.min.js",
17+
"public/**",
18+
"CHANGELOG.md"
19+
]
20+
},
21+
"formatter": {
22+
"enabled": true,
23+
"formatWithErrors": false,
24+
"indentStyle": "space",
25+
"indentWidth": 2,
26+
"lineEnding": "lf",
27+
"lineWidth": 100
28+
},
29+
"linter": {
30+
"enabled": true,
31+
"rules": {
32+
"recommended": true,
33+
"suspicious": {
34+
"noExplicitAny": "warn"
35+
}
36+
}
37+
},
38+
"javascript": {
39+
"formatter": {
40+
"jsxQuoteStyle": "double",
41+
"quoteProperties": "asNeeded",
42+
"trailingCommas": "es5",
43+
"semicolons": "always",
44+
"arrowParentheses": "always",
45+
"bracketSpacing": true,
46+
"bracketSameLine": false,
47+
"quoteStyle": "single"
48+
}
49+
}
50+
}

bun.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deno.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ module.exports = {
22
preset: 'ts-jest/presets/default',
33
testEnvironment: 'node',
44
roots: ['<rootDir>/tests'],
5-
testMatch: [
6-
'**/__tests__/**/*.+(ts|tsx)',
7-
'**/*.(test|spec).+(ts|tsx)'
8-
],
5+
testMatch: ['**/__tests__/**/*.+(ts|tsx)', '**/*.(test|spec).+(ts|tsx)'],
96
transform: {
107
'^.+\\.(ts|tsx)$': 'ts-jest',
118
},
129
moduleNameMapper: {
13-
'^badge-maker$': '<rootDir>/tests/__mocks__/badge-maker.js'
10+
'^badge-maker$': '<rootDir>/tests/__mocks__/badge-maker.js',
1411
},
1512
setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
1613
coverageDirectory: 'coverage',
17-
collectCoverageFrom: [
18-
'api/**/*.{ts}',
19-
'!api/**/*.d.ts',
20-
],
21-
};
14+
collectCoverageFrom: ['api/**/*.{ts}', '!api/**/*.d.ts'],
15+
};

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"version": "1.4.1",
44
"license": "MIT",
55
"exports": "./mod.ts"
6-
}
6+
}

mod.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { generateBadgeSVG } from './api/badge-generator.ts';
77

8-
export { generateBadgeSVG, type BadgeFormat } from './api/badge-generator.ts';
8+
export { type BadgeFormat, generateBadgeSVG } from './api/badge-generator.ts';
99

1010
// Re-export types
1111
export type {
1212
BadgeOptions,
13-
TelegramApiResponse,
13+
Environment,
1414
Logger,
1515
RequestQuery,
16-
Environment
16+
TelegramApiResponse,
1717
} from './types/index.ts';
1818

1919
/**
@@ -37,7 +37,7 @@ export function createTelegramBadge(
3737
label = 'Telegram',
3838
color = '#0088cc',
3939
labelColor = '#555',
40-
logo = true
40+
logo = true,
4141
} = options;
4242

4343
return generateBadgeSVG({
@@ -46,7 +46,7 @@ export function createTelegramBadge(
4646
color,
4747
labelColor,
4848
style,
49-
logo: logo
49+
logo: logo,
5050
});
5151
}
5252

@@ -59,13 +59,13 @@ export function validateChannelId(channelId: string): string {
5959
if (!channelId) {
6060
throw new Error('Channel ID is required');
6161
}
62-
62+
6363
// Remove @ if present and validate format
6464
const normalized = channelId.startsWith('@') ? channelId.slice(1) : channelId;
65-
65+
6666
if (!/^[a-zA-Z0-9_]{5,32}$/.test(normalized)) {
6767
throw new Error('Invalid channel ID format');
6868
}
69-
69+
7070
return `@${normalized}`;
71-
}
71+
}

0 commit comments

Comments
 (0)