-
Notifications
You must be signed in to change notification settings - Fork 46
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
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3781819
Nest runner inside src/runner
rogeliog e093c3c
WIP
rogeliog d48e06c
WIP
rogeliog fc41645
Better UX
rogeliog f938801
Add tests to watch plugin
rogeliog f5400ab
Update README.md
rogeliog dc8ff6e
Merge branch 'master' into eslint-watch-plugin
rogeliog c64f70a
Remove ora loading indicator and small style fixes
rogeliog ab18d77
Make getPrompt a closure
rogeliog 9391ea3
Change main file to infer the index.js
rogeliog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "jest-runner-eslint", | ||
"version": "0.6.0", | ||
"main": "build/index.js", | ||
"main": "build/runner/index.js", | ||
"author": "Rogelio Guzman <[email protected]>", | ||
"description": "An experimental ESLint runner for Jest", | ||
"license": "MIT", | ||
|
@@ -23,6 +23,7 @@ | |
"format": "prettier --write \"**/*.js\"" | ||
}, | ||
"dependencies": { | ||
"chalk": "^2.4.1", | ||
"cosmiconfig": "^5.0.0", | ||
"create-jest-runner": "^0.4.1", | ||
"eslint": "^5.6.0", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { createJestRunner } = require('create-jest-runner'); | ||
const configOverrides = require('../utils/configOverrides'); | ||
|
||
const runner = createJestRunner(require.resolve('./runESLint'), { | ||
getExtraOptions: () => ({ fix: configOverrides.getFix() }), | ||
}); | ||
|
||
module.exports = runner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class ConfigOverrides { | ||
setFix(fix) { | ||
this.fix = fix; | ||
} | ||
|
||
getFix() { | ||
return this.fix; | ||
} | ||
} | ||
|
||
const configOverrides = new ConfigOverrides(); | ||
|
||
module.exports = configOverrides; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable global-require */ | ||
const chalk = require('chalk'); | ||
|
||
jest.doMock('chalk', () => new chalk.constructor({ enabled: false })); | ||
|
||
jest.useFakeTimers(); | ||
|
||
let WatchFixPlugin; | ||
let configOverrides; | ||
|
||
describe('watchFixPlugin', () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
configOverrides = require('../../utils/configOverrides'); | ||
WatchFixPlugin = require('../'); | ||
}); | ||
|
||
it('shows the correct prompt', async () => { | ||
const stdout = { write: jest.fn() }; | ||
const config = {}; | ||
const plugin = new WatchFixPlugin({ stdout, config }); | ||
expect(plugin.getUsageInfo()).toEqual({ | ||
key: 'F', | ||
prompt: 'override ESLint --fix', | ||
}); | ||
|
||
await plugin.run(plugin); | ||
|
||
expect(plugin.getUsageInfo()).toEqual({ | ||
key: 'F', | ||
prompt: 'toggle ESLint --fix (enabled)', | ||
}); | ||
|
||
await plugin.run(plugin); | ||
|
||
expect(plugin.getUsageInfo()).toEqual({ | ||
key: 'F', | ||
prompt: 'toggle ESLint --fix (disabled)', | ||
}); | ||
}); | ||
|
||
it('overrides the setting in configOverrides after each invocation', async () => { | ||
const stdout = { write: jest.fn() }; | ||
const config = {}; | ||
const plugin = new WatchFixPlugin({ stdout, config }); | ||
expect(configOverrides.getFix()).toBeUndefined(); | ||
|
||
await plugin.run(plugin); | ||
|
||
expect(configOverrides.getFix()).toBe(true); | ||
|
||
await plugin.run(plugin); | ||
|
||
expect(configOverrides.getFix()).toBe(false); | ||
}); | ||
|
||
it('can customize the key', () => { | ||
const stdout = { write: jest.fn() }; | ||
const config = { key: 'z' }; | ||
const plugin = new WatchFixPlugin({ stdout, config }); | ||
expect(plugin.getUsageInfo()).toEqual({ | ||
key: 'z', | ||
prompt: 'override ESLint --fix', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const chalk = require('chalk'); | ||
const configOverrides = require('../utils/configOverrides'); | ||
|
||
class ESLintWatchFixPlugin { | ||
constructor({ stdout, config }) { | ||
this._stdout = stdout; | ||
this._key = config.key || 'F'; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
ljharb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async run() { | ||
const fix = configOverrides.getFix(); | ||
configOverrides.setFix(!fix); | ||
return true; | ||
} | ||
|
||
getUsageInfo() { | ||
return { | ||
key: this._key, | ||
prompt: this._getPrompt(), | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
_getPrompt() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
const fix = configOverrides.getFix(); | ||
if (fix === undefined) { | ||
return 'override ESLint --fix'; | ||
} | ||
if (!fix) { | ||
return `toggle ESLint --fix ${chalk.italic('(disabled)')}`; | ||
} | ||
return `toggle ESLint --fix ${chalk.italic('(enabled)')}`; | ||
} | ||
} | ||
|
||
module.exports = ESLintWatchFixPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const ESLintWatchFixPlugin = require('./build/watchFixPlugin'); | ||
|
||
module.exports = ESLintWatchFixPlugin; |
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.
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 can just be build/runner