Naming conventions #4282
Replies: 4 comments 9 replies
-
|
I am not sure if this should be part of the same rule. However, we can add a convention for filenames. Conventional filenames for JavaScript and TypeScriptPlease feel free to comment in this thread if I missed something. The rule applies to all files ending with the following extensions:
ConfigurationAn option should be provided to choose between |
Beta Was this translation helpful? Give feedback.
-
|
I like this proposal very much. It could be a rule under |
Beta Was this translation helpful? Give feedback.
-
|
I updated the spec with the current implementation of the rule. EDIT: I am thinking about enabling I am wondering if we should also accept local variables / parameters / top-level let in However, for consistency, this could also require supporting We could add some restrictions: for instance we could allow I could like to get opinions about this. |
Beta Was this translation helpful? Give feedback.
-
Have you tried to see if Rust/clippy throws a warning if we write an enum variant in lower case? I would tend to follow the rules set by a language that has first class support for enums |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
For now, Rome has only one rule to check consistent naming convention: useCamelCase which is certainly inspired by its equivalent ESLint rule camel-case.
Some users proposed the addition of new rules : usePascalCaseClassNames.
TypeScript ESLint implements an all-in-one rule: naming-convention.
The rule has a default behavior and is fine-tunable (AST node type, regex, ...).
I personally did not like the multiplication of rules:
useCamelCase,usePascalCaseClassNames,useConstantCase, ...On the other hand, I did not like the fine-tunable all-in-one rule.
I suggest introducing a new rule
useConventionalNameoruseNamingConventionthat ensures the respect of naming conventions in the JS/TS community.The rule should be sufficiently relaxed in order to accommodate with the current practice in the community.
In the following section I gathered the naming practice.
Conventional name
Please feel free to comment in this thread if I missed something.
An identifier is in
PascalCase,camelCase, orCONSTANT_CASE.An identifier can be prefixed with underscores
_.This supports several practices:
__htmlAn identifier can be suffixed with underscores
_.This allows compatibility with the default behavior of ESLint
naming-convention.An identifier can be prefixed with dollar signs
$.This supports several practices:
An identifier can be suffixed with dollar signs
$.This supports one practice:
Observablestream.On top of these simple rules, we add some restrictions:
PascalCasePascalCaseorcamelCasecamelCasecamelCaseorCONSTANT_CASEPascalCaseorcamelCaseorCONSTANT_CASESome remarks:
All values that are types (class, enum, enum value, interface, type alias, type parameter) can be in
PascalCaseNamed function in
PascalCaseIn contrast to the default behavior of ESLint
nameing-convention, I think we should allow named function inPascalCase.This allows:
old-fashion ES5 classes
React components:
@Decoaratorstatic class property / getter in
CONSTANT_CASEIn contrast to the default behavior of ESLint
nameing-convention, we allow static class property inCONSTANT_CASE.This is often used to denote a class constant.
interface / type readonly property / getter in
CONSTANT_CASEThis allows to model the interface of the sttatic part of a class.
Top-level variables can be in
CONSTANT_CASEorPascalCaseIn contrast to the default behavior of ESLint
nameing-convention, only top-level variables of a script, module, or namespace declared withconstorvarcan be inCONSTANT_CASEorPascalCase.An
enumvalue is either inUpperCamelCaseor inCONSTANT_CASEWe find these two naming conventions in the community.
UpperCamelCaseseems more widely used thanCONSTANT_CASE.Strangely, the default behavior of ESLint
nameing-conventionrequires usingcamelCase.This seems to confuse users.
I opened an issue about that.
Configuration
strictCase: allow supporting consecutive uppercase chars incamelCASEandPascalCASE. In strict case mode (default)HTTPServeris not considered inPascalCase. It has to be renamed toHttpServer.enumMemberCase: allow choosing betweenPascalCase(default),CONSTANT_CASE, andcamelCase(for _ESlint8 compatibility).Beta Was this translation helpful? Give feedback.
All reactions