Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[camelcase] The camelcase rule allows PascalCase #871

Closed
Labels
enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulehas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@octogonz

Description

@octogonz

Repro

{"rules": {"@typescript-eslint/camelcase": ["error" ],  }}
exportclassExample{publicPascalCasedMethod():void{}publicconvertToHTML():void{}public_______HOWisTHISacceptable______():void{}}

Expected Result

A "camel case" identifier starts with a lower case letter, and then uses a capital for the first letter of each word.

For the TSLint rules that I've been migrating, the identifierPascalCasedMethod would be forbidden because it is not camel case. It should be changed topascalCasedMethod.

We would also forbid the identifierconvertToHTML, instead preferringconvertToHtml in camel case.

I don't know how to describe_______HOWisTHISacceptable______, but it's clearly not camel case.

Actual Result

The@typescript-eslint/camelcase rule accepts all of the above identifiers. No errors are reported. Recently I saw a PR where someone created a Pascal-cased method.

From what I can tell, the rule implementation doesn't consider camel case at all. It merely banssnake_case by checking whether an underscore appears between any letters.

Additional Info

This problem also affects the base ESLint rule. It was brought up a long time ago aseslint/eslint#10473. In that thread, they note that JavaScript has trouble distinguishing acamelCase member from aPascalCase constructor function.

We could fix it in ESLint, but I see a few reasons why we might instead want to tackle this problem in@typescript-eslint/eslint-plugin:

  • This plugin has a goal to replace TSLint, whosevariable-name does not allowPascalCase or extra underscores
  • Unlike JavaScript, the constructor function casing concern is irrelevant to TypeScript
  • The@typescript-eslint/camelcase extension has a fair amount of extra logic, so we'd likely have to modify it regardless of whether we fixed ESLint or not

The fix should be pretty easy, and would involve adding a new option (e.g.strict: true) that changes the rule to actually test for camel case. Or, if we want to be very flexible, the option could require the identifier MUST match one of the RegExps from theallow option. That would give custom configurations a lot of freedom for allowing/disallowing edge cases, while keeping the rule simple to understand.

In theeslint/eslint#10473 discussion, they pointed out that ESLint'sid-match rule can be used to solve this problem. I'm open to that approach as well, however we'd have to extend that rule for@typescript-eslint/eslint-plugin and reimplement all the logic that's currently incamelCase. That seems less desirable to me, since (for myself at least) I want the error message to say "you're not using camel case" rather than saying "PLEASE COMPLY WITH ON OF THESE CRYPTIC REGEXPS".

Versions

packageversion
@typescript-eslint/eslint-plugin2.0.0
@typescript-eslint/parser2.0.0
TypeScript3.5.2
ESLint6.1.0
node8.15.0
npm6.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulehas 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


      [8]ページ先頭

      ©2009-2025 Movatter.jp