Skip to content

Commit

Permalink
fix(lint): migrate to eslint v9 + flat config + recommended rules (#867)
Browse files Browse the repository at this point in the history
* chore(deps): update eslint to v9 and migrate to flat config

* fix(eslint): fixup all errors found by the new set of eslint rules

BREAKING CHANGE: We updated our config to the recommended typescript-eslint typed rules
 so some types have become stricter than they were before.
  • Loading branch information
gdostie authored Oct 10, 2024
1 parent 2c51527 commit da19840
Show file tree
Hide file tree
Showing 214 changed files with 8,189 additions and 18,337 deletions.
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/lint/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description: 'Check files respect ESLint & Prettier rules'
runs:
using: composite
steps:
- run: npm run prettier:check && npm run eslint:check
- run: npm run lint
shell: bash
4 changes: 4 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
printWidth: 120
tabWidth: 4
singleQuote: true
bracketSpacing: false
1 change: 0 additions & 1 deletion commitlint.config.cjs

This file was deleted.

5 changes: 5 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Configuration = {
extends: ['@commitlint/config-conventional'],
};

export default Configuration;
52 changes: 52 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginJest from 'eslint-plugin-jest';
import jsdoc from 'eslint-plugin-jsdoc';
import {dirname} from 'node:path';
import {fileURLToPath} from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

export default tseslint.config(
{ignores: ['dist']},
{
extends: [
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
jsdoc.configs['flat/recommended-typescript'],
eslintConfigPrettier,
],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/prefer-promise-reject-errors': 'warn',
'@typescript-eslint/only-throw-error': 'warn',
'@typescript-eslint/unbound-method': 'warn',
},
},
{
files: ['**/*.spec.ts'],
extends: [eslintPluginJest.configs['flat/recommended']],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
},
},
{files: ['**/*.js', '**/*.mjs'], ...tseslint.configs.disableTypeChecked},
);
26 changes: 26 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const unmockedDependencies = ['query-string-esm', 'decode-uri-component', 'split-on-first', 'filter-obj'];

// /*
// * For a detailed explanation regarding each configuration property, visit:
// * https://jestjs.io/docs/configuration
// */

export default {
extensionsToTreatAsEsm: ['.ts'],
preset: 'ts-jest/presets/default-esm',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^#query-string': 'query-string-cjs',
},
transform: {
'^.+\\.[tj]s$': ['ts-jest', {tsconfig: '<rootDir>/../tsconfig.test.json', useESM: true}],
},
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: ['<rootDir>/**/*.{ts,tsx}'],
coverageDirectory: 'coverage',
setupFiles: ['../jest.setup.ts'],
transformIgnorePatterns: [`node_modules/(?!(${unmockedDependencies.join('|')}))`],
rootDir: './src',
testEnvironment: 'node',
};
37 changes: 0 additions & 37 deletions jest.config.mjs

This file was deleted.

Loading

0 comments on commit da19840

Please sign in to comment.