Skip to content

Commit 8f2fdf2

Browse files
author
Matthias Hecht
committed
feat(naming-convention): adds a new shared configuration for enforcing naming conventions
1 parent 9f028ed commit 8f2fdf2

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ This shared ESLint configuration is designed to enforce best practices and recom
176176
- [`playwright/prefer-to-have-length`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/prefer-to-have-length.md): enforces the use of `.toHaveLength()` instead of `.toEqual(n)` when testing the length of an object.
177177
- [`playwright/require-top-level-describe`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/require-top-level-describe.md): requires tests to be organized into top-level `describe()` blocks.
178178

179+
### Naming Convention
180+
181+
```js
182+
import boehringer from '@boehringer-ingelheim/eslint-config';
183+
184+
export default boehringer.config(
185+
boehringer.configs.strict,
186+
// possibly other configs,
187+
boehringer.configs.namingConvention
188+
);
189+
```
190+
191+
This shared ESLint configuration is designed to enforce some naming conventions. It uses the [`@typescript-eslint/naming-convention`](https://typescript-eslint.io/rules/naming-convention/) rule for enforcing the naming conventions. The enforced conventions can be found in [configs/naming-convention.js](./configs/naming-convention.js#L7-L65)
192+
179193
### Prettier-disable
180194

181195
```js

configs/naming-convention.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const tseslint = require('typescript-eslint');
2+
3+
module.exports = tseslint.config({
4+
rules: {
5+
'@typescript-eslint/naming-convention': [
6+
'error',
7+
{
8+
// Enforce that interface names do not start with an 'I'
9+
custom: {
10+
match: false,
11+
regex: '^I[A-Z]',
12+
},
13+
format: ['StrictPascalCase'],
14+
leadingUnderscore: 'forbid',
15+
selector: 'interface',
16+
trailingUnderscore: 'forbid',
17+
},
18+
{
19+
// Enforce that type alias names do not start with an 'T'
20+
custom: {
21+
match: false,
22+
regex: '^T[A-Z]',
23+
},
24+
format: ['StrictPascalCase'],
25+
leadingUnderscore: 'forbid',
26+
selector: 'typeAlias',
27+
trailingUnderscore: 'forbid',
28+
},
29+
{
30+
// Enforce that all top-level variables are in UPPER_CASE
31+
format: ['UPPER_CASE'],
32+
leadingUnderscore: 'forbid',
33+
modifiers: ['global'],
34+
selector: 'variable',
35+
trailingUnderscore: 'forbid',
36+
types: ['boolean', 'number', 'string'],
37+
},
38+
{
39+
// Enforce that all top-level array variables are in UPPER_CASE and are suffixed with a 'S' to indicate plural form
40+
format: ['UPPER_CASE'],
41+
leadingUnderscore: 'forbid',
42+
modifiers: ['global'],
43+
selector: 'variable',
44+
suffix: ['S'],
45+
trailingUnderscore: 'forbid',
46+
types: ['array'],
47+
},
48+
{
49+
// Enforce that array variables are suffixed with a 's' to indicate plural form
50+
format: ['strictCamelCase'],
51+
leadingUnderscore: 'forbid',
52+
selector: 'variable',
53+
suffix: ['s'],
54+
trailingUnderscore: 'forbid',
55+
types: ['array'],
56+
},
57+
{
58+
// Enforce that boolean variables are prefixed with an allowed verb
59+
format: ['StrictPascalCase'],
60+
leadingUnderscore: 'forbid',
61+
prefix: ['is', 'has', 'should', 'can'],
62+
selector: 'variable',
63+
trailingUnderscore: 'forbid',
64+
types: ['boolean'],
65+
},
66+
],
67+
},
68+
});

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const tseslint = require('typescript-eslint');
22

33
const base = require('./configs/base.js');
44
const local = require('./configs/local.js');
5+
const namingConvention = require('./configs/naming-convention.js');
56
const nextjs = require('./configs/nextjs.js');
67
const playwright = require('./configs/playwright.js');
78
const prettierDisable = require('./configs/prettier-disable.js');
@@ -13,6 +14,7 @@ module.exports = {
1314
configs: {
1415
base,
1516
local,
17+
namingConvention,
1618
nextjs,
1719
playwright,
1820
prettierDisable,

0 commit comments

Comments
 (0)