Rule for allowing upper camel case only in Class names and constructor functions (that require new)
See original GitHub issueI’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 bycamelcase
rule.
- Use upper camel case only for class and constructor function names (
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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Pascal Case: under_scores, camelCase and PascalCase
In camel casing, names start with a lower case but each proper word in the name is capitalized and so are acronyms. For...
Read more >10 JavaScript Naming Conventions Every Developer Should ...
You can use the camel case naming convention for all types of variables in JavaScript, and it will ensure that there aren't multiple...
Read more >naming-convention | typescript-eslint
This rule allows you to enforce conventions for any identifier, using granular ... the default config is similar to ESLint's camelcase rule but...
Read more >Style · C++ Best Practices
Common C++ Naming Conventions · Macro names use upper case with underscores: INT_MAX . · Template parameter names use camel case: InputIterator ....
Read more >What is pascal case? - TheServerSide.com
Pascal case requires that the first letter of a variable be in upper case. In contrast, camel case -- also known as CamelCase...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?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”] }],