Skip to content

Rule proposal: Type-based naming rule #722

Closed
@ark120202

Description

@ark120202

I'd like to have a rule that enforces some strict conventions on identifier names. camelcase also allows PascalCase and with id-match it's impossible to enforce this:

// Valid
const foo = getString();
// Invalid
const Foo = getString();
// Invalid, also conflicts with new-cap
const foo = createClass(); // function createClass(): new (...args: any[]) => any
// Invalid
const foo: React.FC = ...;
// Any name is [in]valid?
const foo = Math.random() < 0.5 ? createClass() : createString();

It also was a limitation for tslint, so there are few relevant issues:

I'm not really sure what kind of configuration fits this rule (or multiple rules?). For me it would be enough to have a stricter version of camelcase that keeps all classes and functions returning JSX.Element in PascalCase and everything else in camelCase, but for some more complex cases it may be worth to have extensible configuration, similar to naming-convention from tslint-consistent-codestyle, which also would cover #515.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: new plugin ruleNew rule request for eslint-pluginhas prthere is a PR raised to close thispackage: 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