Skip to content

[no-unnecessary-condition] Add option to ignore expressions as an arguments of certain functions. #2752

Open
@IvanGoncharov

Description

@IvanGoncharov

We working on converting graphql and express-graphql package to TS and want to use no-unnecessary-condition since we had this lint rule in Flow.
The problem is that both libraries are used in a lot of JS projects so we need to check arguments of public API functions for popular mistakes.
So we created devCheck function for this purpose:

function devAssert(condition: unknown, message: string): asserts condition {
  const booleanCondition = Boolean(condition);
  if (!booleanCondition) {
    throw new Error(message);
  }
}

Problem is that we get this error:

  190:13  error  Unnecessary conditional, the types have no overlap  @typescript-eslint/no-unnecessary-condition

for this code

export function graphqlHTTP(options: Options): Middleware {
  devAssert(options != null, 'GraphQL middleware requires options.');

It would be ideal if we can pass devAssert as an option for the no-unnecessary-condition rule and expressions inside arguments would be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions