Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

CLI: Add --esprima option. #708 #711

Closed
wants to merge 1 commit into from
Closed

Conversation

koistya
Copy link
Contributor

@koistya koistya commented Oct 22, 2014

Currently you cannot use csjs with JSX (ReactJS) files:

var React = require('react');
module.exports = React.createClass({
  render() {
    return <div>Hello</div>;
  }
});
Unexpected token < at ./src/components/test.jsx :
      3 |  render() {
      4 |    return <div>Hello</div>;
--------------------^

If you could provide a custom Esprima version via CLI or .jscsrc file, that would fix the problem:

at the CLI:

jscs --esprima=esprima-fb

in .jscsrc

{
  "esprima": "esprima-fb"
}

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) when pulling da794b5 on koistya:esprima into d1a246b on jscs-dev:master.

@mdevils
Copy link
Member

mdevils commented Oct 22, 2014

Hello! Thank you for your submission.

StringChecker cannot include non-precalculated requires as it is used to build browser-version.

You only can do this in Checker.

Also, the base path for the require should be process.cwd().

@mikesherov
Copy link
Contributor

Also, there needs to be tests for this, and as well, you need to actually add the esprima option to the bin/jscs

@mikesherov
Copy link
Contributor

Thanks again @koistya. I appreciate the effort you've put forth here.

Instead of looking for a string type in constructor, you should follow the conventions we have for new options: it needs to work from both .jscsrc and the cli, it needs a module to consume the option and remove it off of the config option, and then you need a set of unit tests to make sure your change works.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) when pulling 4e3161b on koistya:esprima into 7965275 on jscs-dev:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) when pulling 46d0cc3 on koistya:esprima into 7965275 on jscs-dev:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) when pulling 9b8cf69 on koistya:esprima into 7965275 on jscs-dev:master.

@koistya koistya changed the title Allow to specify a esprima version via CLI. #708 CLI: Add --esprima option. #708 Oct 23, 2014
@koistya koistya force-pushed the esprima branch 3 times, most recently from 890e096 to 4ae0a5a Compare October 23, 2014 08:23
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) when pulling 4ae0a5a on koistya:esprima into 7965275 on jscs-dev:master.

@koistya
Copy link
Contributor Author

koistya commented Oct 23, 2014

@mikesherov, @mdevils take a look now, is this something you would be willing to merge? If so, I will try to add tests.

@@ -32,6 +38,11 @@ Checker.prototype.configure = function(config) {
excludeFiles(config, this, cwd);
additionalRules(config, this, cwd);
esnext(config);
esprima(config);

if (typeof config.esprima === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be done inside the options configuration module.

@mikesherov
Copy link
Contributor

It's definitely something we'll be merging. However, there are still a few nits to work out.

Either way, you should write tests anyway because we know what the external API already is, and it will help us review what work you've done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) when pulling 1b160af on koistya:esprima into 7965275 on jscs-dev:master.

@@ -25,7 +25,8 @@ module.exports = function(program) {
var promise = defer.promise();
var checker = new Checker({
verbose: program.verbose,
esnext: program.esnext
esnext: program.esnext,
esprima: program.esprima
Copy link
Contributor

Choose a reason for hiding this comment

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

This is why I need to see some tests :-) Currently, passing a string here will explode, no?

@mikesherov
Copy link
Contributor

@koistya, thanks again for contributing! Please write the following tests before I review again:

  1. --esprima option to the cli.
  2. esprima as an option in .jscsrc.

@koistya
Copy link
Contributor Author

koistya commented Oct 24, 2014

I just have tested manually with both CLI and .jscsrc option, works fine.

@koistya koistya force-pushed the esprima branch 3 times, most recently from 4d223f4 to b5309cc Compare October 24, 2014 11:49
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) when pulling b5309cc on koistya:esprima into 041d1ee on jscs-dev:master.

@koistya koistya force-pushed the esprima branch 3 times, most recently from 85d811a to 4833995 Compare October 24, 2014 12:44
@koistya
Copy link
Contributor Author

koistya commented Oct 24, 2014

I'm wondering, why does this unit test fail with Error: timeout of 2000ms exceeded

it('should use a custom esprima provided in the config file', function(done) {
    var data = 'import { foo } from "bar";\n';

    var result = cli({
        args: [],
        'no-colors': true,
        config: 'test/data/cli/esprima.json'
    });

    process.stdin.emit('data', data);
    process.stdin.emit('end');

    return result.promise.always(function() {
        assert(console.log.getCall(0).args[0] === 'No code style errors found.');
        rAfter();
        done();
    });
});


beforeEach(function() {
sinon.spy(console, 'log');
process.stdin.isTTY = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just have copied from the existing test above.

Copy link
Contributor

Choose a reason for hiding this comment

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

remove it then. :-)

@mikesherov
Copy link
Contributor

I'm wondering, why does this unit test fail with Error: timeout of 2000ms exceeded

Maybe has something to do with setting isTTY unnecessarily?

@@ -113,6 +113,12 @@ module.exports = function(program) {
return returnArgs;
}

if (program.esprima && typeof program.esprima === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can just be if (typeof program.esprima === 'string') {

@koistya
Copy link
Contributor Author

koistya commented Oct 24, 2014

Removing isTTY didn't make any difference.

@@ -113,6 +113,12 @@ module.exports = function(program) {
return returnArgs;
}

if (program.esprima && typeof program.esprima === 'string') {
config.esprima = require(program.esprima);
} else if (config.esprima && typeof config.esprima === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

this can just be } else if (typeof config.esprima === 'string') {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I guess config is always defined at this point.

@mikesherov
Copy link
Contributor

@koistya thanks for sticking with this.

@mikesherov
Copy link
Contributor

@koistya perhaps it's because you haven't added any rules?

@koistya
Copy link
Contributor Author

koistya commented Oct 26, 2014

@mikesherov I just copied a unit test from above and replaced the input string with import { foo } from "bar"; It fails with a timeout error. I checked the code manually, it works with both --esprima CLI flag and "esprima" setting in .jscsrc config file (valided JSX code by using 'esprima-fb' esprima setting). But I don't know how to make the unit test work.

@mikesherov
Copy link
Contributor

@koistya, no worries. I'll take it the rest of way. Thanks again for contributing!

@markelog
Copy link
Member

markelog commented Nov 5, 2014

@mikesherov ?

@mikesherov
Copy link
Contributor

Was waiting for config to land. Will pick this up tomorrow.

@mikesherov
Copy link
Contributor

@koistya Thanks again for contributing! I landed a modified patch here: bdc5ff0 Still giving you the credit though as you did a majority of the work. Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants