Skip to content

Commit 4b5811a

Browse files
committed
naming-convention: make parameterProperty configurable
Fixes: #76
1 parent 8402e28 commit 4b5811a

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

rules/namingConventionRule.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@ enum Types {
3737
parameter = 1 << 2,
3838
member = 1 << 3,
3939
property = 1 << 4,
40-
method = 1 << 5,
41-
type = 1 << 6,
42-
class = 1 << 7,
43-
interface = 1 << 8,
44-
typeAlias = 1 << 9,
45-
genericTypeParameter = 1 << 10,
46-
enum = 1 << 11,
47-
enumMember = 1 << 12,
48-
functionVariable = 1 << 13,
40+
parameterProperty = 1 << 5,
41+
method = 1 << 6,
42+
type = 1 << 7,
43+
class = 1 << 8,
44+
interface = 1 << 9,
45+
typeAlias = 1 << 10,
46+
genericTypeParameter = 1 << 11,
47+
enum = 1 << 12,
48+
enumMember = 1 << 13,
49+
functionVariable = 1 << 14,
4950
// tslint:enable:naming-convention
5051
}
5152

@@ -56,7 +57,7 @@ enum TypeSelector {
5657
functionVariable = variable | Types.functionVariable,
5758
parameter = variable | Types.parameter,
5859
property = Types.member | Types.property,
59-
parameterProperty = parameter | property,
60+
parameterProperty = Types.parameterProperty | parameter | property,
6061
method = Types.member | Types.method,
6162
class = Types.type | Types.class,
6263
interface = Types.type | Types.interface,
@@ -110,6 +111,7 @@ enum Specifity {
110111
property = 6 << 9,
111112
method = Specifity.property,
112113
enumMember = 7 << 9,
114+
parameterProperty = enumMember,
113115
type = 8 << 9,
114116
class = 9 << 9,
115117
interface = Specifity.class,

test/rules/naming-convention/default/test.ts.lint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class TestClass {
7878
~~~ [method name must be in StrictPascalCase]
7979
constructor(public readonly _foo, protected bar) {}
8080
~~~~ [parameterProperty name must not have leading underscore]
81-
~~~~ [parameterProperty name must be in UPPER_CASE]
8281
~~~ [parameterProperty name must have leading underscore]
8382
constructor(private readonly _FOO_Bar) {}
8483
toJSON() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class Point {
2+
constructor(protected x: number, protected y: number, Z: number, public selected: boolean) {}
3+
~ [parameterProperty name must be in UPPER_CASE]
4+
~ [parameter name must be in camelCase]
5+
~~~~~~~~ [parameterProperty name must be in PascalCase]
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"rulesDirectory": [
3+
"../../../../rules"
4+
],
5+
"rules": {
6+
"naming-convention": [
7+
true,
8+
{"type": "default", "format": "PascalCase", "leadingUnderscore": "forbid", "trailingUnderscore": "forbid"},
9+
{"type": "parameter", "format": "camelCase"},
10+
{"type": "variable", "format": "camelCase"},
11+
{"type": "property", "format": "camelCase"},
12+
{"type": "property", "modifiers": ["public"], "format": "PascalCase"},
13+
{"type": "parameterProperty", "modifiers": "protected", "format": "UPPER_CASE"},
14+
{"type": "parameterProperty", "filter": "x", "format": "camelCase"}
15+
]
16+
}
17+
}

0 commit comments

Comments
 (0)