Skip to content
This repository has been archived by the owner on May 6, 2018. It is now read-only.

Trailing space in comment breaks brackets-jscs #15

Closed
hacker112 opened this issue Mar 11, 2015 · 7 comments
Closed

Trailing space in comment breaks brackets-jscs #15

hacker112 opened this issue Mar 11, 2015 · 7 comments

Comments

@hacker112
Copy link

If there is a trailing space in a comment an "Unexpected token"-error is created in brackets-jscs.
This is not a problem when running JSCS in commandline.

// This line has a trailing space 
function a() {
    return;
}

jscs-brackets-trailing-space-error

@hacker112
Copy link
Author

And here is by the way the .jscs.json-config that was used if that helps

{
    "excludeFiles": ["frontend/app/bower_components", "frontend/node_modules", "frontend/instrument",
                     "frontend/dist", "frontend/.tmp", "frontend/coverage",
                     "backend/node_modules", "backend/coverage"],
    "disallowKeywords": ["with"],
    "disallowKeywordsInComments": ["TODO"],
    "disallowKeywordsOnNewLine": ["else"],
    "disallowMixedSpacesAndTabs": true,
    "disallowMultipleLineStrings": true,
    "disallowNewlineBeforeBlockStatements": true,
    "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"],
    "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
    "disallowSpacesInCallExpression": true,
    "disallowSpacesInsideParentheses": true,
    "maximumLineLength": 120,
    "requireBlocksOnNewline": true,
    "requireCapitalizedConstructors": true,
    "requireCommaBeforeLineBreak": true,
    "requireDotNotation": "except_snake_case",
    "requireLineBreakAfterVariableAssignment": true,
    "requireOperatorBeforeLineBreak": true,
    "requireParenthesesAroundIIFE": true,
    "requireSpaceBeforeBlockStatements": true,
    "requireSpaceBeforeKeywords": ["else", "while", "catch"],
    "requireSpaceBeforeObjectValues": true,
    "requireSpaceBetweenArguments": true,
    "requireSpacesInConditionalExpression": true,
    "requireSpacesInForStatement": true,
    "validateLineBreaks": "LF",
    "validateParameterSeparator": ", ",
    "validateQuoteMarks": "'"
}

@hacker112
Copy link
Author

I have now found that the error is in handleJSXJSCS (Probably in JSXTransformer.transform(text, {harmony: true}).code;)

I added some console output to confirm this

console.log('text', text);
console.log('JSXCode', JSXCode);
return handleJSCS(JSXCode, fullPath, config);

Which gives the output:

text // This line has a trailing space 
function a() {
    return;
}
JSXCode // This line has a trailing spacefunction a() {
    return;
}

My workaround until it is fixed is to change line 189 in main.js to (since I do not use harmony I hope guess that JSXTransformer.transform is not necessary for me):

return handleJSCS(text, fullPath, config);

@EvHaus
Copy link
Owner

EvHaus commented Mar 11, 2015

Looks like an issue with the JSXTransformer. I have opened a new bug with the Facebook team: facebook/react#3378

@hacker112
Copy link
Author

I think it is not JSXTransformer, but this line in handleJSXJSCS:

// Trim trailing whitespace
JSXCode = JSXCode.replace(/( +)\n/g, '');

If I remove it it works better.

Also Node-shebangs ( #!/usr/bin/env node\n ) are not handled correctly. It should be ignored if it is in the beginning of a file. I suggest the following in the beginning of the handleJSXJSCS-function:

text = text.replace(/^#!.+\n/m, '');

@EvHaus
Copy link
Owner

EvHaus commented Mar 12, 2015

A fix has been pushed for this. Please try v0.2.2 of the extension.

@EvHaus EvHaus closed this as completed Mar 12, 2015
@hacker112
Copy link
Author

The first problem is fixed now. But the other one is still a problem, I will create separate issue for that and a pull request.

@hacker112
Copy link
Author

Now you have a new problem. The rule:

{"disallowTrailingWhitespace": true}

does not work anymore. I will create a new issue for that.

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

No branches or pull requests

2 participants