Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1904] Add ESLint support for TypeScript imports #1905

Merged
merged 3 commits into from
Feb 19, 2023

Conversation

vvidday
Copy link
Contributor

@vvidday vvidday commented Feb 11, 2023

Fixes #1904

Proposed commit message

ESLint is currently not configured to properly support TypeScript
imports. This results in an error when importing local TypeScript files
with the file extension omitted, which is the default way to import
TypeScript files.

Let's configure ESLint to support TypeScript imports and enforce the
omission of file extensions for .ts and .js files. This will allow us to
pass the lint check while using the default import method, and enforce
consistency throughout the codebase.

Other information

Changes to .eslintrc.json

Adding plugin:import/typescript allows ESLint to properly resolve TypeScript imports that don't include the .ts file extension, which solves the "Unable to resolve path to module '../..'" error.

   "import/extensions": [
      "error",
      {
        "js": "never",
        "ts": "never"
      }
    ]

The above lines configure the import/extensions rule to make sure imports should never end with .js or .ts. If the rule is broken, it will be considered an error by ESLint. This solves the "Missing file extension for '../..'" error.

Others

The other changes are removing the .ts extensions from existing imports.

@vvidday vvidday marked this pull request as ready for review February 11, 2023 06:57
@vvidday vvidday requested a review from a team February 11, 2023 06:58
Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ckcherry23 ckcherry23 requested a review from a team February 11, 2023 07:16
@HCY123902 HCY123902 requested a review from a team February 13, 2023 04:32
Copy link
Contributor

@zhoukerrr zhoukerrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dcshzj dcshzj merged commit dd6e0e9 into reposense:master Feb 19, 2023
@github-actions
Copy link
Contributor

The following links are for previewing this pull request:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESLint support for TypeScript imports
6 participants