Skip to content

Commit

Permalink
refactor ts configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Ezequiel Fabbroni Assum committed Oct 28, 2024
1 parent 094c9aa commit 694de07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
25 changes: 2 additions & 23 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-param-reassign */
/* eslint-disable import/extensions */
import globals from 'globals';

// import tseslint from 'typescript-eslint';
import { isPackageAvailable } from '../utils.js';
import bestPractices from './best-practices.js';
import errors from './errors.js';
Expand All @@ -19,17 +17,13 @@ import reactA11y from './react-a11y.js';
import storybook from './storybook.js';
import strict from './strict.js';
import style from './style.js';
import ts from './ts.js';
import variables from './variables.js';

const isTSAvailable = await isPackageAvailable('typescript');
let tseslint;

let tsConfigs = [];
if (isTSAvailable) {
// eslint-disable-next-line import/no-unresolved
tseslint = await import('typescript-eslint');
tsConfigs = await import('./ts.js');
}

const isJestAvailable = await isPackageAvailable('jest');

const configs = [
Expand Down Expand Up @@ -60,21 +54,6 @@ const overrides = [
},
].filter(Boolean);

const tsConfigs = isTSAvailable
? tseslint.config(
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{ ...ts },
)
: [];

if (tsConfigs.length) {
tsConfigs.forEach((tsconfig) => {
tsconfig.files = ['**/*.ts', '**/*.tsx'];
tsconfig.ignores = ['**/*.d.ts'];
});
}

export default [
...configs,
{
Expand Down
21 changes: 20 additions & 1 deletion configs/ts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default {
/* eslint-disable import/no-unresolved */
/* eslint-disable no-param-reassign */
import tseslint from 'typescript-eslint';

const tsCustomConfig = {
name: 'ts-cabify-eslint-config',
files: ['**/*.ts', '**/*.tsx'],
rules: {
Expand Down Expand Up @@ -140,3 +144,18 @@ export default {
},
ignores: ['*.d.ts'],
};

const tsLintConfig = tseslint.config(
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{ ...tsCustomConfig },
);

if (tsLintConfig.length) {
tsLintConfig.forEach((tsconfig) => {
tsconfig.files = ['**/*.ts', '**/*.tsx'];
tsconfig.ignores = ['**/*.d.ts'];
});
}

export default tsLintConfig;

0 comments on commit 694de07

Please sign in to comment.