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

Watch plugin for toggling --fix #53

Merged
merged 10 commits into from
Oct 1, 2018
Merged

Watch plugin for toggling --fix #53

merged 10 commits into from
Oct 1, 2018

Conversation

rogeliog
Copy link
Member

@rogeliog rogeliog commented Sep 28, 2018

Fixes #43

I was originally thinking of a more fully featured watch plugin #43 (comment), but I was not happy with that UX.

Given that --fix is the most common request, I think it makes sense to start with a --fix plugin, and if need be we can work on another one later.

fix

  • This PR depends on Upgrade all dependencies and remove transpilation step #49, so disregard the babel@7 stuff, I'll rebase once that is merged.
  • I intentionally left the plugin in jest-runner-eslint/watch-fix instead of jest-runner-eslint/watch to leave room for more plugins.
  • The way the plugin and the runner communicate is through configOverrides, I would love to get some feedback on this. I'm not a fan of it, but we need a way that they can both access shared state... Other ideas are more than welcome.
  • One limitation or known issue is: We don't know initially what the current value of --fix is in the config. Given this, I decided to show a different message until the user enables the toggling. I think that the UX is still fine.

@rogeliog rogeliog requested review from SimenB and ljharb September 28, 2018 00:30
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

This is awesome!

I agree configOverrides is weird. I think we really need jestjs/jest#4278, and make sure that watch plugins are able read it, and vice versa.

Probably some shared config spot for custom stuff so we don't pollute globalConfig, but still allow custom runners and plugins to communicate and have their own config without resorting to weird stateful modules and manual cosmiconfig

};
}

async _showLoading(fix) {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added that loading indicator, because I felt that it provided a smoother experience (See the bottom part of the gif in the PR description) I'm happy to remove it you feel like it would be better without it.

Copy link
Member

Choose a reason for hiding this comment

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

It looks slick, but does it do anything? Other than delay for a tiny bit

Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason was to provide an indicator and feedback of what is happening, but I guess you are right... none of the other Jest keys does that, I just removed it.

@@ -24,7 +24,7 @@ const runESLintRunnerWithMockedEngine = options => {
});
const runESLint = require('../runESLint');

return runESLint(options.runESLint);
return runESLint(Object.assign({ extraOptions: {} }, options.runESLint));
Copy link
Member

Choose a reason for hiding this comment

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

object spread?

README.md Outdated
@@ -172,6 +193,8 @@ module.exports = {
}
```

###
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️

fix: getComputedFixValue(cliOptions),
}),
const { cliOptions: baseCliOptions } = getESLintOptions(config);
const cliOptions = Object.assign(
Copy link
Member

Choose a reason for hiding this comment

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

object spread


const runAndAwait = async plugin => {
const runPromise = plugin.run();
await jest.runTimersToTime(700);
Copy link
Member

Choose a reason for hiding this comment

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

we have runAllPendingTimers and runAllTimers instead of hardcoding the values

Copy link
Member

Choose a reason for hiding this comment

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

They also don't return promises, so you can drop the await

src/watchFixPlugin/index.js Show resolved Hide resolved
@rogeliog rogeliog force-pushed the eslint-watch-plugin branch from 8ba5cb6 to c64f70a Compare October 1, 2018 05:40
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Woooooo!

@rogeliog
Copy link
Member Author

rogeliog commented Oct 1, 2018

@ljharb Any thoughts?

package.json Outdated
@@ -1,7 +1,7 @@
{
"name": "jest-runner-eslint",
"version": "0.6.0",
"main": "build/index.js",
"main": "build/runner/index.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

this can just be build/runner

}

// eslint-disable-next-line class-methods-use-this
_getPrompt() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why can’t this be a closed over function instead of a fake private method?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@rogeliog rogeliog merged commit 61b9dfd into master Oct 1, 2018
@@ -15,23 +15,22 @@ class ESLintWatchFixPlugin {
}

getUsageInfo() {
const getPrompt = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is defined at module level, then it should be a bit faster.

@SimenB SimenB deleted the eslint-watch-plugin branch October 1, 2018 20:49
@SimenB
Copy link
Member

SimenB commented Oct 1, 2018

(we should do #54 before releasing this, BTW)

@rogeliog
Copy link
Member Author

rogeliog commented Oct 2, 2018

@SimenB Perfect!

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.

Watch Mode Plugin: jest-runner-eslint/watch
3 participants