From 56a732389ead4d32bc696224785f72dc962f062b Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 3 Aug 2024 09:14:15 +1200 Subject: [PATCH] chore: handle different rule names depending on `@typescript-eslint/eslint-plugin` version --- .eslintrc.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 70f54bac1..5d6e5f4b9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,25 @@ 'use strict'; +const { + version: typescriptESLintPluginVersion, +} = require('@typescript-eslint/eslint-plugin/package.json'); +const semver = require('semver'); const globals = require('./src/globals.json'); +const typescriptBanTypesRules = () => { + if (semver.major(typescriptESLintPluginVersion) === 8) { + return { + '@typescript-eslint/no-empty-object-type': 'error', + '@typescript-eslint/no-unsafe-function-type': 'error', + '@typescript-eslint/no-wrapper-object-types': 'error', + }; + } + + return { + '@typescript-eslint/ban-types': 'error', + }; +}; + module.exports = { parser: require.resolve('@typescript-eslint/parser'), extends: [ @@ -30,7 +48,7 @@ module.exports = { '@typescript-eslint/array-type': ['error', { default: 'array-simple' }], '@typescript-eslint/no-require-imports': 'error', '@typescript-eslint/ban-ts-comment': 'error', - '@typescript-eslint/ban-types': 'error', + ...typescriptBanTypesRules(), '@typescript-eslint/consistent-type-imports': [ 'error', { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },