8000 Add custom lint rule to ensure import paths end with `.d.ts` extension by som-sm · Pull Request #1168 · sindresorhus/type-fest · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Add custom lint rule to ensure import paths end with .d.ts extension #1168

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

Merged
merged 2 commits into from
Jun 6, 2025

Conversation

som-sm
Copy link
Collaborator
@som-sm som-sm commented Jun 6, 2025
  • Adds an auto-fixable solution for Add lint rule to prevent .js / .ts extensions in import statements #1152, improving DX as mentioned in this comment.

    import-path-rule.mov
    image
  • Updates xo because there are some bugs in the existing version.

  • Enables the allowJS flag in tsconfig.json to ensure the xo.config.js file is checked. This shouldn't be a problem because we have noEmit enabled, so it shouldn't matter if .js files are part of the program. Also, this doesn't check all .js files for errors, only those that have the @ts-check directive.

  • This is kinda better than the no-restricted-imports rule, because that restricts certain extensions, whereas this enforces the desired one.
    And interestingly, it also catches some existing errors that weren't caught earlier. And these errors are not because of any of our recent changes, these were there since the very beginning.

    import type {Simplify} from './simplify.d.d.ts';
    import type {UnionToIntersection} from './union-to-intersection.d.d.ts';

    import type {IsNumberLike} from '../../source/internal/numeric.d.d.ts';

@som-sm som-sm requested a review from sindresorhus June 6, 2025 08:07
Comment on lines +3 to +5
export const importPathRule = /** @type {const} */ ({
meta: {
type: 'problem',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The /** @type {const} */ comment ensures that the inferred type of meta.type is 'problem' and not string, because otherwise there would be complaints in xo.config.js.

It would have been nice if XO exposed rule creation utilities (like ESLintUtils.RuleCreator.withoutDocs) from typescript-eslint, that would have ensured proper type safety on this rule. That said, even with that utility, we would have still required node types.

@som-sm
Copy link
Collaborator Author
som-sm commented Jun 6, 2025

Enables the allowJS flag in tsconfig.json to ensure the xo.config.js file is checked. This shouldn't be a problem because we have noEmit enabled, so it shouldn't matter if .js files are part of the program. Also, this doesn't check all .js files for errors, only those that have the @ts-check directive.

And this shouldn't cause slowdowns even when we disable skipLibCheck, because checkJS is still disabled, so it should only check files that have the @ts-check directive.


Also, on a different note, after the V5 updates, I remember seeing errors when skipLibCheck was disabled, but I don't see those errors anymore. Maybe the issue got fixed, so maybe we can disable that back?

@sindresorhus
Copy link
Owner

Also, on a different note, after the V5 updates, I remember seeing errors when skipLibCheck was disabled, but I don't see those errors anymore. Maybe the issue got fixed, so maybe we can disable that back?

Yeah, I think we can. I also saw errors, but not anymore.

@sindresorhus sindresorhus merged commit 57fef12 into main Jun 6, 2025
6 checks passed
@sindresorhus sindresorhus deleted the feat/add-lint-rule-for-import-path branch June 6, 2025 11:55
benzaria pushed a commit to benzaria/type-fest that referenced this pull request Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0