Skip to content

Commit

Permalink
feat: add an option to skip the eslint step (#139)
Browse files Browse the repository at this point in the history
This is useful if you're not using eslint for whatever reason or to reduce the
total running time.

This also changes the requirements code to be a little smarter and not prompt to
install things that we don't need for the current operation.
  • Loading branch information
alangpierce committed Oct 30, 2017
1 parent 622cf76 commit a2927be
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ file values; see the result of `--help` for more information.
the `convert` command. This makes bulk-decaffeinate take less time, but if any
files fail to convert, it may leave the filesystem in a partially-converted
state.
* `skipEslintFix`: set to `true` to skip the ESLint step.

### Configuring paths to external tools

Expand Down
4 changes: 2 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ async function runCommand(command) {
let config = await resolveConfig(commander);
await check(config);
} else if (command === 'convert') {
let config = await resolveConfig(commander);
let config = await resolveConfig(commander, {needsJscodeshift: true, needsEslint: true});
await convert(config);
} else if (command === 'modernize-js') {
let config = await resolveConfig(commander);
let config = await resolveConfig(commander, {needsJscodeshift: true, needsEslint: true});
await modernizeJS(config);
} else if (command === 'view-errors') {
await viewErrors();
Expand Down
10 changes: 7 additions & 3 deletions src/config/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import execLive from '../util/execLive';
* Resolve the configuration from a number of sources: any number of config
* files and CLI options. Then "canonicalize" the config as much as we can.
*/
export default async function resolveConfig(commander) {
export default async function resolveConfig(commander, {needsJscodeshift, needsEslint} = {}) {
let config = {};

if (commander.config && commander.config.length > 0) {
Expand Down Expand Up @@ -42,9 +42,10 @@ export default async function resolveConfig(commander) {
landBase: config.landBase,
numWorkers: config.numWorkers || 8,
skipVerify: config.skipVerify,
skipEslintFix: config.skipEslintFix,
decaffeinatePath: await resolveDecaffeinatePath(config),
jscodeshiftPath: await resolveJscodeshiftPath(config),
eslintPath: await resolveEslintPath(config),
jscodeshiftPath: needsJscodeshift ? await resolveJscodeshiftPath(config) : null,
eslintPath: needsEslint ? await resolveEslintPath(config) : null,
};
}

Expand Down Expand Up @@ -167,6 +168,9 @@ async function resolveJscodeshiftPath(config) {
}

async function resolveEslintPath(config) {
if (config.skipEslintFix) {
return null;
}
if (config.eslintPath) {
return config.eslintPath;
}
Expand Down
4 changes: 3 additions & 1 deletion src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ Re-run with the "check" command for more details.`);
if (config.fixImportsConfig) {
thirdCommitModifiedFiles = await runFixImports(jsFiles, config);
}
await runEslintFix(jsFiles, config, {isUpdate: false});
if (!config.skipEslintFix) {
await runEslintFix(jsFiles, config, {isUpdate: false});
}
if (config.codePrefix) {
await prependCodePrefix(config, jsFiles, config.codePrefix);
}
Expand Down
4 changes: 3 additions & 1 deletion src/modernizeJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default async function modernizeJS(config) {
if (config.fixImportsConfig) {
await runFixImports(jsFiles, config);
}
await runEslintFix(jsFiles, config, {isUpdate: true});
if (!config.skipEslintFix) {
await runEslintFix(jsFiles, config, {isUpdate: true});
}

console.log(`Successfully modernized ${pluralize(jsFiles.length, 'file')}.`);
console.log('You should now fix lint issues in any affected files.');
Expand Down
7 changes: 7 additions & 0 deletions test/convert-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,11 @@ Proceeding anyway.`);
assert.equal((await exec('git rev-list --count HEAD'))[0].trim(), '4');
});
});

it('allows skipping eslint --fix', async function() {
await runWithTemplateDir('skip-eslint-fix', async function() {
const {stdout} = await runCliExpectSuccess('convert');
assert(!stdout.includes('Running eslint'), 'Expected eslint to be skipped.');
});
});
});
1 change: 1 addition & 0 deletions test/examples/skip-eslint-fix/A.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log 'Hello world'
3 changes: 3 additions & 0 deletions test/examples/skip-eslint-fix/bulk-decaffeinate.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipEslintFix: true,
};

0 comments on commit a2927be

Please sign in to comment.