rpg-combat-pi-01/eslint.config.js
Willem van den Ende 0540e5ff5b feat(eslint): add no-primitive-value-properties rule to enforce value objects
Add custom ESLint rule that warns when class properties or constructor
parameters use primitive types (number, string, boolean) where a value
object exists in src/value-objects/.

The rule auto-discovers value objects from the directory and maps
property names (e.g. 'health' → 'Health') to suggest the correct type.

Found 4 warnings on the codebase:
- MagicalObject.ts: #health: number property
- MagicalObject.ts: health: number constructor param
- MagicalWeapon.ts: health: number constructor param
- HealingObject.ts: health: number constructor param
2026-06-14 12:39:54 +01:00

90 lines
2.5 KiB
JavaScript

import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-config-prettier';
import noPrimitiveValue from './eslint/no-primitive-value-properties.js';
export default tseslint.config(
{ ignores: ['dist', 'node_modules', 'coverage', 'allium-main'] },
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ['src/**/*.ts'],
extends: [...tseslint.configs.recommendedTypeChecked],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
rpg: {
rules: {
'no-primitive-value-properties': noPrimitiveValue,
},
},
},
rules: {
'@typescript-eslint/switch-exhaustiveness-check': 'warn',
'@typescript-eslint/no-unnecessary-condition': 'warn',
'rpg/no-primitive-value-properties': 'warn',
},
},
{
rules: {
complexity: ['warn', 12],
'max-depth': ['warn', 4],
'max-params': ['warn', 5],
'max-lines-per-function': [
'warn',
{ max: 60, skipBlankLines: true, skipComments: true, IIFEs: true },
],
'no-else-return': ['warn', { allowElseIf: false }],
'no-lonely-if': 'warn',
'no-param-reassign': ['warn', { props: false }],
eqeqeq: ['warn', 'always', { null: 'ignore' }],
'prefer-const': 'warn',
'prefer-template': 'warn',
'object-shorthand': 'warn',
'no-console': 'warn',
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
allowDirectConstAssertionInArrowFunctions: true,
allowIIFEs: true,
},
],
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-unused-vars': [
'warn',
{ varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'warn',
// null is forbidden by TypeScript strictNullChecks (tsconfig).
},
},
{
files: ['**/*.test.ts', '**/*.spec.ts'],
rules: {
'max-lines-per-function': 'off',
'max-params': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
},
prettier,
);