diff --git a/README.md b/README.md index 9d72340..6a635b6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/configs/naming-convention.js b/configs/naming-convention.js new file mode 100644 index 0000000..0cd40a3 --- /dev/null +++ b/configs/naming-convention.js @@ -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'], + }, + ], + }, +}); diff --git a/index.js b/index.js index e87726f..ef3d0cf 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -13,6 +14,7 @@ module.exports = { configs: { base, local, + namingConvention, nextjs, playwright, prettierDisable,