'use strict';

const rules = require('./rules');

let hasTypescript;
try {
    require.resolve('typescript');
    hasTypescript = true;
} catch (err) {
    hasTypescript = false;
}

const overrides = [];
if (hasTypescript) {
    overrides.push(
        {
            // overrides just for react files
            files: ['*.jsx', '*.tsx'],
            extends: ['plugin:@typescript-eslint/recommended', 'plugin:react-hooks/recommended', 'airbnb'],
            plugins: ['@typescript-eslint'],
            parser: '@typescript-eslint/parser',
            env: {
                jest: true,
                jasmine: false,
                node: false,
                browser: true,
            },
            parserOptions: {
                ecmaVersion: 8,
                sourceType: 'module',
                ecmaFeatures: {
                    modules: true,
                    jsx: true,
                },
                useJSXTextNode: true,
            },
            rules: rules.react,
        },
        {
            // overrides just for typescript files
            files: ['*.ts'],
            extends: ['plugin:@typescript-eslint/recommended', 'airbnb-base'],
            plugins: ['@typescript-eslint'],
            parser: '@typescript-eslint/parser',
            parserOptions: {
                ecmaVersion: 8,
                sourceType: 'module',
                ecmaFeatures: {
                    modules: true,
                    jsx: false,
                },
            },
            rules: rules.typescript,
        },
        {
            // overrides just for spec files
            files: ['*-spec.js', '*-spec.ts', '*-spec.tsx', '*-spec.jsx'],
            plugins: ['jest'],
            env: {
                'jest/globals': true
            },
            rules: rules.jest,
        },
    );
}

module.exports = overrides;

@@ -240,32 +240,479 @@
 push(%0A        %7B%0A
+            files: %5B'*.mjs'%5D,%0A            extends: %5B'airbnb-base'%5D,%0A            parserOptions: %7B%0A                ecmaVersion: 8,%0A                sourceType: 'module',%0A                ecmaFeatures: %7B%0A                    modules: true,%0A                %7D,%0A            %7D,%0A            env: %7B%0A                node: true,%0A                jasmine: true,%0A                jest: true,%0A            %7D,%0A            rules: rules.javascript,%0A        %7D,%0A        %7B%0A
             // o

Make sure eslint works with mjs files