Skip to content

[@typescript-eslint/naming-convention] Less strict handling of merged declarations #2223

Closed
@octogonz

Description

@octogonz

Repro

TypeScript allows two different declarations to use the same name; they get merged into a single type. Besides a small handful of useful scenarios (e.g. namespace+enum), merged declarations generally arise as hacks in advanced abstractions (e.g. mixins) or retrofitted types for a legacy API. To avoid these complexities, I'll give somewhat contrived examples below.

The problem is that @typescript-eslint/naming-convention seems to check each declaration independently, whereas merged declarations must all have the same name. As a result, ESLint may reject every possible name.

{
  "rules": {
    "@typescript-eslint/naming-convention": ["error"]
  }
}

A couple example inputs:

export class SomeClass {}

// ('typeLike' must have 'PascalCase')
export type Example = SomeClass;

// ERROR: Variable name `Example` must match one of 
// the following formats: camelCase, UPPER_CASE
export const Example = SomeClass;
// ('typeLike' must have 'PascalCase')
export interface Example2 {
  x: boolean;
}

// ERROR: Function name `Example2` must match one of the following formats: camelCase
export function Example2(): Example2 {
  return { x: false };
}

Expected Result

Here's a better way to handle merged declarations: The @typescript-eslint/naming-convention rule should recognize merged declarations, and accept ANY applicable pattern, instead of applying ALL patterns.

For the sample declaration Example2 above, ESLint could accept EITHER 'PascalCase' OR 'camelCase' (whereas currently it requires BOTH).

Versions

package version
@typescript-eslint/eslint-plugin 3.3.0
@typescript-eslint/parser 3.3.0
TypeScript 3.5.3
ESLint 7.2.0
node 12.17.0
npm 6.14.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions