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

v3.0.3 throws "Cannot read property 'replace' of undefined" #2219

Closed
EvHaus opened this issue Apr 15, 2016 · 19 comments
Closed

v3.0.3 throws "Cannot read property 'replace' of undefined" #2219

EvHaus opened this issue Apr 15, 2016 · 19 comments
Labels

Comments

@EvHaus
Copy link

EvHaus commented Apr 15, 2016

After upgrading to 3.0.2, I can't seem to be able to get JSCS to work. Running the jscs CLI returns this error:

TypeError: Cannot read property 'replace' of undefined
    at renderLine (/Users/test/my_project/node_modules/jscs/lib/errors.js:266:16)
    at Object.Errors.explainError (/Users/test/my_project/node_modules/jscs/lib/errors.js:197:13)
    at /Users/test/my_project/node_modules/jscs/lib/reporters/console.js:16:36
    at Array.forEach (native)
    at /Users/test/my_project/node_modules/jscs/lib/reporters/console.js:14:35
    at Array.forEach (native)
    at Object.module.exports [as writer] (/Users/test/my_project/node_modules/jscs/lib/reporters/console.js:9:22)
    at /Users/test/my_project/node_modules/jscs/lib/cli.js:149:18
    at Array.<anonymous> (/Users/test/my_project/node_modules/vow/lib/vow.js:712:56)
    at Immediate.callFns [as _onImmediate] (/Users/test/my_project/node_modules/vow/lib/vow.js:23:35)

My .jscsrc is:

{
    "excludeFiles": [
        "html/build/**",
        "html/js/examples/**",
        "html/test/jasmine-2.4.1/**"
    ],

    "disallowKeywords": ["with"],
    "disallowMultipleLineStrings": true,
    "disallowNamedUnassignedFunctions": true,
    "disallowNewlineBeforeBlockStatements": true,
    "disallowOperatorBeforeLineBreak": ["."],
    "disallowQuotedKeysInObjects": "allButReserved",
    "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "~"],
    "disallowSpaceBeforeBinaryOperators": ["!"],
    "disallowSpacesInsideArrayBrackets": "all",
    "disallowSpacesInsideBrackets": true,
    "disallowSpacesInsideObjectBrackets": "all",
    "disallowTrailingComma": true,
    "disallowTrailingWhitespace": true,
    "requireAnonymousFunctions": true,
    "requireCapitalizedConstructors": true,
    "requireCommaBeforeLineBreak": true,
    "requireCurlyBraces": ["for", "try", "catch"],
    "requireLineBreakAfterVariableAssignment": true,
    "requireOperatorBeforeLineBreak": ["?", "=", "+", "-", "/", "*", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
    "requirePaddingNewLinesAfterUseStrict": true,
    "requirePaddingNewLinesBeforeExport": true,
    "requireParenthesesAroundIIFE": true,
    "requireSpaceAfterKeywords": ["do", "for", "else", "switch", "case", "void", "while", "with", "typeof", "function"],
    "requireSpaceBeforeKeywords": ["else", "while"],
    "requireSpaceBeforeObjectValues": true,
    "requireSpacesInConditionalExpression": {
        "afterTest": true,
        "beforeConsequent": true,
        "afterConsequent": true,
        "beforeAlternate": true
    },
    "requireSpacesInForStatement": true,
    "requireSpacesInFunctionDeclaration": {
        "beforeOpeningRoundBrace": true,
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInNamedFunctionExpression": {
        "beforeOpeningCurlyBrace": true
    },
    "safeContextKeyword": ["self", "_this"],
    "validateAlignedFunctionParameters": {
        "lineBreakAfterOpeningBraces": true,
        "lineBreakBeforeClosingBraces": true
    },
    "validateIndentation": "\t",
    "validateParameterSeparator": ", "
}
@hzoo
Copy link
Member

hzoo commented Apr 15, 2016

I thought we fixed this one @mdevils?

@koistya
Copy link
Contributor

koistya commented Apr 16, 2016

I have the same issue in react-starter-kit after upgrading to 3.0.2

@hzoo hzoo added the bug label Apr 16, 2016
@koistya
Copy link
Contributor

koistya commented Apr 17, 2016

3.0.3 doesn't fix it, take a look https://travis-ci.org/kriasoft/react-starter-kit/builds/123586977

@mdevils
Copy link
Member

mdevils commented Apr 17, 2016

@hzoo I though so

Will take a look soon

@louh
Copy link

louh commented Apr 20, 2016

This has been happening for me for any version in the 3.0.x series.

I went through my codebase and ran jscs on each file until I discovered which file was causing the error to occur, and then through each function inside that file until I narrowed down the root cause. It seems that this object destructuring assignment inside of a function parameter causes the error: https://github.com/tangrams/tangram-play/blob/master/src/js/map/map.js#L80

This is valid ES6 and has been addressed before.

I created a very minimal test case so you can duplicate the error:

export function myFunction ({ foo = false, bar = null } = {}) {
    console.log(foo, bar);
}

See here:
https://gist.github.com/louh/0b2e74228c141afc4a34b70d3e944254

@kaievns
Copy link

kaievns commented Apr 21, 2016

still happening in 3.0.3

@Yixi
Copy link

Yixi commented Apr 27, 2016

I have same problem use with react

@Grygir
Copy link

Grygir commented Apr 27, 2016

Same error for static property definition (in jscs 3.0.3)

class Bar {
    static test = {
        foo: 'bar'
    };
}

That seems to be valid code.

TypeError: Cannot read property 'replace' of undefined
    at renderLine (/var/www/test/node_modules/jscs/lib/errors.js:266:16)
    at Object.Errors.explainError (/var/www/test/node_modules/jscs/lib/errors.js:197:13)
    at /var/www/test/node_modules/jscs/lib/reporters/console.js:16:36
    at Array.forEach (native)
    at /var/www/test/node_modules/jscs/lib/reporters/console.js:14:35
    at Array.forEach (native)
    at Object.module.exports [as writer] (/var/www/test/node_modules/jscs/lib/reporters/console.js:9:22)
    at /var/www/test/node_modules/jscs/lib/cli.js:149:18
    at Array.<anonymous> (/var/www/test/node_modules/vow/lib/vow.js:712:56)
    at Immediate.callFns [as _onImmediate] (/var/www/test/node_modules/vow/lib/vow.js:23:35)

@EvHaus EvHaus changed the title v3.0.2 throws "Cannot read property 'replace' of undefined" v3.0.x throws "Cannot read property 'replace' of undefined" May 8, 2016
@EvHaus EvHaus changed the title v3.0.x throws "Cannot read property 'replace' of undefined" v3.0.3 throws "Cannot read property 'replace' of undefined" May 8, 2016
@r-murphy
Copy link

I got the same error when using esnext bind expression, which doesn't seem to be supported in cst used by jscs 3.0. Whenever there is a parse error (error.rule === "parseError"), the error has no line number.

The fixed I applied temporarily to my jscs install was this, which a least prints the underlying reason for the parse error. I'm not sure if that's the best place for the fix or if it should be as soon as the parse error is detected.

explainError: function(error, colorize) {
  if (typeof error.line === 'undefined') {
    //probably a parseError, so include the rule name
    return formatErrorMessage(error.rule + ': ' + error.message, this.getFilename(), colorize);
  }
  //... the rest 
}

@markelog
Copy link
Member

There is lot of different errors here and they about different things, like

export function myFunction ({ foo = false, bar = null } = {}) {
    console.log(foo, bar);
}

Is cst/cst#118

static properties is about - cst/cst#112

And so on.

After cst/cst#116 and with 729db94, errors will be outputted in a friendly manner

@markelog markelog removed the bug label May 13, 2016
@UnsungHero97
Copy link

pulling in the latest changes from master fixed this issue for me:

"devDependencies": {
  ...
  "jscs": "git:github.com/jscs-dev/node-jscs.git",
  ...
}

@qfox
Copy link
Member

qfox commented May 16, 2016

This is enough:

"devDependencies": {
  ...
  "jscs": "jscs-dev/node-jscs",
  ...
}

@UnsungHero97
Copy link

@zxqfox cool, thanks!

@szebrowski
Copy link

For me problem still occurs. Even on the jscs-dev/node-jscs version. It's hard for me to paste example code because project is too large.

@lf94
Copy link

lf94 commented May 20, 2016

Reporting in the same. Version 3.0.3. May move to ESLint as suggested though on the blog. For now I'm using the fix people have suggested.

@qfox
Copy link
Member

qfox commented May 20, 2016

We gonna publish 3.0.4 in a few days with a fix (we hope). Can you please try master branch?

@szebrowski
Copy link

I will try it on Monday (just finished work;)
On 20 May 2016 4:06 pm, "Alexej Yaroshevich" notifications@github.com
wrote:

We gonna publish 3.0.4 in a few days with a fix (we hope). Can you please
try master branch?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#2219 (comment)

@szebrowski
Copy link

Unfortunatly, I still get 'replace' of undefined error. :(

On Fri, May 20, 2016 at 4:17 PM Sebastian mergol@gmail.com wrote:

I will try it on Monday (just finished work;)
On 20 May 2016 4:06 pm, "Alexej Yaroshevich" notifications@github.com
wrote:

We gonna publish 3.0.4 in a few days with a fix (we hope). Can you please
try master branch?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#2219 (comment)

@szebrowski
Copy link

szebrowski commented May 23, 2016

Most basic example to get the error:

var m = require('mori');

function getTrNid(trNid, saveRes) {
  return trNid < 0
        ? m.getIn(saveRes, [parseInt(trNid), 'nid'])
        : trNid;
};

module.exports = getTrNid;

Results in:

~/delme/node-jscs/bin/jscs -x --preset airbnb src/js/model/FlightListLeg/getTrNid.js 
validateIndentation: Invalid indentation character:      at src/js/model/FlightListLeg/getTrNid.js :
     3 |function getTrNid(trNid, saveRes) {
     4 |  return trNid < 0
     5 |  ? m.getIn(saveRes, [parseInt(trNid), 'nid'])
--------^
     6 |  : trNid;
     7 |};

validateIndentation: Invalid indentation character:      at src/js/model/FlightListLeg/getTrNid.js :
     4 |  return trNid < 0
     5 |  ? m.getIn(saveRes, [parseInt(trNid), 'nid'])
     6 |  : trNid;
--------^
     7 |};
     8 |

TypeError: Cannot read property 'replace' of undefined
    at renderLine (/home/x/delme/node-jscs/lib/errors.js:267:16)
    at Object.Errors.explainError (/home/x/delme/node-jscs/lib/errors.js:198:13)
    at /home/x/delme/node-jscs/lib/reporters/console.js:16:36
    at Array.forEach (native)
    at /home/x/delme/node-jscs/lib/reporters/console.js:14:35
    at Array.forEach (native)
    at Object.module.exports [as writer] (/home/x/delme/node-jscs/lib/reporters/console.js:9:22)
    at /home/x/delme/node-jscs/lib/cli.js:149:18
    at Array.<anonymous> (/home/x/delme/node-jscs/node_modules/vow/lib/vow.js:712:56)
    at Immediate.callFns [as _onImmediate] (/home/x/delme/node-jscs/node_modules/vow/lib/vow.js:23:35)

@markelog markelog added the bug label Jun 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests