Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [consistent-type-imports] import assertion checks added#7722

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

rielAsh24
Copy link
Contributor

Added type assertion for json files

PR Checklist

 

Overview

This PR addresses the issue wheretypescript-eslint/eslint-plugin throws an error when an import statement with type imports includes an import assertions.

Reproduction Code:

import*asaJsonfrom'./a.json' assert{type:'json'}constwhat:aJson.A;

Actual Behaviour

typescript-eslint provides an invalid TypeScript code as a fix and hence had to be addressed by adding a rule that checks for such import type assertions.

Expected Behaviour

Since typescript 4.5, import assertions are supported, soNo Error orAll is Ok is the expected output.

 

Changes made:

  1. Modified rule inconsistent-type-imports.ts for type only import. Now it checks for absence of assertions and only then suggests the fix.
// checks for presence of import assertionsif(node.assertions.length===0){yield*fixInsertTypeSpecifierForImportDeclaration(fixer,node,false);}
  1. Tweaked reporting conditions inconsistent-type-imports.ts for type only imports. Now it checks for absence of import assertions and only then reports the error.
/** checks if import has type assertions * ``` * import * as type from 'mod' assert { type: 'json' }; * ``` * https://github.com/typescript-eslint/typescript-eslint/issues/7527 */if(report.node.assertions.length===0){context.report({node:report.node,messageId:"typeOverValue",*fix(fixer){yield*fixToTypeImportDeclaration(fixer,report,sourceImports);}});}
  1. Added a rule toconsistent-type-imports.test.ts which considers import assertion for json files as a valid rule.
{code:`      import * as Type from 'foo' assert { type: 'json' };      const a: typeof Type = Type;    `,options:[{prefer:'no-type-imports'}],dependencyConstraints:{typescript:'4.5',},},

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@rielAsh24!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint.

@netlify
Copy link

netlifybot commentedOct 4, 2023
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit81f63d6
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/65269a352a2c260009d0fc9b
😎 Deploy Previewhttps://deploy-preview-7722--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@nx-cloud
Copy link

nx-cloudbot commentedOct 4, 2023
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit81f63d6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 19 targets

Sent with 💌 fromNxCloud.

@rielAsh24rielAsh24force-pushed theFix-7527_Import-assertions-fixed branch fromc7f375e toed1119fCompareOctober 4, 2023 14:23
@rielAsh24rielAsh24 changed the titlefix(eslint-plugin):[consistent-type-imports] Import assertion checks addedfix(eslint-plugin): [consistent-type-imports] Import assertion checks addedOct 5, 2023
@rielAsh24rielAsh24 changed the titlefix(eslint-plugin): [consistent-type-imports] Import assertion checks addedfix(eslint-plugin): [consistent-type-imports] import assertion checks addedOct 5, 2023
Added type assertion for json files
The linter checks for import assertions before suggesting fixes
@rielAsh24rielAsh24force-pushed theFix-7527_Import-assertions-fixed branch fromed1119f to81f63d6CompareOctober 11, 2023 12:50
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Thanks!

Lady on a boat saying 'this is glorious'

rielAsh24 and ValentinGurkov reacted with heart emoji
@JoshuaKGoldbergJoshuaKGoldberg merged commitafdae37 intotypescript-eslint:mainOct 11, 2023
@rielAsh24
Copy link
ContributorAuthor

rielAsh24 commentedOct 11, 2023
edited
Loading

Thanks!

Lady on a boat saying 'this is glorious'

Glad I could help! 😁

JoshuaKGoldberg reacted with heart emoji

@rielAsh24rielAsh24 deleted the Fix-7527_Import-assertions-fixed branchOctober 13, 2023 13:38
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsOct 21, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: [consistent-type-imports] Incorrectly suggestsimport type on import assertion
2 participants
@rielAsh24@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp