GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Fix] `exportMap`: export map cache is tainted by unreliable parse results by michaelfaith · Pull Request #3062 · import-js/eslint-plugin-import

Conversation

@michaelfaith

@michaelfaith michaelfaith commented Sep 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This change addresses an issue observed with the v9 upgrade, where the ExportMap Cache is being tainted with a bad export map, if the parse doesn't yield a visitorKeys (which can happen if an incompatible parser is used (e.g. og babel eslint)). If one run of the no-cycle rule uses an incompatible parser and taints the cache and a subsequent test is run with a compatible parser, then the bad export map will be found in the cache and used instead of attempting to proceed with the parse.

I don't think this is likely to occur in the wild, but in the event that it does, this should help. One thing to note, though: if someone is using an incompatible parser, then this change will have a performance impact, since it will attempt to create an export map every time, until it yields one that has visitorKeys attached.

I also updated the getExports test to use a valid parserPath, rather than a mocked one, so the tests are acting on a valid parserPath. Otherwise the export map won't be cached following this change and the test for it caching would fail.

Additional context: #2996 (comment)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@michaelfaith @ljharb
[Fix] exportMap: export map cache is tainted by unreliable parse re…
61f02a2
…sults

This change addresses and issue observed with the v9 upgrade, where the ExportMap Cache is being tainted with a bad export map, if the parse doesn't yield a `visitorKeys` (which can happen if an incompatible parser is used (e.g. og babel eslint)) for one run of the no-cycle rule.  If a subsequent test is run with a compatible parser, then the bad export map will be found in the cache and used instead of attempting to proceed with the parse.

I also updated the `getExports` test to use a valid parserPath, rather than a mocked one, so that the tests are acting on a valid parserPath.  Otherwise the export map won't be cached following this change.
@michaelfaith michaelfaith mentioned this pull request Sep 15, 2024
[New] support eslint 9 #2996
Merged
@michaelfaith

michaelfaith commented Sep 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

The test failures are from eslint 2 and 3, which I'm guessing doesn't yield a visitorKeys from the parse, causing the cache to be bypassed (failing the test that the export map is cached).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Sep 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.72%. Comparing base (5c9757c) to head (8117601).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3062      +/-   ##
==========================================
- Coverage   92.21%   90.72%   -1.50%     
==========================================
  Files          82       82              
  Lines        3557     3557              
  Branches     1244     1244              
==========================================
- Hits         3280     3227      -53     
- Misses        277      330      +53     
Flag Coverage Δ
90.72% <100.00%> (-1.50%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michaelfaith

michaelfaith commented Sep 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Another idea for how to approach this, to limit the impact to just the rules that need it:
we could add an additional optional param to ExportMapBuilder.get that takes a skip cache function, which takes an export map and returns a boolean for whether that instance of the map should be cached. no-cycle could then pass in (exportMap) => !exportMap.visitorKeys, which has the same effect, but limits it to only that rule.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

G-Rath
G-Rath reviewed Sep 15, 2024
View reviewed changes
Comment thread tests/src/core/getExports.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@G-Rath

G-Rath commented Sep 15, 2024

Copy link
Copy Markdown
Contributor

Confirming that this looks to address some of the test failures in #2996 - definitely the ones from no-cycle and probably others.

The test failures are from eslint 2 and 3

Could you just also check what version of ESLint is being used? as this seems to only take effect when using flat config and/or ESLint v9 which neither of those versions will support, and it feels like it could be more of a footgun to have rules control the cache

michaelfaith reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michaelfaith

michaelfaith commented Sep 15, 2024

Copy link
Copy Markdown
Contributor Author

Could you just also check what version of ESLint is being used? as this seems to only take effect when using flat config and/or ESLint v9 which neither of those versions will support, and it feels like it could be more of a footgun to have rules control the cache

Yeah, I like that too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljharb
ljharb approved these changes Sep 16, 2024
View reviewed changes

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This approach seems fine to me. If a version check is the cleanest way to handle this, that's fine, but it'd be much nicer to feature-test instead.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@michaelfaith
michaelfaith force-pushed the fix/exportmap-cache branch from e4c27ef to 76c11e6 Compare September 16, 2024 22:23
@michaelfaith michaelfaith changed the title fix(utils): export map cache is tainted by unreliable parse results fix(core): export map cache is tainted by unreliable parse results Sep 16, 2024
@michaelfaith

michaelfaith commented Sep 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

This approach seems fine to me. If a version check is the cleanest way to handle this, that's fine, but it'd be much nicer to feature-test instead.

Updated the tests to only run the caching test if we determine babel-eslint has visitor-keys.

cc @G-Rath you may want to pull this into your PR, to resolve the v2/v3 test errors.

G-Rath reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljharb
ljharb requested changes Sep 25, 2024
View reviewed changes
Comment thread tests/src/core/getExports.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/src/core/getExports.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@michaelfaith
michaelfaith force-pushed the fix/exportmap-cache branch 4 times, most recently from f6630cd to 89c3040 Compare September 25, 2024 22:22
@ljharb
ljharb force-pushed the fix/exportmap-cache branch 2 times, most recently from ebd6131 to 61f02a2 Compare September 25, 2024 22:59
ljharb
ljharb approved these changes Sep 25, 2024
View reviewed changes
@ljharb ljharb changed the title fix(core): export map cache is tainted by unreliable parse results [Fix] exportMap: export map cache is tainted by unreliable parse results Sep 25, 2024
@ljharb
ljharb merged commit 61f02a2 into import-js:main Sep 26, 2024
@michaelfaith
michaelfaith deleted the fix/exportmap-cache branch September 26, 2024 21:44
renovate Bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Oct 4, 2024
@renovate
Update dependency eslint-plugin-import to v2.31.0
698bf28
| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | eslint-plugin-import | 2.30.0 | 2.31.0 |


## [v2.31.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2310---2024-10-03)

##### Added

-   support eslint v9 (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)] \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`order`]: allow validating named imports (\[[#3043](import-js/eslint-plugin-import#3043)], thanks \[[@manuth](https://github.com/manuth)])
-   \[`extensions`]: add the `checkTypeImports` option (\[[#2817](import-js/eslint-plugin-import#2817)], thanks \[[@phryneas](https://github.com/phryneas)])

##### Fixed

-   `ExportMap` / flat config: include `languageOptions` in context (\[[#3052](import-js/eslint-plugin-import#3052)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`no-named-as-default`]: Allow using an identifier if the export is both a named and a default export (\[[#3032](import-js/eslint-plugin-import#3032)], thanks \[[@akwodkiewicz](https://github.com/akwodkiewicz)])
-   \[`export`]: False positive for exported overloaded functions in TS (\[[#3065](import-js/eslint-plugin-import#3065)], thanks \[[@liuxingbaoyu](https://github.com/liuxingbaoyu)])
-   `exportMap`: export map cache is tainted by unreliable parse results (\[[#3062](import-js/eslint-plugin-import#3062)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   `exportMap`: improve cacheKey when using flat config (\[[#3072](import-js/eslint-plugin-import#3072)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   adjust "is source type module" checks for flat config (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)])

##### Changed

-   \[Docs] \[`no-relative-packages`]: fix typo (\[[#3066](import-js/eslint-plugin-import#3066)], thanks \[[@joshuaobrien](https://github.com/joshuaobrien)])
-   \[Performance] \[`no-cycle`]: dont scc for each linted file (\[[#3068](import-js/eslint-plugin-import#3068)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] \[`no-cycle`]: add `disableScc` to docs (\[[#3070](import-js/eslint-plugin-import#3070)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Tests] use re-exported `RuleTester` (\[[#3071](import-js/eslint-plugin-import#3071)], thanks \[[@G-Rath](https://github.com/G-Rath)])
-   \[Docs] \[`no-restricted-paths`]: fix grammar (\[[#3073](import-js/eslint-plugin-import#3073)], thanks \[[@unbeauvoyage](https://github.com/unbeauvoyage)])
-   \[Tests] \[`no-default-export`], \[`no-named-export`]:  add test case (thanks \[[@G-Rath](https://github.com/G-Rath)])
renovate Bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Oct 4, 2024
@renovate
Update dependency eslint-plugin-import to v2.31.0
c755ad9
| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | eslint-plugin-import | 2.30.0 | 2.31.0 |


## [v2.31.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2310---2024-10-03)

##### Added

-   support eslint v9 (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)] \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`order`]: allow validating named imports (\[[#3043](import-js/eslint-plugin-import#3043)], thanks \[[@manuth](https://github.com/manuth)])
-   \[`extensions`]: add the `checkTypeImports` option (\[[#2817](import-js/eslint-plugin-import#2817)], thanks \[[@phryneas](https://github.com/phryneas)])

##### Fixed

-   `ExportMap` / flat config: include `languageOptions` in context (\[[#3052](import-js/eslint-plugin-import#3052)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   \[`no-named-as-default`]: Allow using an identifier if the export is both a named and a default export (\[[#3032](import-js/eslint-plugin-import#3032)], thanks \[[@akwodkiewicz](https://github.com/akwodkiewicz)])
-   \[`export`]: False positive for exported overloaded functions in TS (\[[#3065](import-js/eslint-plugin-import#3065)], thanks \[[@liuxingbaoyu](https://github.com/liuxingbaoyu)])
-   `exportMap`: export map cache is tainted by unreliable parse results (\[[#3062](import-js/eslint-plugin-import#3062)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   `exportMap`: improve cacheKey when using flat config (\[[#3072](import-js/eslint-plugin-import#3072)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])
-   adjust "is source type module" checks for flat config (\[[#2996](import-js/eslint-plugin-import#2996)], thanks \[[@G-Rath](https://github.com/G-Rath)])

##### Changed

-   \[Docs] \[`no-relative-packages`]: fix typo (\[[#3066](import-js/eslint-plugin-import#3066)], thanks \[[@joshuaobrien](https://github.com/joshuaobrien)])
-   \[Performance] \[`no-cycle`]: dont scc for each linted file (\[[#3068](import-js/eslint-plugin-import#3068)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] \[`no-cycle`]: add `disableScc` to docs (\[[#3070](import-js/eslint-plugin-import#3070)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Tests] use re-exported `RuleTester` (\[[#3071](import-js/eslint-plugin-import#3071)], thanks \[[@G-Rath](https://github.com/G-Rath)])
-   \[Docs] \[`no-restricted-paths`]: fix grammar (\[[#3073](import-js/eslint-plugin-import#3073)], thanks \[[@unbeauvoyage](https://github.com/unbeauvoyage)])
-   \[Tests] \[`no-default-export`], \[`no-named-export`]:  add test case (thanks \[[@G-Rath](https://github.com/G-Rath)])
@thlucas1 thlucas1 mentioned this pull request Oct 22, 2024
Bump eslint-plugin-import from 2.30.0 to 2.31.0 thlucas1/spotifyplus_card#3
Closed
@ManuelDevWeb ManuelDevWeb mentioned this pull request Oct 25, 2024
[Snyk] Upgrade eslint-plugin-import from 2.22.1 to 2.31.0 ManuelDevWeb/platziVideoReactRouterYRedux#339
Open
@indy2kro indy2kro mentioned this pull request Oct 25, 2024
[Snyk] Upgrade eslint-plugin-import from 2.30.0 to 2.31.0 indy2kro/laravel-git-hooks#14
Merged
@alhugot-azpn alhugot-azpn mentioned this pull request Oct 25, 2024
security(snyk): upgrade eslint-plugin-import from 2.30.0 to 2.31.0 emerson-eps/eslint-config#277
Merged
@qdraw qdraw mentioned this pull request Oct 25, 2024
[Snyk] Upgrade eslint-plugin-import from 2.30.0 to 2.31.0 qdraw/starsky#1785
Merged
@richyhoopd richyhoopd mentioned this pull request Oct 26, 2024
[Snyk] Upgrade eslint-plugin-import from 2.20.2 to 2.31.0 richyhoopd/Video-App#1239
Open
@ManuelDevWeb ManuelDevWeb mentioned this pull request Oct 26, 2024
[Snyk] Upgrade eslint-plugin-import from 2.22.1 to 2.31.0 ManuelDevWeb/platziVideoReact#339
Open
@Vishesh7797 Vishesh7797 mentioned this pull request Oct 27, 2024
[Snyk] Upgrade eslint-plugin-import from 2.14.0 to 2.31.0 Vishesh7797/material-ui#4
Open
@Exkaleburx Exkaleburx mentioned this pull request Oct 27, 2024
[Snyk] Upgrade eslint-plugin-import from 2.20.1 to 2.31.0 Exkaleburx/plug-and-klay#19
Open
@Mastermindzh Mastermindzh mentioned this pull request Oct 27, 2024
[Snyk] Upgrade eslint-plugin-import from 2.26.0 to 2.31.0 Mastermindzh/eslint-config#47
Closed
@DadonStyle DadonStyle mentioned this pull request Oct 27, 2024
[Snyk] Upgrade eslint-plugin-import from 2.25.4 to 2.31.0 DadonStyle/Crypto-Tower-FE#37
Open
This was referenced Oct 28, 2024
[Snyk] Upgrade eslint-plugin-import from 2.29.1 to 2.31.0 nodeshift/kube-service-bindings#242
Closed
[Snyk] Upgrade eslint-plugin-import from 2.27.5 to 2.31.0 nodeshift/opossum#902
Closed
@github-actions github-actions Bot mentioned this pull request Oct 30, 2024
chore: release eslint-plugin-import-x un-ts/eslint-plugin-import-x#172
Merged
renovate Bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Oct 30, 2024
@renovate
fix(deps): update dependency eslint-plugin-import-x to v4.4.0
9731285
##### [v4.4.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#440)

##### Minor Changes

-   [#169](un-ts/eslint-plugin-import-x#169) [`9c58269`](un-ts/eslint-plugin-import-x@9c58269) Thanks [@teidesu](https://github.com/teidesu)! - Add new rule option `checkTypedImports` for `extensions`, backports import-js/eslint-plugin-import#2817

##### Patch Changes

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Perf: avoid regexp during parser choosing

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Add extra guard for rule `no-named-as-default`. A few guards are borrowed from import-js/eslint-plugin-import#3032, but we don't sync the rest of changes from upstream since we have already implemented a way more performant check.

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - More test cases for `no-named-export` and `no-defualt-export` rule specifically with non-module `sourceType`

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `export` when there is only one `TSDeclareFunction` (import-js/eslint-plugin-import#3065)

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Prevent `ExportMap`'s cache is being tainted by incompatible parser (e.g. old `babel-eslint`). The cache is now skipped w/ incompatible parsers, which might introduce performance impacts only for those who are using incompatible parsers. (import-js/eslint-plugin-import#3062)

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Docs: fix a few typos here and there

-   [#168](un-ts/eslint-plugin-import-x#168) [`5de039c`](un-ts/eslint-plugin-import-x@5de039c) Thanks [@hyoban](https://github.com/hyoban)! - Fixes un-ts/eslint-plugin-import-x#167, the `no-duplicates` rule now allows co-existing inline type imports and namespace imports.

-   [#171](un-ts/eslint-plugin-import-x#171) [`9715220`](un-ts/eslint-plugin-import-x@9715220) Thanks [@SukkaW](https://github.com/SukkaW)! - Properly fix espree parser w/ ESLint Flat Config
@thlucas1 thlucas1 mentioned this pull request Nov 1, 2024
Bump eslint-plugin-import from 2.29.1 to 2.31.0 thlucas1/homeassistantcomponent_soundtouchplus_card#23
Closed
@DadonStyle DadonStyle mentioned this pull request Nov 3, 2024
[Snyk] Upgrade eslint-plugin-import from 2.25.4 to 2.31.0 DadonStyle/Crypto-Tower-FE#42
Open
@dpesall dpesall mentioned this pull request Nov 6, 2024
[Snyk] Upgrade eslint-plugin-import from 2.29.1 to 2.31.0 nasa/cmr-stac#377
Open
@Luis-Kristen Luis-Kristen mentioned this pull request Nov 7, 2024
[Snyk] Upgrade eslint-plugin-import from 2.20.1 to 2.31.0 Luis-Kristen/feature-react#207
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ljharb ljharb ljharb approved these changes
+1 more reviewer
@G-Rath G-Rath G-Rath left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@michaelfaith @G-Rath @ljharb
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.