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

Running eslint without --fix still updates snapshots #14

Closed
BatuhanW opened this issue Jan 28, 2021 · 3 comments · Fixed by #113
Closed

Running eslint without --fix still updates snapshots #14

BatuhanW opened this issue Jan 28, 2021 · 3 comments · Fixed by #113
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(

Comments

@BatuhanW
Copy link
Contributor

BatuhanW commented Jan 28, 2021

Thanks for the great library!

The issue is, I'm changing one of the test types expecting them to throw an error. Then running eslint without --fix option. It still updates snapshots.

Edit: I found out that explicitly setting "expect-type/expect": ["error", { "disableExpectTypeSnapshotFix": false }] fixes the issue. It only generates snapshots with --fix.

Having no rule at all doesn't prevent snapshots to be generated.

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :( labels Aug 21, 2021
@JoshuaKGoldberg
Copy link
Owner

JoshuaKGoldberg commented Aug 21, 2021

I suspect this is the triggering code:

// Trick: Function `fix` is ALWAYS run, and result is collected. However RuleFix objects are only read if `--fix` is passed
get text() {
  if (!applied) {
    // Make sure we update snapshot only on first read of this object
    applied = true;
    if (!options.disableExpectTypeSnapshotFix) {
      updateTypeSnapshot(fileName, snapshotName, actual);
    }
  }
  return '';
},

Since then (2 years ago) ESLint has probably added some call to .text.

@JoshuaKGoldberg
Copy link
Owner

Adding the hacktoberfest label to this. I don't think it's a particularly easy issue (not good first issue), but we'll see. 😄

@JoshuaKGoldberg
Copy link
Owner

I'd asked about this in the ESLint Discord: https://discord.com/channels/688543509199716507/711686958635548723/1107343559981551788. Nothing we can use here was mentioned. Ah well.

JoshuaKGoldberg added a commit that referenced this issue Dec 19, 2023
## PR Checklist

- [x] Addresses an existing open issue: fixes #14
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Only adds a `fix()` function if `process.argv.includes("--fix")`. This
will therefore stop type snapshots from being updated automatically when
ESLint is run through the Node API, such as in an editor extension.

This is the best I can do without ESLint providing a native way for
rules to know whether they're in fix mode 😬. I don't like it. It's a
rough heuristic and I'll file a followup issue on improving it (that
will be blocked on ESLint's making an API, I assume).

This also isn't tested yet so I'll file a followup issue for that too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(
Projects
None yet
2 participants