Skip to content

Commit

Permalink
feat(naming-convention): adds a new shared configuration for enforcin…
Browse files Browse the repository at this point in the history
…g naming conventions
  • Loading branch information
Matthias Hecht committed Jan 17, 2025
1 parent 9f028ed commit 8f2fdf2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ This shared ESLint configuration is designed to enforce best practices and recom
- [`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.
- [`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.

### Naming Convention

```js
import boehringer from '@boehringer-ingelheim/eslint-config';

export default boehringer.config(
boehringer.configs.strict,
// possibly other configs,
boehringer.configs.namingConvention
);
```

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)

### Prettier-disable

```js
Expand Down
68 changes: 68 additions & 0 deletions configs/naming-convention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const tseslint = require('typescript-eslint');

module.exports = tseslint.config({
rules: {
'@typescript-eslint/naming-convention': [
'error',
{
// Enforce that interface names do not start with an 'I'
custom: {
match: false,
regex: '^I[A-Z]',
},
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
selector: 'interface',
trailingUnderscore: 'forbid',
},
{
// Enforce that type alias names do not start with an 'T'
custom: {
match: false,
regex: '^T[A-Z]',
},
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
selector: 'typeAlias',
trailingUnderscore: 'forbid',
},
{
// Enforce that all top-level variables are in UPPER_CASE
format: ['UPPER_CASE'],
leadingUnderscore: 'forbid',
modifiers: ['global'],
selector: 'variable',
trailingUnderscore: 'forbid',
types: ['boolean', 'number', 'string'],
},
{
// Enforce that all top-level array variables are in UPPER_CASE and are suffixed with a 'S' to indicate plural form
format: ['UPPER_CASE'],
leadingUnderscore: 'forbid',
modifiers: ['global'],
selector: 'variable',
suffix: ['S'],
trailingUnderscore: 'forbid',
types: ['array'],
},
{
// Enforce that array variables are suffixed with a 's' to indicate plural form
format: ['strictCamelCase'],
leadingUnderscore: 'forbid',
selector: 'variable',
suffix: ['s'],
trailingUnderscore: 'forbid',
types: ['array'],
},
{
// Enforce that boolean variables are prefixed with an allowed verb
format: ['StrictPascalCase'],
leadingUnderscore: 'forbid',
prefix: ['is', 'has', 'should', 'can'],
selector: 'variable',
trailingUnderscore: 'forbid',
types: ['boolean'],
},
],
},
});
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const tseslint = require('typescript-eslint');

const base = require('./configs/base.js');
const local = require('./configs/local.js');
const namingConvention = require('./configs/naming-convention.js');
const nextjs = require('./configs/nextjs.js');
const playwright = require('./configs/playwright.js');
const prettierDisable = require('./configs/prettier-disable.js');
Expand All @@ -13,6 +14,7 @@ module.exports = {
configs: {
base,
local,
namingConvention,
nextjs,
playwright,
prettierDisable,
Expand Down

0 comments on commit 8f2fdf2

Please sign in to comment.