Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Preserve .eslintcache on fixes #898

Merged
merged 2 commits into from
May 3, 2017
Merged

Preserve .eslintcache on fixes #898

merged 2 commits into from
May 3, 2017

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented May 1, 2017

Fixes #635

The main point of this PR is to avoid deleting the .eslintcache file when performing fix jobs in linter-eslint. Previously, they were deleted because if ESLint is run without the cache option, it will automatically delete any existing cache files. linter-eslint doesn't delete the cache on regular lint jobs because it uses executeOnText, which bypasses the cache and does not delete it.

Update: I've changed this PR to use executeOnText for fix jobs as suggested by @not-an-aardvark in #873 (comment). It's a much better solution than my first approach.

The approach I took was fairly simplistic. We will search for a .eslintcache file, and if we find it, we will set cache for fix jobs. There is a slight danger here that we may create extra .eslintcache files in unexpected locations, because that setting will also create cache files if none exist. In my own testing so far I haven't experienced that problem, but we should be on the lookout for it in more complicated project structures.

At this time I think it's reasonable to only consider files named .eslintcache, as that is the default and most common. If there is overwhelming demand for a config setting, we can consider that, but for now I'd like to keep it as simple as possible.

@IanVS IanVS requested a review from Arcanemagus May 1, 2017 05:38
@IanVS
Copy link
Member Author

IanVS commented May 1, 2017

Now that I think about this a little more, we should probably explore using executeOnText for fixes as suggested in #873 (comment). That would be a more robust solution than what I'm doing here, and is worth a shot.

Also, I guess the Appveyor spec failure is the same race condition failure that caused us to disable the other test in that suite. Maybe breaking them into separate describe blocks will help… I'll try it later.

@Arcanemagus
Copy link
Member

That's a bizarre failure in the AppVeyor build, it looks like it grabbed the notification for one of the debug tooltip tests, I'm not entirely sure we can actually fix that within the limitations of Jasmine 1.3 that Atom uses 😕.

src/main.js Outdated
// Abort for invalid or unsaved text editors
atom.notifications.addError('Linter-ESLint: Please save before fixing')
Copy link
Member Author

Choose a reason for hiding this comment

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

Note, we can now perform fixes on unsaved text!

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a small caveat here. If you make a change to introduce a linting error within a previously-passing file without saving, and the fix results in the same code as what was previously saved, manually running a fix command will have no visible effect in the editor. That's because the file on disk will essentially not be changed, and so Atom won't know to reload the editor. I think that's a small enough edge case that we don't need to worry about it, but wanted to make you aware.

@IanVS IanVS force-pushed the issue635-preserve-cache branch 2 times, most recently from 68993c0 to 1fff6c8 Compare May 2, 2017 03:21
@IanVS IanVS force-pushed the issue635-preserve-cache branch from 1fff6c8 to 72c0f1d Compare May 2, 2017 03:59
Copy link
Member

@Arcanemagus Arcanemagus left a comment

Choose a reason for hiding this comment

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

As noted in chat, the second usage of makeFixes potentially triggering the Atom internals bug has no effect on this spec as we don't care about the contents of the file being fixed for this new spec.

fs.createReadStream(fileToCopyPath).pipe(ws)
})
}

function copyFileToTempDir(fileToCopyPath) {
Copy link
Member

Choose a reason for hiding this comment

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

docbloc this?

src/worker.js Outdated
@@ -36,8 +36,8 @@ function lintJob({ cliEngineOptions, contents, eslint, filePath }) {
: cliEngine.executeOnFiles([filePath])
Copy link
Member

Choose a reason for hiding this comment

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

Closest I can get to commenting while still be in the PR:

contents will always be a string now, so this entire check is irrelevant now.

@IanVS IanVS force-pushed the issue635-preserve-cache branch from e1e158a to 62f416f Compare May 2, 2017 14:20
@IanVS
Copy link
Member Author

IanVS commented May 2, 2017

@Arcanemagus thanks for the review. I've addressed your feedback and squashed commits.

@Arcanemagus
Copy link
Member

Currently although we can get the list of fixes for an unsaved buffer, since we are using CLIEngine.outputFixes() to apply them, we must still have the buffer be saved when running or it appears nothing happens. (Or worse, it tries to apply fixes from the unsaved buffer to the saved state on disk, with potentially disastrous results.)

@IanVS
Copy link
Member Author

IanVS commented May 3, 2017

Hah! I spend a few minutes in your non-compiling branch, and now I'm already forgetting to check in compiled files!

@IanVS IanVS force-pushed the issue635-preserve-cache branch from 34008d2 to 862dcc1 Compare May 3, 2017 03:11
There’s no need for it to also handle opening the file.
We may not always want to copy and then also immediately open it.
@IanVS IanVS force-pushed the issue635-preserve-cache branch from 862dcc1 to 4ff4b82 Compare May 3, 2017 03:21
This prevents ESLint from deleting the users cache file, because
`executeOnText` bypasses the cache logic in ESLint entirely.
@IanVS IanVS force-pushed the issue635-preserve-cache branch from 4ff4b82 to 580e569 Compare May 3, 2017 03:23
@IanVS IanVS merged commit 8b44cad into master May 3, 2017
@IanVS IanVS deleted the issue635-preserve-cache branch May 3, 2017 03:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants