Skip to content

Commit

Permalink
feat: when specifying files from the CLI, ignore the equivalent confi…
Browse files Browse the repository at this point in the history
…g settings (#127)

This fixes an annoyance that was also causing trouble in the
decaffeinate-examples project. When specifying a path file, like the successful
files after `check`, it should only convert those files, not union them with the
existing config.
  • Loading branch information
alangpierce authored May 29, 2017
1 parent 7abea82 commit b142fcf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ If multiple of `searchDirectory`, `pathFile`, or `filesToProcess` are specified,
the union of the files is taken. If none is specified, bulk-decaffeinate will
recursively discover all CoffeeScript files in the working directory.

Each of these has a command line arg version; see the result of `--help` for
more information.
Each of these has a command line arg version, which takes precedence over config
file values; see the result of `--help` for more information.

### Other configuration

Expand Down
8 changes: 8 additions & 0 deletions src/config/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ function getCLIParamsConfig(config, commander) {
jscodeshiftPath,
eslintPath,
} = commander;
// As a special case, specifying files to process from the CLI should cause
// any equivalent config file settings to be ignored.
if ((file && file.length > 0) || dir || pathFile) {
config.filesToProcess = null;
config.searchDirectory = null;
config.pathFile = null;
}

if (file && file.length > 0) {
config.filesToProcess = file;
}
Expand Down
9 changes: 9 additions & 0 deletions test/bulk-decaffeinate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ describe('check', () => {
assertIncludes(stdout, 'All checks succeeded');
});
});

it('ignores config file paths when CLI arg paths are specified', async function() {
await runWithTemplateDir('search-directory-config', async function() {
let {stdout, stderr} = await runCli('check -f ./A.coffee');
assert.equal(stderr, '');
assertIncludes(stdout, 'Doing a dry run of decaffeinate on 1 file...');
assertIncludes(stdout, 'All checks succeeded');
});
});
});
1 change: 1 addition & 0 deletions test/examples/search-directory-config/A.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log 'Hello'
1 change: 1 addition & 0 deletions test/examples/search-directory-config/B.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log 'World'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
searchDirectory: '.',
};

0 comments on commit b142fcf

Please sign in to comment.