I need to run eslint on a script in my_repo, but I am totally unfamiliar with TypeScript, so I might be doing some lame mistake.
This is the repo structure, with the eslint.config.mjs
configuration file:
my_repo
-- frontend_react
---- eslint.config.mjs
---- path_to_script
so I installed it and ran it:
npm install eslint --save-dev -> it installs eslint 9.20.1
npx eslint --config frontend_react/eslint.config.mjs frontend_react/src/views/tmp/StreamsReporting/StreamsStatistics.tsx --fix
but I'm getting the error:
Oops! Something went wrong! :(
ESLint: 9.0.0
ConfigError: Config (unnamed): All arguments must be objects.
at rethrowConfigError (/Users/user_name/work/projects/my_repo/node_modules/@humanwhocodes/config-array/api.js:225:8)
at /Users/user_name/work/projects/my_repo/node_modules/@humanwhocodes/config-array/api.js:1018:5
at Array.reduce (<anonymous>)
at FlatConfigArray.getConfig (/Users/user_name/work/projects/my_repo/node_modules/@humanwhocodes/config-array/api.js:1014:39)
at FlatConfigArray.isFileIgnored (/Users/user_name/work/projects/my_repo/node_modules/@humanwhocodes/config-array/api.js:1046:15)
at /Users/user_name/work/projects/my_repo/node_modules/eslint/lib/eslint/eslint-helpers.js:514:38
at Array.forEach (<anonymous>)
at findFiles (/Users/user_name/work/projects/my_repo/node_modules/eslint/lib/eslint/eslint-helpers.js:503:11)
at async ESLint.lintFiles (/Users/user_name/work/projects/my_repo/node_modules/eslint/lib/eslint/eslint.js:846:27)
at async Object.execute (/Users/user_name/work/projects/my_repo/node_modules/eslint/lib/cli.js:461:23)
The configuration file is:
import prettier from 'eslint-plugin-prettier';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default [
{
ignores: ['**/node_modules', '**/package.lock.json', '**/build', '**/resources', '**/vite.config.js'],
},
..pat.extends('eslint:recommended', 'plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'prettier'),
{
plugins: {
prettier,
'@typescript-eslint': typescriptEslint,
},
languageOptions: {
globals: {
...globals.browser,
},
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
project: ['tsconfig.json'],
},
},
rules: {
'react/react-in-jsx-scope': 'off',
'prettier/prettier': ['error'],
'semi': ['error', 'always'],
'quotes': [
'warn',
'single',
{
allowTemplateLiterals: true,
},
],
'no-extra-boolean-cast': 'off',
},
},
];
I tried changing the first part to:
const extendsConfig = compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
);
export default {
ignores: ['**/node_modules', '**/package.lock.json', '**/build', '**/resources', '**/vite.config.js'],
extends: extendsConfig,
[...]
but now it seems the file is ignored altogether:
/Users/user_name/work/projects/my_repo/frontend_react/src/views/tmp/StreamsReporting/StreamsStatistics.tsx
0:0 warning File ignored because no matching configuration was supplied
✖ 1 problem (0 errors, 1 warning)
Any suggestions?