dfinity / dfinity/candid

eslint no-unused-var for generated JS and TS types

Open
#573 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
301
Forks
85
Avg merge
1h 4m
Merged PRs (30d)
4

Description

Is your feature request related to a problem? Please describe.

Given that most JS and TS projects use ESLint for code validation, I suggest adding two exceptions (// eslint-disable-next-line @typescript-eslint/no-unused-vars) to the generated types by default; otherwise, they may cause developers' linters to fail.

JS:

export const idlFactory = ({ IDL }) => {
  const Hello = IDL.Record({ 'world' : IDL.Text });
  return IDL.Service({
    'yolo' : IDL.Func([Hello], [IDL.Text], ['query']),
  });
};
export const init = ({ IDL }) => { return []; }; // ---> ESLint: 'IDL' is defined but never used.(@typescript-eslint/no-unused-vars)

TS:

import type { Principal } from '@dfinity/principal'; // ---> ESLint: 'Principal' is defined but never used.(@typescript-eslint/no-unused-vars)
import type { ActorMethod } from '@dfinity/agent';
import type { IDL } from '@dfinity/candid';

export interface Hello { 'world' : string }
export interface _SERVICE {
  'yolo' : ActorMethod<[Hello], string>,
}
export declare const idlFactory: IDL.InterfaceFactory;
export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the generator responsible for the JavaScript and TypeScript outputs shown in the issue and inspect how their templates are assembled. Verify the generated files with ESLint and TypeScript linting; done means the default outputs no longer report the demonstrated unused-variable warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.