Skip to content

Typescript-only rules are being checked against pure JS files #488

@Fryuni

Description

@Fryuni

🐞 Bug report

Linting raw JS files in a project that uses the exported typescript config fails with the following message:

Error: Error while loading rule '@typescript-eslint/await-thenable': You have used a rule which requires type information, but don't have parserOptions set to generate type information for this file. See https://tseslint.com/typed-linting for enabling linting with type information.
Parser: typescript-eslint/parser
Occurred while linting /home/lotus/.local/share/git_worktrees/3a52ce780950d4d969792a2559cd519d7ee8c727/file.js

This happens because the recommendedTypeChecked config from typescript-eslint is generated without a filter for only TS files. This requires loading the type information for the project, which might not be relevant or even valid. Ideally, TS-only rules should be applied only to TS/TSX files.

Steps to reproduce

  1. Create a project using the configs.typescript rules exported:
    import {defineConfig} from 'eslint/config';
    import {configs} from '@croct/eslint-plugin';
    
    export default defineConfig(configs.typescript)
  2. Create a pure JS file (.[cm]?js)
  3. Run eslint file.js

Expected behavior

JS files should be validated with the javascript config even on projects using typescript.

Additional context

A workaround:

import { defineConfig } from 'eslint/config';
import { configs } from '@croct/eslint-plugin';

export default defineConfig(
    configs.javascript.map(
        config => ({
            files: ['**/*.{js,mjs,cjs}'],
            ...config,
        }),
    ),
    configs.typescript.map(
        config => ({
            files: ['**/*.{ts,mts,cts}'],
            ...config,
        }),
    ),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions