Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule for allowing upper camel case only in Class names and constructor functions (that require new) #8085

Closed
mugli opened this issue Feb 15, 2017 · 5 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@mugli
Copy link

mugli commented Feb 15, 2017

I'd like to setup eslint so that I can:

  • Use lower camel case for all variable names (myImportedModule, myObject).
  • Except:
    • Use upper camel case only for class and constructor function names (MyClass), and nowhere else.
    • Allow all upper snake cases for constants (MY_CONSTANT). This is already covered by camelcase rule.

I have tried:

new-cap: [2, {newIsCap: true, capIsNew: true, properties: true}]

But capIsNew option here only works on function names, not on other variables/object names. For example,

// Expecting lint error: MyLogger has to be lower camel-case (myLogger)
// but it works
const MyLogger = require('my-logger'); 
MyLogger.log('...');

I've also considered id-match, but it doesn't distinguish between identifier types (classes/constructors vs other variables). I cannot totally disable upper camel case names.

Can it be done?

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 15, 2017
@not-an-aardvark
Copy link
Member

Does the camelcase rule do what you're looking for?

@not-an-aardvark not-an-aardvark added question This issue asks a question about ESLint and removed triage An ESLint team member will look at this issue soon labels Feb 15, 2017
@mugli
Copy link
Author

mugli commented Feb 15, 2017

No. camelcase doesn't care if the first letter is upper or lower. It just looks for underscores (_) in identifier names (with the exception of all cap constants).

@mugli mugli changed the title Rule for allowing upper camel case only in Class names and constructors Rule for allowing upper camel case only in Class names and constructor functions (that require new) Feb 16, 2017
@platinumazure
Copy link
Member

id-match is close except that its pattern applies to all identifiers. Could it be expanded to allow an object-based configuration for constructors, functions, identifiers, and properties, each possibly with a different pattern?

@alberto
Copy link
Member

alberto commented Mar 11, 2017

Closing this issue as it looks like the question has been answered. Please feel free to visit us in the ESLint Gitter if you have any other issues!

@ratracegrad
Copy link

Saw this was closed and wondering what is the correct setting if you are getting new-cap error messages for creation of class in a Polymer 2 app? I have this line which generates 2 new-cap error messages:
class ShopView extends ReduxMixin(Polymer.Element)

I have this rule:
"new-cap": ["error", { "capIsNewExceptions": ["Polymer", "PolymerRedux"] }],

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

6 participants