Skip to content

Commit

Permalink
feat: disable type checking for JavaScript files (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfeltscher authored Dec 5, 2024
1 parent a3bc9ec commit 19cccd0
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import reactPlugin from 'eslint-plugin-react';
import globals from 'globals';
import tsEslint from 'typescript-eslint';

const JS_FILES = ['**/*.js', '**/*.mjs'];

const reactRules: Linter.RulesRecord = {
'react/prop-types': 'off',
'react/display-name': 'off',
Expand Down Expand Up @@ -50,36 +52,6 @@ const rules = (react: boolean): Linter.RulesRecord => ({
...(react ? reactRules : {}),
});

export const generateLegacyConfig = (react: boolean): Linter.LegacyConfig => ({
rules: rules(react),
env: {
es2020: true,
browser: true,
node: true,
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
projectService: true,
},
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
...(react ? ['plugin:react/recommended', 'plugin:react/jsx-runtime'] : []),
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
});

const flatConfigTypescript = tsEslint.config(
js.configs.recommended,
eslintPluginPrettierRecommended,
Expand All @@ -88,6 +60,10 @@ const flatConfigTypescript = tsEslint.config(
eslintPluginImportConfigs.typescript,
tsEslint.configs.recommendedTypeChecked,
tsEslint.configs.stylisticTypeChecked,
{
files: JS_FILES,
extends: [tsEslint.configs.disableTypeChecked],
},
{
rules: rules(false),
languageOptions: {
Expand Down Expand Up @@ -120,3 +96,39 @@ export const configs = {
typescript: flatConfigTypescript,
react: flatConfigReact,
};

export const generateLegacyConfig = (react: boolean): Linter.LegacyConfig => ({
rules: rules(react),
env: {
es2020: true,
browser: true,
node: true,
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
projectService: true,
},
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
...(react ? ['plugin:react/recommended', 'plugin:react/jsx-runtime'] : []),
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
overrides: [
{
files: JS_FILES,
extends: ['plugin:@typescript-eslint/disable-type-checked'],
},
],
});

0 comments on commit 19cccd0

Please sign in to comment.