Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-inject": "^5.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@scaleway/eslint-config-react": "^3.13.7",
"@scaleway/eslint-config-react": "^3.14.1",
"@types/jest": "^29.2.6",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"cross-env": "^7.0.3",
Expand Down
6 changes: 0 additions & 6 deletions packages/clients/src/api/baremetal/v1/api.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ export class BaremetalV1UtilsAPI extends API {
return server.install
})

if (!value) {
throw new Error(
`Server creation has not begun for server ${request.serverId}`,
)
}

return {
done: !SERVER_INSTALL_TRANSIENT_STATUSES.includes(value.status),
value,
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/src/api/instance/v1/api.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class InstanceV1UtilsAPI extends API {
method: 'PUT',
path: `/instance/v1/zones/${validatePathParam(
'zone',
imageReq.zone ?? this.client.settings.defaultZone,
imageReq.zone,
)}/images/${validatePathParam('id', imageReq.id)}`,
},
unmarshalSetImageResponse,
Expand Down
6 changes: 2 additions & 4 deletions packages/clients/src/helpers/__tests__/is-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ describe('isBrowser', () => {
})

it('returns true after defining a window', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Fake window/document for the test
// @ts-expect-error Fake window/document for the test
global.window = { document: 'not-undefined' }
expect(isBrowser()).toBe(true)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Reset the global variable
// @ts-expect-error Reset the global variable
delete global.window
})
})
2 changes: 1 addition & 1 deletion packages/clients/src/helpers/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const isJSONObject = (obj: unknown): obj is JSONObject => {
objT !== 'string' &&
objT !== 'number' &&
objT !== 'boolean' &&
Array.isArray(obj) === false &&
!Array.isArray(obj) &&
objT === 'object'
)
}
3 changes: 3 additions & 0 deletions packages/clients/src/internal/async/interval-retrier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type IntervalStrategy = Generator<number, never | number, number>
export function* createFixedIntervalStrategy(
interval: number,
): IntervalStrategy {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) yield interval
}

Expand All @@ -51,6 +52,7 @@ export function* createFibonacciIntervalStrategy(
factor = 1,
): IntervalStrategy {
let [prev, current] = [0, 1]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
yield current * base
;[prev, current] = [current, prev + current * factor]
Expand Down Expand Up @@ -79,6 +81,7 @@ export function* createExponentialBackoffStrategy(
const ceiling = Math.log(maxDelay / minDelay) / Math.log(2) + 1
const randomInRange = (min: number, max: number) =>
min + Math.random() * (max - min)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
if (attempt > ceiling) {
yield maxDelay
Expand Down
4 changes: 3 additions & 1 deletion packages/clients/src/internal/interceptors/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export const composeInterceptors =
async (instance: T): Promise<T> =>
interceptors.reduce(
async (asyncResult, interceptor) => interceptor(await asyncResult),
Promise.resolve(instance) as Promise<T>,
new Promise<T>(resolve => {
resolve(instance)
}),
)
9 changes: 3 additions & 6 deletions packages/clients/src/scw/__tests__/client-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@ const VALID_SETTINGS: Settings = {
const INVALID_SETTINGS_LIST: Partial<Settings>[] = [
{ apiURL: 'https://api.scaleway.com/' },
{ apiURL: 'ftp://api.scaleway.com' },
// @ts-ignore Unknown zone
{ defaultZone: 'fr-par-0' },
// @ts-ignore Unknown zone
{ defaultZone: 'fr-par' },
// @ts-ignore Unknown region
{ defaultRegion: 'fr-par-1' },
// @ts-ignore Unknown client type
// @ts-expect-error Unknown client type
{ httpClient: 'str-client' },
{ defaultOrganizationId: '' },
{ defaultOrganizationId: 'not-a-uuid-v4' },
{ defaultProjectId: '' },
{ defaultProjectId: 'not-a-uuid-v4' },
{ defaultPageSize: 0 },
{ defaultPageSize: -1 },
// @ts-ignore
// @ts-expect-error Wrong type
{ defaultPageSize: '42' },
// @ts-ignore Unknown user agent type
// @ts-expect-error Unknown user agent type
{ userAgent: null },
]
/* eslint-enable @typescript-eslint/ban-ts-comment */
Expand Down
6 changes: 3 additions & 3 deletions packages/clients/src/scw/client-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const assertValidSettings = (obj: Readonly<Settings>): void => {
) {
throw new Error('Default organization ID cannot be empty')
}
if (isOrganizationId(obj.defaultOrganizationId) !== true) {
if (!isOrganizationId(obj.defaultOrganizationId)) {
throw new Error(
`Invalid organization ID format '${obj.defaultOrganizationId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
)
Expand All @@ -83,7 +83,7 @@ export const assertValidSettings = (obj: Readonly<Settings>): void => {
) {
throw new Error('Default project ID cannot be empty')
}
if (isProjectId(obj.defaultProjectId) !== true) {
if (!isProjectId(obj.defaultProjectId)) {
throw new Error(
`Invalid project ID format '${obj.defaultProjectId}', expected a UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
)
Expand All @@ -105,7 +105,7 @@ export const assertValidSettings = (obj: Readonly<Settings>): void => {
throw new Error(`Invalid URL ${obj.apiURL}`)
}

if (obj.apiURL.slice(-1) === '/') {
if (obj.apiURL.endsWith('/')) {
throw new Error(
`Invalid URL ${obj.apiURL}: it should not have a trailing slash`,
)
Expand Down
4 changes: 4 additions & 0 deletions packages/clients/src/scw/errors/scw-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ export class ScalewayError extends Error {
): ScalewayError | null {
return new ScalewayError(status, obj)
}

toString(): string {
return `${this.name}: ${this.message}`
}
}
4 changes: 2 additions & 2 deletions packages/clients/src/scw/fetch/__tests__/build-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ describe(`buildRequest`, () => {

it(`has NOT the header "User-Agent" when browser is detected`, () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Fake window/document for the test
// @ts-expect-error Fake window/document for the test
global.window = { document: 'not-undefined' }
const fReq = buildRequest(SCW_POST_REQUEST, DEFAULT_SETTINGS)
expect(fReq.headers.get('User-Agent')).toBeNull()
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Reset the global variable
// @ts-expect-error Reset the global variable
delete global.window
})

Expand Down
2 changes: 1 addition & 1 deletion packages/clients/src/scw/fetch/response-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const fixLegacyTotalCount = <T>(obj: T, headers: Headers): T => {
return obj
}
const totalCount = parseInt(headerVal, 10)
if (Number.isNaN(totalCount) === true) {
if (Number.isNaN(totalCount)) {
return obj
}
if (isJSONObject(obj) && !(TOTAL_COUNT_RES_KEY in obj)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('getScwConfigurationDirectory', () => {

it(`uses the home directory if any`, () => {
const oldXDG: string | undefined = updateEnv('XDG_CONFIG_HOME', '')
expect(getScwConfigurationDirectory()?.length).toBeGreaterThan(0)
expect(getScwConfigurationDirectory().length).toBeGreaterThan(0)
setOrDeleteEnv('XDG_CONFIG_HOME', oldXDG)
})
})
Expand All @@ -42,9 +42,9 @@ describe('resolveConfigurationFilePath', () => {
})

it('is defined and not be empty', () => {
const filePath: string | null = resolveConfigurationFilePath()
const filePath: string = resolveConfigurationFilePath()
expect(filePath).not.toBeNull()
expect(filePath?.length).toBeGreaterThan(0)
expect(filePath.length).toBeGreaterThan(0)
})

it(`is the user's defined path`, () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/configuration-loader/src/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export const loadAllProfilesFromConfigurationFile = (
}
const configs = loadConfigurationFromFile(filePath)

return Object.keys(configs).reduce(
return Object.keys(configs).reduce<Record<string, Profile>>(
(prev, pKey) => ({
...prev,
[pKey]: convertFileConfigToSDK(configs[pKey]),
}),
{} as Record<string, Profile>,
{},
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/configuration-loader/src/yml-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const convertYamlToConfiguration = (
currentSection = undefined
if (newSection[1] === 'profiles') {
foundProfilesKey = true
} else if (foundProfilesKey === true) {
} else if (foundProfilesKey) {
;[, currentSection] = newSection
}
}
Expand Down
Loading