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.
-
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
useConventionalName
oruseNamingConvention
that 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:
__html
An 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:
Observable
stream.On top of these simple rules, we add some restrictions:
PascalCase
PascalCase
orcamelCase
camelCase
camelCase
orCONSTANT_CASE
PascalCase
orcamelCase
orCONSTANT_CASE
Some remarks:
All values that are types (class, enum, enum value, interface, type alias, type parameter) can be in
PascalCase
Named function in
PascalCase
In 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:
@Decoarator
static class property / getter in
CONSTANT_CASE
In 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_CASE
This allows to model the interface of the sttatic part of a class.
Top-level variables can be in
CONSTANT_CASE
orPascalCase
In contrast to the default behavior of ESLint
nameing-convention
, only top-level variables of a script, module, or namespace declared withconst
orvar
can be inCONSTANT_CASE
orPascalCase
.An
enum
value is either inUpperCamelCase
or inCONSTANT_CASE
We find these two naming conventions in the community.
UpperCamelCase
seems more widely used thanCONSTANT_CASE
.Strangely, the default behavior of ESLint
nameing-convention
requires usingcamelCase
.This seems to confuse users.
I opened an issue about that.
Configuration
strictCase
: allow supporting consecutive uppercase chars incamelCASE
andPascalCASE
. In strict case mode (default)HTTPServer
is 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