Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DSDK-196][FEAT][OTHR] Add prettier configuration #20

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ jobs:
- name: Lint
run: pnpm lint

prettier:
runs-on: [device-sdk-4xlarge-linux]
valpinkman marked this conversation as resolved.
Show resolved Hide resolved
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v3

- uses: ./actions/setup-toolchain-composite

- name: Prettier
run: pnpm prettier

test:
runs-on: [device-sdk-4xlarge-linux]
env:
Expand Down
3 changes: 3 additions & 0 deletions apps/sample/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@ledgerhq/prettier-config-dsdk"),
};
5 changes: 4 additions & 1 deletion apps/sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint --max-warnings=0",
"lint:fix": "next lint --fix"
"lint:fix": "next lint --fix",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write"
},
"dependencies": {
"@ledgerhq/device-sdk-core": "workspace:*",
Expand All @@ -19,6 +21,7 @@
},
"devDependencies": {
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@types/react": "^18",
"@types/styled-components": "^5.1.25",
Expand Down
2 changes: 1 addition & 1 deletion apps/sample/src/providers/DeviceSdkProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useContext } from "react";
import { DeviceSdk,DeviceSdkBuilder } from "@ledgerhq/device-sdk-core";
import { DeviceSdk, DeviceSdkBuilder } from "@ledgerhq/device-sdk-core";

export const sdk = new DeviceSdkBuilder().build();

Expand Down
14 changes: 3 additions & 11 deletions apps/sample/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@
}
],
"paths": {
"@/*": [
"./src/*"
]
"@/*": ["./src/*"]
},
"strictNullChecks": true
},
"include": [
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"dev": "turbo dev --log-order=grouped",
"lint": "turbo run lint --log-order=grouped",
"lint:fix": "turbo run lint:fix --log-order=grouped",
"prettier": "turbo run prettier --log-order=grouped",
"prettier:fix": "turbo run prettier:fix --log-order=grouped",
"test": "turbo run test --log-order=grouped",
"core": "pnpm --filter @ledgerhq/device-sdk-core",
"signer": "pnpm --filter @ledgerhq/device-sdk-signer",
Expand Down
6 changes: 6 additions & 0 deletions packages/config/prettier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('prettier').Config} **/
module.exports = {
tabWidth: 2,
semi: true,
singleQuote: false,
};
12 changes: 12 additions & 0 deletions packages/config/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@ledgerhq/prettier-config-dsdk",
"license": "MIT",
"version": "0.0.1",
"private": true,
"files": [
"index.js"
],
"devDependencies": {
"prettier": "^3.1.1"
}
}
1 change: 1 addition & 0 deletions packages/core/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/*
3 changes: 3 additions & 0 deletions packages/core/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@ledgerhq/prettier-config-dsdk"),
};
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"dev": "tsc && (concurrently \"tsc -w -p tsconfig.prod.json\" \"tsc-alias -w -p tsconfig.prod.json\")",
"lint": "eslint --cache --ext .ts \"src\" --max-warnings=0",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write",
"test": "jest src",
"test:watch": "pnpm test -- --watch",
"test:coverage": "pnpm test -- --coverage",
Expand All @@ -27,6 +29,7 @@
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*",
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*",
"concurrently": "^8.2.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const makeContainer = ({
const container = new Container();
container.applyMiddleware(logger);
container.load(
configModuleFactory({ stub })
configModuleFactory({ stub }),
// modules go here
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("LocalConfigDataSource", () => {

it("should return an Either<never, Config>", () => {
readFileSyncSpy.mockReturnValue(
JSON.stringify({ name: "DeviceSDK", version: "0.0.0-spied.1" })
JSON.stringify({ name: "DeviceSDK", version: "0.0.0-spied.1" }),
);

jsonParse.mockReturnValue({
Expand All @@ -38,7 +38,7 @@ describe("LocalConfigDataSource", () => {
Either.of({
name: "DeviceSDK",
version: "0.0.0-spied.1",
})
}),
);
});

Expand All @@ -54,7 +54,7 @@ describe("LocalConfigDataSource", () => {
it("should return an Either<JSONParseError, never> if JSON.parse throws", () => {
const err = new Error("JSON.parse error");
readFileSyncSpy.mockReturnValue(
JSON.stringify({ name: "DeviceSDK", version: "0.0.0-spied.1" })
JSON.stringify({ name: "DeviceSDK", version: "0.0.0-spied.1" }),
);

jsonParse.mockImplementation(() => {
Expand All @@ -71,7 +71,7 @@ describe("LocalConfigDataSource", () => {
JSON.stringify({
name: "@ledgerhq/device-sdk-core",
version: "0.0.1",
})
}),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class FileLocalConfigDataSource implements LocalConfigDataSource {
(error) => {
console.log("JSON.parse error");
return new JSONParseError(error);
}
},
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class StubRemoteConfigDataSource implements RemoteConfigDataSource {
Either.of({
name: "DeviceSDK",
version: "0.0.0-fake.2",
})
)
}),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ let datasource: RemoteConfigDataSource;
/* eslint-disable @typescript-eslint/no-explicit-any */
const callApiSpy = jest.spyOn(
RestRemoteConfigDataSource.prototype as any,
"_callApi"
"_callApi",
);
const parseResponseSpy = jest.spyOn(
RestRemoteConfigDataSource.prototype as any,
"_parseResponse"
"_parseResponse",
);
/* eslint-enable @typescript-eslint/no-explicit-any */

Expand All @@ -37,23 +37,23 @@ describe("RemoteRestConfigDataSource", () => {
ok: true,
json: () =>
Promise.resolve(
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" })
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" }),
),
})
}),
);

parseResponseSpy.mockReturnValue(
Either.of({
name: "DeviceSDK",
version: "0.0.0-fake.1",
})
}),
);

expect(await datasource.getConfig()).toStrictEqual(
Either.of({
name: "DeviceSDK",
version: "0.0.0-fake.1",
})
}),
);
});

Expand All @@ -62,7 +62,7 @@ describe("RemoteRestConfigDataSource", () => {
callApiSpy.mockResolvedValue(Left(err));

expect(await datasource.getConfig()).toStrictEqual(
Left(new ApiCallError(err))
Left(new ApiCallError(err)),
);
});

Expand All @@ -72,13 +72,13 @@ describe("RemoteRestConfigDataSource", () => {
ok: false,
json: () =>
Promise.resolve(
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" })
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" }),
),
})
}),
);

expect(await datasource.getConfig()).toStrictEqual(
Left(new ApiCallError(new Error("response not ok")))
Left(new ApiCallError(new Error("response not ok"))),
);
});

Expand All @@ -88,11 +88,11 @@ describe("RemoteRestConfigDataSource", () => {
Either.of({
ok: true,
json: () => Promise.resolve(Left(err)),
})
}),
);

expect(await datasource.getConfig()).toStrictEqual(
Left(new JSONParseError())
Left(new JSONParseError()),
);
});

Expand All @@ -102,17 +102,17 @@ describe("RemoteRestConfigDataSource", () => {
ok: true,
json: () =>
Promise.resolve(
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" })
Either.of({ name: "DeviceSDK", version: "0.0.0-fake.1" }),
),
})
}),
);

parseResponseSpy.mockImplementation(() => {
return Left(new ParseResponseError());
});

expect(await datasource.getConfig()).toStrictEqual(
Left(new ParseResponseError())
Left(new ParseResponseError()),
);
});

Expand All @@ -126,13 +126,13 @@ describe("RemoteRestConfigDataSource", () => {
Either.of({
version: "0.0.0-fake.1",
yolo: "yolo",
})
}),
),
})
}),
);

expect(await datasource.getConfig()).toStrictEqual(
Left(new ParseResponseError())
Left(new ParseResponseError()),
);
});

Expand All @@ -147,7 +147,7 @@ describe("RemoteRestConfigDataSource", () => {
Either.of({
name: "DeviceSDK",
version: "0.0.0-fake.1",
})
}),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class RestRemoteConfigDataSource implements RemoteConfigDataSource {
name: "DeviceSDK",
version: "0.0.0-fake.1",
yolo: "yolo",
})
}),
);
}),
})
}),
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("DefaultConfigService", () => {
Either.of({
name: "DeviceSDK",
version: "1.0.0-local",
})
}),
);

expect(await service.getSdkConfig()).toStrictEqual({
Expand All @@ -45,7 +45,7 @@ describe("DefaultConfigService", () => {
Either.of({
name: "DeviceSDK",
version: "1.0.0-remote",
})
}),
);

expect(await service.getSdkConfig()).toStrictEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DefaultConfigService implements ConfigService {
private _remote: RemoteConfigDataSource;
constructor(
@inject(types.LocalConfigDataSource) local: LocalConfigDataSource,
@inject(types.RemoteConfigDataSource) remote: RemoteConfigDataSource
@inject(types.RemoteConfigDataSource) remote: RemoteConfigDataSource,
) {
this._local = local;
this._remote = remote;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"baseUrl": ".",
"paths": {
"@internal/*": ["src/internal/*"],
"@root/*": ["./*"],
"@root/*": ["./*"]
}
},
"include": ["src", "index.ts", "jest.*.ts"]
Expand Down
3 changes: 3 additions & 0 deletions packages/signer/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@ledgerhq/prettier-config-dsdk"),
};
5 changes: 4 additions & 1 deletion packages/signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"dev": "tsc --watch",
"lint": "eslint --cache --ext .ts \"src\" --max-warnings=0",
"lint:fix": "eslint --cache --fix --ext .ts \"src\"",
"prettier": "prettier . --check",
"prettier:fix": "prettier . --write",
"test": "jest --passWithNoTests"
},
"dependencies": {
Expand All @@ -21,6 +23,7 @@
"devDependencies": {
"@ledgerhq/tsconfig-dsdk": "workspace:*",
"@ledgerhq/eslint-config-dsdk": "workspace:*",
"@ledgerhq/jest-config-dsdk": "workspace:*"
"@ledgerhq/jest-config-dsdk": "workspace:*",
"@ledgerhq/prettier-config-dsdk": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/signer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"outDir": "./lib"
},
"include": ["src/**/*", "jest.config.ts"],
"include": ["src/**/*", "jest.config.ts"]
}
3 changes: 3 additions & 0 deletions packages/trusted-apps/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@ledgerhq/prettier-config-dsdk"),
};
Loading
Loading