Skip to content

Commit 6fcbc0c

Browse files
authored
chore: introduce prettier (#27)
1 parent 6abeec5 commit 6fcbc0c

40 files changed

+745
-439
lines changed

Diff for: .eslintrc.cjs

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@ module.exports = {
44
extends: [
55
'eslint:recommended',
66
'plugin:@typescript-eslint/recommended',
7-
'plugin:import/typescript'
7+
'plugin:import/typescript',
8+
'plugin:prettier/recommended',
89
],
910
parser: '@typescript-eslint/parser',
1011
plugins: ['@typescript-eslint'],
1112
rules: {
12-
indent: ['error', 2],
1313
'no-multiple-empty-lines': 'error',
14-
quotes: ['error', 'single', { 'allowTemplateLiterals': true }],
14+
quotes: ['error', 'single', { allowTemplateLiterals: true }],
1515
semi: 'off',
1616
'@typescript-eslint/semi': ['error', 'never'],
1717
'@typescript-eslint/member-delimiter-style': [
1818
'error',
1919
{
20-
'multiline': {
21-
'delimiter': 'none',
22-
'requireLast': true
20+
multiline: {
21+
delimiter: 'none',
22+
requireLast: true,
2323
},
24-
'singleline': {
25-
'delimiter': 'semi',
26-
'requireLast': false
24+
singleline: {
25+
delimiter: 'semi',
26+
requireLast: false,
2727
},
28-
'multilineDetection': 'brackets'
29-
}
28+
multilineDetection: 'brackets',
29+
},
3030
],
3131
'@typescript-eslint/no-unused-vars': [
3232
'warn',
3333
{
34-
'argsIgnorePattern': '^_',
35-
'varsIgnorePattern': '^_',
36-
'caughtErrorsIgnorePattern': '^_',
37-
'destructuredArrayIgnorePattern': '^_'
38-
}
39-
]
40-
}
34+
argsIgnorePattern: '^_',
35+
varsIgnorePattern: '^_',
36+
caughtErrorsIgnorePattern: '^_',
37+
destructuredArrayIgnorePattern: '^_',
38+
},
39+
],
40+
},
4141
}

Diff for: .prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030
"@typescript-eslint/parser": "5.54.0",
3131
"cross-fetch": "3.1.5",
3232
"eslint": "8.35.0",
33+
"eslint-config-prettier": "^8.7.0",
3334
"eslint-plugin-import": "2.27.5",
35+
"eslint-plugin-prettier": "^4.2.1",
3436
"happy-dom": "8.9.0",
3537
"msw": "1.1.0",
38+
"prettier": "^2.8.4",
3639
"typescript": "4.9.5",
3740
"vite": "4.1.4",
3841
"vitest": "0.29.2"

Diff for: pnpm-lock.yaml

+49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/BKTConfig.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export const defineBKTConfig = (config: RawBKTConfig): BKTConfig => {
4444

4545
if (!result.apiKey) throw new Error('apiKey is required')
4646
if (!result.apiEndpoint) throw new Error('apiEndpoint is required')
47-
if (!isValidUrl(result.apiEndpoint))
48-
throw new Error('apiEndpoint is invalid')
47+
if (!isValidUrl(result.apiEndpoint)) throw new Error('apiEndpoint is invalid')
4948
if (!result.featureTag) throw new Error('featureTag is required')
5049
if (!result.appVersion) throw new Error('appVersion is required')
5150

Diff for: src/BKTEvaluation.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ export interface BKTEvaluation {
55
readonly userId: string
66
readonly variationId: string
77
readonly variationValue: string
8-
readonly reason: 'TARGET' | 'RULE' | 'DEFAULT' | 'CLIENT' | 'OFF_VARIATION' | 'PREREQUISITE'
8+
readonly reason:
9+
| 'TARGET'
10+
| 'RULE'
11+
| 'DEFAULT'
12+
| 'CLIENT'
13+
| 'OFF_VARIATION'
14+
| 'PREREQUISITE'
915
}

Diff for: src/BKTExceptions.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ErrorMetricsEventType, MetricsEventType } from './internal/model/MetricsEventData'
1+
import {
2+
ErrorMetricsEventType,
3+
MetricsEventType,
4+
} from './internal/model/MetricsEventData'
25

36
abstract class BKTBaseException extends Error {
47
type?: ErrorMetricsEventType = undefined
@@ -39,7 +42,6 @@ export class ServiceUnavailableException extends BKTBaseException {
3942
type?: ErrorMetricsEventType = MetricsEventType.ServiceUnavailableError
4043
}
4144

42-
4345
// network errors
4446
export class TimeoutException extends BKTBaseException {
4547
type?: ErrorMetricsEventType = MetricsEventType.TimeoutError
@@ -55,4 +57,16 @@ export class IllegalStateException extends BKTBaseException {}
5557
// unknown errors
5658
export class UnknownException extends BKTBaseException {}
5759

58-
export type BKTException = BadRequestException | UnauthorizedException | ForbiddenException | NotFoundException | ClientClosedRequestException | InternalServerErrorException | ServiceUnavailableException | TimeoutException | NetworkException | IllegalArgumentException | IllegalStateException | UnknownException
60+
export type BKTException =
61+
| BadRequestException
62+
| UnauthorizedException
63+
| ForbiddenException
64+
| NotFoundException
65+
| ClientClosedRequestException
66+
| InternalServerErrorException
67+
| ServiceUnavailableException
68+
| TimeoutException
69+
| NetworkException
70+
| IllegalArgumentException
71+
| IllegalStateException
72+
| UnknownException

Diff for: src/BKTUser.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export interface BKTUser extends RawBKTUser {
88
readonly attributes: Record<string, string>
99
}
1010

11-
1211
export const defineBKTUser = (user: RawBKTUser): BKTUser => {
1312
if (!user.id) {
1413
throw new Error('user id is required')
@@ -17,7 +16,7 @@ export const defineBKTUser = (user: RawBKTUser): BKTUser => {
1716
return {
1817
id: user.id,
1918
attributes: {
20-
...user.customAttributes
21-
}
19+
...user.customAttributes,
20+
},
2221
}
2322
}

Diff for: src/internal/IdGenerator.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export interface IdGenerator {
32
newId(): string
43
}

Diff for: src/internal/UserHolder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export class UserHolder {
55
private user: User
66
userId: string
77

8-
constructor(
9-
user: User,
10-
) {
8+
constructor(user: User) {
119
this.user = user
1210
this.userId = this.user.id
1311
}
@@ -16,7 +14,9 @@ export class UserHolder {
1614
return this.user
1715
}
1816

19-
updateAttributes(updater: (previous: Record<string, string>) => Record<string, string>): void {
17+
updateAttributes(
18+
updater: (previous: Record<string, string>) => Record<string, string>,
19+
): void {
2020
this.user = {
2121
...this.user,
2222
data: updater(this.user.data ?? {}),

Diff for: src/internal/di/Component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class DefaultComponent implements Component {
3333
this._evaluationInteractor = this.interactorModule.evaluationInteractor(
3434
this.dataModule.apiClient(),
3535
this.dataModule.evaluationStorage(),
36-
this.dataModule.idGenerator()
36+
this.dataModule.idGenerator(),
3737
)
3838
}
3939
return this._evaluationInteractor

Diff for: src/internal/di/DataModule.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { BKTConfig } from '../../BKTConfig'
22
import { Clock, DefaultClock } from '../Clock'
3-
import { EvaluationStorage, EvaluationStorageImpl } from '../evaluation/EvaluationStorage'
3+
import {
4+
EvaluationStorage,
5+
EvaluationStorageImpl,
6+
} from '../evaluation/EvaluationStorage'
47
import { EventStorage, EventStorageImpl } from '../event/EventStorage'
58
import { DefaultIdGenerator, IdGenerator } from '../IdGenerator'
69
import { User } from '../model/User'
@@ -17,10 +20,7 @@ export class DataModule {
1720
private _evaluationStorage?: EvaluationStorage
1821
private _eventStorage?: EventStorage
1922

20-
constructor(
21-
user: User,
22-
config: BKTConfig,
23-
) {
23+
constructor(user: User, config: BKTConfig) {
2424
this._config = config
2525
this._userHolder = new UserHolder(user)
2626
}
@@ -64,7 +64,7 @@ export class DataModule {
6464
if (!this._evaluationStorage) {
6565
this._evaluationStorage = new EvaluationStorageImpl(
6666
this.userHolder().userId,
67-
new DefaultStorage(`${this.config().storageKeyPrefix}_bkt_evaluations`)
67+
new DefaultStorage(`${this.config().storageKeyPrefix}_bkt_evaluations`),
6868
)
6969
}
7070
return this._evaluationStorage
@@ -74,7 +74,7 @@ export class DataModule {
7474
if (!this._eventStorage) {
7575
this._eventStorage = new EventStorageImpl(
7676
this.userHolder().userId,
77-
new DefaultStorage(`${this.config().storageKeyPrefix}_bkt_events`)
77+
new DefaultStorage(`${this.config().storageKeyPrefix}_bkt_events`),
7878
)
7979
}
8080
return this._eventStorage

Diff for: src/internal/di/InteractorModule.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ export class InteractorModule {
1212
evaluationStorage: EvaluationStorage,
1313
idGenerator: IdGenerator,
1414
): EvaluationInteractor {
15-
return new EvaluationInteractor(
16-
apiClient,
17-
evaluationStorage,
18-
idGenerator,
19-
)
15+
return new EvaluationInteractor(apiClient, evaluationStorage, idGenerator)
2016
}
2117

2218
eventInteractor(

Diff for: src/internal/evaluation/EvaluationInteractor.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ export class EvaluationInteractor {
1010
private apiClient: ApiClient,
1111
private evaluationStorage: EvaluationStorage,
1212
private idGenerator: IdGenerator,
13-
) { }
13+
) {}
1414

1515
// visible for testing. should only be accessed from test code
1616
updateListeners: Record<string, () => void> = {}
1717

18-
async fetch(user: User, timeoutMillis?: number): Promise<GetEvaluationsResult> {
19-
const currentEvaluationsId = this.evaluationStorage.getCurrentEvaluationsId() ?? ''
18+
async fetch(
19+
user: User,
20+
timeoutMillis?: number,
21+
): Promise<GetEvaluationsResult> {
22+
const currentEvaluationsId =
23+
this.evaluationStorage.getCurrentEvaluationsId() ?? ''
2024

21-
const result = await this.apiClient.getEvaluations(user, currentEvaluationsId, timeoutMillis)
25+
const result = await this.apiClient.getEvaluations(
26+
user,
27+
currentEvaluationsId,
28+
timeoutMillis,
29+
)
2230

2331
if (result.type === 'success') {
2432
const response = result.value
@@ -31,10 +39,10 @@ export class EvaluationInteractor {
3139

3240
this.evaluationStorage.deleteAllAndInsert(
3341
response.userEvaluationsId,
34-
response.evaluations.evaluations ?? []
42+
response.evaluations.evaluations ?? [],
3543
)
3644

37-
Object.values(this.updateListeners).forEach(listener => listener())
45+
Object.values(this.updateListeners).forEach((listener) => listener())
3846
}
3947

4048
return result

0 commit comments

Comments
 (0)