Skip to content

Commit

Permalink
replace eslint with biome (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
Co-authored-by: Mirko Mollik <[email protected]>
Co-authored-by: Lukas.J.Han <[email protected]>
  • Loading branch information
3 people authored Feb 22, 2024
1 parent 9652e75 commit cc9923b
Show file tree
Hide file tree
Showing 20 changed files with 251 additions and 1,418 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.json

This file was deleted.

44 changes: 22 additions & 22 deletions .github/workflows/build-test-publish-on-push-cached.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,28 @@ jobs:
with:
fail_ci_if_error: true

# lint:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - uses: pnpm/action-setup@v3
# with:
# version: 8
# - run: pnpm add -g pnpm
# - name: 'Restore build output'
# uses: actions/cache/restore@v4
# with:
# path: ${{ github.workspace }}
# key: ${{ runner.os }}-build-${{ github.sha }}-${{ github.run_id }}
# restore-keys: ${{ runner.os }}-build-${{ github.sha }}
# fail-on-cache-miss: true
# - name: 'Setup Node.js with pnpm cache'
# uses: actions/setup-node@v4
# with:
# node-version: 20
# cache: 'pnpm'
# - name: 'Run lint'
# run: pnpm run lint
lint:
needs: build
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v3
with:
version: 8
- run: pnpm add -g pnpm
- name: 'Restore build output'
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}
key: ${{ runner.os }}-build-${{ github.sha }}-${{ github.run_id }}
restore-keys: ${{ runner.os }}-build-${{ github.sha }}
fail-on-cache-miss: true
- name: 'Setup Node.js with pnpm cache'
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: 'Run lint'
run: pnpm run lint

# Only run this job when the push is on main, next or unstable
publish:
Expand Down
29 changes: 29 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignore": ["**/dist/**", "**/coverage/**"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"lineEnding": "lf"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
}
}
}
}
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "sd-jwt draft 7 implementation in typescript",
"scripts": {
"build": "lerna run build --stream",
"lint": "lerna run lint --stream",
"lint": "biome lint ./packages",
"test": "vitest run --coverage",
"clean": "lerna clean -y",
"publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest",
"publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes",
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes"
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes",
"biome": "biome"
},
"keywords": [
"sd-jwt",
Expand All @@ -27,6 +28,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@types/node": "^20.10.2",
"@vitest/coverage-v8": "^1.2.2",
"jsdom": "^24.0.0",
Expand All @@ -36,13 +38,5 @@
"typescript": "^5.3.2",
"vite": "^5.1.1",
"vitest": "^1.2.2"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^6.4.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/broswer-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:browser && pnpm run test:cov",
"test:browser": "vitest run ./src/test/*.spec.ts",
"test:cov": "vitest run --coverage"
Expand Down
4 changes: 2 additions & 2 deletions packages/broswer-crypto/src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const generateSalt = (length: number): string => {

export async function digest(
data: string,
algorithm: string = 'SHA-256',
algorithm = 'SHA-256',
): Promise<Uint8Array> {
const { subtle } = globalThis.crypto;
const ec = new TextEncoder();
const digest = await subtle.digest(algorithm, ec.encode(data));
return new Uint8Array(digest);
}

export const getHasher = (algorithm: string = 'SHA-256') => {
export const getHasher = (algorithm = 'SHA-256') => {
return (data: string) => digest(data, algorithm);
};
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:e2e && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts && vitest run ./src/test/*.spec.ts --environment jsdom",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class SDJwtInstance {
const missingKeys = requiredClaimKeys.filter((k) => !keys.includes(k));
if (missingKeys.length > 0) {
throw new SDJWTException(
'Missing required claim keys: ' + missingKeys.join(', '),
`Missing required claim keys: ${missingKeys.join(', ')}`,
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/sdjwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ export class SDJwt<
}
}

export const listKeys = (obj: any, prefix: string = '') => {
export const listKeys = (obj: any, prefix = '') => {
const keys: string[] = [];
for (let key in obj) {
for (const key in obj) {
if (obj[key] === undefined) continue;
const newKey = prefix ? `${prefix}.${key}` : key;
keys.push(newKey);
Expand Down Expand Up @@ -224,7 +224,7 @@ export const pack = async <T extends object>(
const sd = disclosureFrame[SD_DIGEST] ?? [];
const decoyCount = disclosureFrame[SD_DECOY] ?? 0;

if (claims instanceof Array) {
if (Array.isArray(claims)) {
const packedClaims: any[] = [];
const disclosures: any[] = [];
const recursivePackedClaims: any = {};
Expand All @@ -244,7 +244,7 @@ export const pack = async <T extends object>(
}
}

for (let i = 0; i < (claims as Array<any>).length; i++) {
for (let i = 0; i < (claims as any[]).length; i++) {
const claim = recursivePackedClaims[i]
? recursivePackedClaims[i]
: claims[i];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/test/kbjwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ describe('KB JWT', () => {
},
});

(kbJwt.payload as any)!['_sd_hash'] = 'hash';
delete (kbJwt.payload as any)!.sd_hash;
(kbJwt.payload as any)._sd_hash = 'hash';
(kbJwt.payload as any).sd_hash = undefined;

const encodedKbJwt = await kbJwt.sign(testSigner);
const decoded = KBJwt.fromKBEncode(encodedKbJwt);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/test/sdjwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ describe('SD JWT', () => {
firstname: 'John',
lastname: 'Doe',
});
expect(disclosureKeymap['firstname']).toBeDefined();
expect(typeof disclosureKeymap['firstname']).toEqual('string');
expect(disclosureKeymap.firstname).toBeDefined();
expect(typeof disclosureKeymap.firstname).toEqual('string');
});

test('pack and unpack', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/decode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts --coverage",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom --coverage"
Expand Down
12 changes: 6 additions & 6 deletions packages/decode/src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const getClaimsSync = <T>(
export const unpackArray = (
arr: Array<any>,
map: Record<string, Disclosure<any>>,
prefix: string = '',
prefix = '',
): { unpackedObj: any; disclosureKeymap: Record<string, string> } => {
const keys: Record<string, string> = {};
const unpackedArray: any[] = [];
Expand Down Expand Up @@ -192,11 +192,11 @@ export const unpackArray = (
export const unpackObj = (
obj: any,
map: Record<string, Disclosure<any>>,
prefix: string = '',
prefix = '',
): { unpackedObj: any; disclosureKeymap: Record<string, string> } => {
const keys: Record<string, string> = {};
if (obj instanceof Object) {
if (obj instanceof Array) {
if (Array.isArray(obj)) {
return unpackArray(obj, map, prefix);
}

Expand All @@ -220,9 +220,9 @@ export const unpackObj = (
const { _sd, ...payload } = obj;
const claims: any = {};
if (_sd) {
_sd.forEach((hash: string) => {
for (const hash of _sd) {
const disclosed = map[hash];
if (disclosed && disclosed.key) {
if (disclosed?.key) {
const presentKey = prefix
? `${prefix}.${disclosed.key}`
: disclosed.key;
Expand All @@ -236,7 +236,7 @@ export const unpackObj = (
claims[disclosed.key] = unpackedObj;
Object.assign(keys, disclosureKeys);
}
});
}
}

const unpackedObj = Object.assign(payload, claims);
Expand Down
2 changes: 1 addition & 1 deletion packages/hash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
Expand Down
2 changes: 1 addition & 1 deletion packages/node-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts",
"test:cov": "vitest run --coverage"
Expand Down
2 changes: 1 addition & 1 deletion packages/node-crypto/src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const generateSalt = (length: number): string => {

export const digest = (
data: string,
algorithm: string = 'SHA-256',
algorithm = 'SHA-256',
): Uint8Array => {
const nodeAlg = toNodeCryptoAlg(algorithm);
const hash = createHash(nodeAlg);
Expand Down
2 changes: 1 addition & 1 deletion packages/present/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"scripts": {
"build": "rm -rf **/dist && tsup",
"lint": "eslint src/**/*.ts",
"lint": "biome lint ./src",
"test": "pnpm run test:node && pnpm run test:browser && pnpm run test:cov",
"test:node": "vitest run ./src/test/*.spec.ts",
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
Expand Down
Loading

0 comments on commit cc9923b

Please sign in to comment.