Skip to content

Commit

Permalink
feat: add an --allow-invalid-constructors option (#97)
Browse files Browse the repository at this point in the history
This is useful to check a repo for decaffeinate problems without needing a
config file.
  • Loading branch information
alangpierce authored Apr 8, 2017
1 parent ed6fccc commit 985811c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ some follow-up cleanups. Here's an example of checking the Hubot repo:
...
> cd hubot
> bulk-decaffeinate check
Discovering .coffee files in the current directory...
Trying decaffeinate on 18 files using 4 workers...
18/18 (7 failures so far)
Done!
7 files failed to convert:
src/adapters/shell.coffee
Doing a dry run of decaffeinate on 18 files...
18/18 (5 failures so far)
5 files failed to convert:
src/adapter.coffee
src/adapters/campfire.coffee
src/brain.coffee
src/listener.coffee
src/message.coffee
src/user.coffee
src/robot.coffee
test/brain_test.coffee
Wrote decaffeinate-errors.log and decaffeinate-results.json with more detailed info.
To open failures in the online repl, run "bulk-decaffeinate view-errors"
To open failures in the online repl, run "bulk-decaffeinate view-errors".
To convert the successful files, run "bulk-decaffeinate convert -p decaffeinate-successful-files.txt".
> bulk-decaffeinate view-errors
(7 browser tabs are opened, showing all failures.)
> bulk-decaffeinate check --allow-invalid-constructors
Doing a dry run of decaffeinate on 18 files...
18/18
All checks succeeded! decaffeinate can convert all 18 files.
Run "bulk-decaffeinate convert" to convert the files to JavaScript.
```

Once any failures are resolved (generally by tweaking the CoffeeScript to work
Expand Down
3 changes: 3 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export default function () {
.option('-d, --dir [path]',
`A directory containing files to decaffeinate. All .coffee files in
any subdirectory of this directory are considered for decaffeinate.`)
.option('--allow-invalid-constructors',
`If specified, the --allow-invalid-constructors arg is added when
invoking decaffeinate.`)
.option('--land-base [revision]',
`The git revision to use as the base commit when running the "land"
command. If none is specified, bulk-decaffeinate tries to use the
Expand Down
10 changes: 6 additions & 4 deletions src/config/resolveConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function resolveConfig(commander, requireValidFiles = true)
for (let filename of currentDirFiles) {
config = await applyPossibleConfig(filename, config);
}
config = Object.assign(config, getCLIParamsConfig(commander));
config = getCLIParamsConfig(config, commander);
let filesToProcess = await resolveFilesToProcess(config, requireValidFiles);
filesToProcess = resolveFileFilter(filesToProcess, config);
if (requireValidFiles) {
Expand Down Expand Up @@ -78,9 +78,8 @@ async function applyPossibleConfig(filename, config) {
/**
* Fill in a configuration from the CLI arguments.
*/
function getCLIParamsConfig(commander) {
let {file, pathFile, dir, landBase, decaffeinatePath, jscodeshiftPath, eslintPath} = commander;
let config = {};
function getCLIParamsConfig(config, commander) {
let {file, pathFile, dir, allowInvalidConstructors, landBase, decaffeinatePath, jscodeshiftPath, eslintPath} = commander;
if (file && file.length > 0) {
config.filesToProcess = file;
}
Expand All @@ -90,6 +89,9 @@ function getCLIParamsConfig(commander) {
if (pathFile) {
config.pathFile = pathFile;
}
if (allowInvalidConstructors) {
config.decaffeinateArgs = [...(config.decaffeinateArgs || []), '--allow-invalid-constructors'];
}
if (landBase) {
config.landBase = landBase;
}
Expand Down
4 changes: 4 additions & 0 deletions test/examples/invalid-subclass-constructor/A.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class A extends B
constructor: ->
@a = 1
super
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ console.log(x);
assert.equal((await exec('git rev-list --count HEAD'))[0].trim(), '4');
});
});

it('allows invalid constructors when specified', async function() {
await runWithTemplateDir('invalid-subclass-constructor', async function() {
await initGitRepo();
await runCliExpectSuccess('convert --allow-invalid-constructors');
});
});

it('does not allow invalid constructors when not specified', async function() {
await runWithTemplateDir('invalid-subclass-constructor', async function() {
await initGitRepo();
let {stderr} = await runCli('convert');
assertIncludes(stderr, 'Some files could not be convered with decaffeinate');
});
});
});

describe('fix-imports', () => {
Expand Down

0 comments on commit 985811c

Please sign in to comment.