question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Feb 16, 2017

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?

0reactions
ratracegradcommented, Nov 1, 2017

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”] }],

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found