sindresorhus/eslint-plugin-unicorn

Rule proposal: `id-match`

Closed

#1,545 opened on Oct 11, 2021

 (9 comments) (1 reaction) (0 assignees)JavaScript (468 forks)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

When working with external libraries, it is often undesirable to rename their exports for the sole purpose of conforming with id-match rule.

This has been proposed as addition to ESLint in https://github.com/eslint/eslint/issues/14005, but ultimately it was rejected:

I think this falls under our policies of not adding new options to stylistic rules, so in my opinion the best course of action would be to make a custom rule/plugin.

This rule would be equivalent to id-match with an additional option ignoreImports that would ignore named imports.

Fail

Assuming that rule does not permit IDs with $:

const ContraImageFragment$key = '';

Pass

Assuming that this rule is configured to ignore imports:

import type { ContraImageFragment$key } from '@/__generated__/ContraImageFragment.graphql';

Happy to contribute to the codebase.

Contributor guide