Skip to content

Commit f6016b4

Browse files
chore: eslint prefer-object-params on (#921)
# Motivation We want more restrictive eslint rules. # Changes - Toggle rule on - Adapt some internal functions - Add some exception either for functional reason, to avoid breaking change or simplity if test --------- Signed-off-by: David Dal Busco <[email protected]> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b154be4 commit f6016b4

File tree

14 files changed

+78
-51
lines changed

14 files changed

+78
-51
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export default [
1313
// This rule is more appropriate in applications where null and undefined have distinct meanings.
1414
// That is why, for now, it's disabled in this repo.
1515
"local-rules/use-option-type-wrapper": "off",
16-
"local-rules/prefer-object-params": "off",
1716
},
1817
},
1918
{

packages/cketh/src/utils/minter.utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ export const encodePrincipalToEthAddress = (principal: Principal): string => {
2020
* @param {number} b A byte.
2121
* @return {string} An updated string.
2222
*/
23-
const appendHexByte = (s: string, b: number): string => {
24-
s += ((b >> 4) & 0x0f).toString(16);
25-
s += (b & 0x0f).toString(16);
26-
return s;
23+
const appendHexByte = ({
24+
stringToAppend,
25+
bytes,
26+
}: {
27+
stringToAppend: string;
28+
bytes: number;
29+
}): string => {
30+
stringToAppend += ((bytes >> 4) & 0x0f).toString(16);
31+
stringToAppend += (bytes & 0x0f).toString(16);
32+
return stringToAppend;
2733
};
2834

2935
/**
@@ -34,9 +40,9 @@ const appendHexByte = (s: string, b: number): string => {
3440
const bytes32Encode = (bytes: Uint8Array): string => {
3541
const n = bytes.length;
3642
let s = "0x";
37-
s = appendHexByte(s, n);
43+
s = appendHexByte({ stringToAppend: s, bytes: n });
3844
for (let i = 0; i < bytes.length; i++) {
39-
s = appendHexByte(s, bytes[i]);
45+
s = appendHexByte({ stringToAppend: s, bytes: bytes[i] });
4046
}
4147
for (let i = 0; i < 31 - bytes.length; i++) {
4248
s += "00";

packages/ic-management/src/utils/transform.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type QueryTransform = Required<ActorConfig>["queryTransform"];
1717
*
1818
* @link https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-effective-canister-id
1919
**/
20+
// eslint-disable-next-line local-rules/prefer-object-params
2021
export const transform: CallTransform | QueryTransform = (
2122
methodName: string,
2223
args: (Record<string, unknown> & {

packages/ledger-icp/src/utils/account_identifier.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const accountIdentifierFromBytes = (
1818
accountIdentifier: Uint8Array,
1919
): AccountIdentifierHex => Buffer.from(accountIdentifier).toString("hex");
2020

21+
// eslint-disable-next-line local-rules/prefer-object-params
2122
export const principalToAccountIdentifier = (
2223
principal: Principal,
2324
subAccount?: Uint8Array,

packages/ledger-icrc/src/utils/ledger.utils.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ describe("ledger-utils", () => {
173173

174174
it.each(missingFieldCases)(
175175
"should return undefined for %s",
176+
// eslint-disable-next-line local-rules/prefer-object-params
176177
(_, response) => {
177178
const result = mapTokenMetadata(response);
178179
expect(result).toBeUndefined();
@@ -216,6 +217,7 @@ describe("ledger-utils", () => {
216217

217218
it.each(invalidFieldCases)(
218219
"should return undefined for %s",
220+
// eslint-disable-next-line local-rules/prefer-object-params
219221
(_, response) => {
220222
const result = mapTokenMetadata(response);
221223
expect(result).toBeUndefined();

packages/nns/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ Set visibility of a neuron
384384
| --------------- | ------------------------------------------------------------------- |
385385
| `setVisibility` | `(neuronId: bigint, visibility: NeuronVisibility) => Promise<void>` |
386386

387-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L525)
387+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L526)
388388

389389
##### :gear: setNodeProviderAccount
390390

@@ -395,7 +395,7 @@ Where the reward is paid to.
395395
| ------------------------ | ---------------------------------------------- |
396396
| `setNodeProviderAccount` | `(accountIdentifier: string) => Promise<void>` |
397397

398-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L545)
398+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L546)
399399

400400
##### :gear: mergeNeurons
401401

@@ -405,7 +405,7 @@ Merge two neurons
405405
| -------------- | --------------------------------------------------------------------------------- |
406406
| `mergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<void>` |
407407

408-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L565)
408+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L566)
409409

410410
##### :gear: simulateMergeNeurons
411411

@@ -415,7 +415,7 @@ Simulate merging two neurons
415415
| ---------------------- | --------------------------------------------------------------------------------------- |
416416
| `simulateMergeNeurons` | `(request: { sourceNeuronId: bigint; targetNeuronId: bigint; }) => Promise<NeuronInfo>` |
417417

418-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L582)
418+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L583)
419419

420420
##### :gear: splitNeuron
421421

@@ -425,7 +425,7 @@ Splits a neuron creating a new one
425425
| ------------- | ----------------------------------------------------------------------------------- |
426426
| `splitNeuron` | `({ neuronId, amount, }: { neuronId: bigint; amount: bigint; }) => Promise<bigint>` |
427427

428-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L627)
428+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L628)
429429

430430
##### :gear: getProposal
431431

@@ -438,7 +438,7 @@ it is fetched using a query call.
438438
| ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
439439
| `getProposal` | `({ proposalId, certified, }: { proposalId: bigint; certified?: boolean or undefined; }) => Promise<ProposalInfo or undefined>` |
440440

441-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L667)
441+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L668)
442442

443443
##### :gear: makeProposal
444444

@@ -448,7 +448,7 @@ Create new proposal
448448
| -------------- | ---------------------------------------------------------------- |
449449
| `makeProposal` | `(request: MakeProposalRequest) => Promise<bigint or undefined>` |
450450

451-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L685)
451+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L686)
452452

453453
##### :gear: registerVote
454454

@@ -458,7 +458,7 @@ Registers vote for a proposal from the neuron passed.
458458
| -------------- | ----------------------------------------------------------------------------------------------------------- |
459459
| `registerVote` | `({ neuronId, vote, proposalId, }: { neuronId: bigint; vote: Vote; proposalId: bigint; }) => Promise<void>` |
460460

461-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L706)
461+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L707)
462462

463463
##### :gear: setFollowees
464464

@@ -468,7 +468,7 @@ Edit neuron followees per topic
468468
| -------------- | ------------------------------------------------- |
469469
| `setFollowees` | `(followRequest: FollowRequest) => Promise<void>` |
470470

471-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L728)
471+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L729)
472472

473473
##### :gear: disburse
474474

@@ -478,7 +478,7 @@ Disburse neuron on Account
478478
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
479479
| `disburse` | `({ neuronId, toAccountId, amount, }: { neuronId: bigint; toAccountId?: string or undefined; amount?: bigint or undefined; }) => Promise<void>` |
480480

481-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L743)
481+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L744)
482482

483483
##### :gear: refreshVotingPower
484484

@@ -490,7 +490,7 @@ parameter of the neuron to the current time).
490490
| -------------------- | --------------------------------------------------------- |
491491
| `refreshVotingPower` | `({ neuronId, }: { neuronId: bigint; }) => Promise<void>` |
492492

493-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L779)
493+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L780)
494494

495495
##### :gear: mergeMaturity
496496

@@ -500,7 +500,7 @@ Merge Maturity of a neuron
500500
| --------------- | ------------------------------------------------------------------------------------------------------- |
501501
| `mergeMaturity` | `({ neuronId, percentageToMerge, }: { neuronId: bigint; percentageToMerge: number; }) => Promise<void>` |
502502

503-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L801)
503+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L802)
504504

505505
##### :gear: stakeMaturity
506506

@@ -515,7 +515,7 @@ Parameters:
515515
- `neuronId`: The id of the neuron for which to stake the maturity
516516
- `percentageToStake`: Optional. Percentage of the current maturity to stake. If not provided, all of the neuron's current maturity will be staked.
517517

518-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L830)
518+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L831)
519519

520520
##### :gear: spawnNeuron
521521

@@ -525,7 +525,7 @@ Merge Maturity of a neuron
525525
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
526526
| `spawnNeuron` | `({ neuronId, percentageToSpawn, newController, nonce, }: { neuronId: bigint; percentageToSpawn?: number or undefined; newController?: Principal or undefined; nonce?: bigint or undefined; }) => Promise<bigint>` |
527527

528-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L852)
528+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L853)
529529

530530
##### :gear: addHotkey
531531

@@ -535,7 +535,7 @@ Add hotkey to neuron
535535
| ----------- | ------------------------------------------------------------------------------------------ |
536536
| `addHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>` |
537537

538-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L899)
538+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L900)
539539

540540
##### :gear: removeHotkey
541541

@@ -545,7 +545,7 @@ Remove hotkey to neuron
545545
| -------------- | ------------------------------------------------------------------------------------------ |
546546
| `removeHotkey` | `({ neuronId, principal, }: { neuronId: bigint; principal: Principal; }) => Promise<void>` |
547547

548-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L919)
548+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L920)
549549

550550
##### :gear: claimOrRefreshNeuronFromAccount
551551

@@ -555,7 +555,7 @@ Gets the NeuronID of a newly created neuron.
555555
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
556556
| `claimOrRefreshNeuronFromAccount` | `({ memo, controller, }: { memo: bigint; controller?: Principal or undefined; }) => Promise<bigint or undefined>` |
557557

558-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L937)
558+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L938)
559559

560560
##### :gear: claimOrRefreshNeuron
561561

@@ -566,7 +566,7 @@ Uses query call only.
566566
| ---------------------- | ------------------------------------------------------------------------ |
567567
| `claimOrRefreshNeuron` | `(request: ClaimOrRefreshNeuronRequest) => Promise<bigint or undefined>` |
568568

569-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L968)
569+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L969)
570570

571571
##### :gear: getNeuron
572572

@@ -576,7 +576,7 @@ Return the data of the neuron provided as id.
576576
| ----------- | ----------------------------------------------------------------------------------------------------------- |
577577
| `getNeuron` | `({ certified, neuronId, }: { certified: boolean; neuronId: bigint; }) => Promise<NeuronInfo or undefined>` |
578578

579-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L993)
579+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L994)
580580

581581
##### :gear: getNetworkEconomicsParameters
582582

@@ -586,7 +586,7 @@ Return the [Network Economics](https://github.com/dfinity/ic/blob/d90e934eb440c7
586586
| ------------------------------- | ------------------------------------------------------------------------ |
587587
| `getNetworkEconomicsParameters` | `({ certified, }: { certified: boolean; }) => Promise<NetworkEconomics>` |
588588

589-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L1014)
589+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L1015)
590590

591591
##### :gear: disburseMaturity
592592

@@ -597,7 +597,7 @@ Reference: https://github.com/dfinity/ic/blob/ca2be53acf413bb92478ee7694ac0fb92a
597597
| ------------------ | ------------------------------------------------------------------------------------------------------------- |
598598
| `disburseMaturity` | `({ neuronId, percentageToDisburse, }: { neuronId: bigint; percentageToDisburse: number; }) => Promise<void>` |
599599

600-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L1037)
600+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/nns/src/governance.canister.ts#L1038)
601601

602602
### :factory: SnsWasmCanister
603603

packages/nns/src/governance.canister.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ export class GovernanceCanister {
522522
*
523523
* @throws {@link GovernanceError}
524524
*/
525+
// eslint-disable-next-line local-rules/prefer-object-params
525526
public setVisibility = async (
526527
neuronId: NeuronId,
527528
visibility: NeuronVisibility,

packages/utils/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,15 @@ Parameters:
232232
| -------------- | ---------------------------------------------------------------- |
233233
| `asNonNullish` | `<T>(value: T, message?: string or undefined) => NonNullable<T>` |
234234

235-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/asserts.utils.ts#L16)
235+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/asserts.utils.ts#L18)
236236

237237
#### :gear: assertPercentageNumber
238238

239239
| Function | Type |
240240
| ------------------------ | ------------------------------ |
241241
| `assertPercentageNumber` | `(percentage: number) => void` |
242242

243-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/asserts.utils.ts#L21)
243+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/asserts.utils.ts#L23)
244244

245245
#### :gear: uint8ArrayToBigInt
246246

@@ -407,7 +407,7 @@ Parameters:
407407
- `_key`: - Ignored. Only provided for API compatibility.
408408
- `value`: - The value to transform before stringification.
409409

410-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L21)
410+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L22)
411411

412412
#### :gear: jsonReviver
413413

@@ -430,7 +430,7 @@ Parameters:
430430
- `_key`: - Ignored but provided for API compatibility.
431431
- `value`: - The parsed value to transform.
432432

433-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L51)
433+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/json.utils.ts#L53)
434434

435435
#### :gear: hashObject
436436

@@ -490,7 +490,7 @@ Returns the current timestamp in nanoseconds as a `bigint`.
490490
| ------------------------ | -------------- |
491491
| `nowInBigIntNanoSeconds` | `() => bigint` |
492492

493-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L117)
493+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L123)
494494

495495
#### :gear: toBigIntNanoSeconds
496496

@@ -504,7 +504,7 @@ Parameters:
504504

505505
- `date`: - The `Date` object to convert.
506506

507-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L126)
507+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/date.utils.ts#L132)
508508

509509
#### :gear: debounce
510510

@@ -611,7 +611,7 @@ Parameters:
611611
- `params.minVersion`: Ex: "1.0.0"
612612
- `params.currentVersion`: Ex: "2.0.0"
613613

614-
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/version.utils.ts#L28)
614+
[:link: Source](https://github.com/dfinity/ic-js/tree/main/packages/utils/src/utils/version.utils.ts#L34)
615615

616616
### :wrench: Constants
617617

packages/utils/src/utils/asserts.utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export class NullishError extends Error {}
44
export const assertNonNullish: <T>(
55
value: T,
66
message?: string,
7+
// eslint-disable-next-line local-rules/prefer-object-params
78
) => asserts value is NonNullable<T> = <T>(
89
value: T,
910
message?: string,
@@ -13,6 +14,7 @@ export const assertNonNullish: <T>(
1314
}
1415
};
1516

17+
// eslint-disable-next-line local-rules/prefer-object-params
1618
export const asNonNullish = <T>(value: T, message?: string): NonNullable<T> => {
1719
assertNonNullish(value, message);
1820
return value;

packages/utils/src/utils/date.utils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("date.utils", () => {
3737
second_plural: "secondes",
3838
};
3939

40+
// eslint-disable-next-line local-rules/prefer-object-params
4041
const test = (
4142
i18nResult: I18nSecondsToDuration,
4243
i18n?: I18nSecondsToDuration,

packages/utils/src/utils/date.utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ export const secondsToDuration = ({
5959
days -= daysInYears(years);
6060

6161
const periods = [
62-
createLabel("year", years),
63-
createLabel("day", days),
64-
createLabel("hour", hours),
65-
createLabel("minute", minutes),
62+
createLabel({ labelKey: "year", amount: years }),
63+
createLabel({ labelKey: "day", amount: days }),
64+
createLabel({ labelKey: "hour", amount: hours }),
65+
createLabel({ labelKey: "minute", amount: minutes }),
6666
...(seconds > BigInt(0) && seconds < BigInt(60)
67-
? [createLabel("second", seconds)]
67+
? [createLabel({ labelKey: "second", amount: seconds })]
6868
: []),
6969
];
7070

@@ -102,7 +102,13 @@ type LabelInfo = {
102102
labelKey: LabelKey;
103103
amount: number;
104104
};
105-
const createLabel = (labelKey: LabelKey, amount: bigint): LabelInfo => ({
105+
const createLabel = ({
106+
labelKey,
107+
amount,
108+
}: {
109+
labelKey: LabelKey;
110+
amount: bigint;
111+
}): LabelInfo => ({
106112
labelKey,
107113
amount: Number(amount),
108114
});

packages/utils/src/utils/debounce.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param {number} [timeout=300] - The debounce delay in milliseconds. Defaults to 300ms if not provided or invalid.
1010
* @returns {(args: unknown[]) => void} A debounced version of the original function.
1111
*/
12-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
12+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type, local-rules/prefer-object-params
1313
export const debounce = (func: Function, timeout?: number) => {
1414
let timer: NodeJS.Timer | undefined;
1515

0 commit comments

Comments
 (0)