jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.97k stars 515 forks source link

Warning: parseError @ line undefined char undefined #2240

Closed srhwork closed 8 years ago

srhwork commented 8 years ago
WARNING in ./web/static/js/components/error/NotFound.js
jscs results in errors
  parseError @ line undefined char undefined
    Cannot iterate using ClassProperty
import React, { Component } from 'react';

const codeStyle = {
    fontSize: '98pt'
};

/**
 * Error 404 component
 *
 * @class      NotFound (name)
 */
class NotFound extends Component {
    /**
     * React DOM rendering
     */
    render = () => {
        return (
            <div className='container'>
                <section>
                    <h1 style={codeStyle}>404</h1>
                    <div>
                        <h2>
                            <i className='fa fa-warning' /> Oops! Página no encontrada.
                        </h2>
                        <br />
                        <p>
                            La página que ha solicitado no se encuentra disponible, esto puede ser debido
                            a que la ruta ha cambiado, o la dirección que ha escrito es incorrecta.
                        </p>
                    </div>
                </section>
            </div>
        );
    };
}

export default NotFound;
{
    "preset": "google",

    "fileExtensions": [".js", ".jsx"],

    "requireCurlyBraces": true,
    "requireLineFeedAtFileEnd": false,
    "requireParenthesesAroundIIFE": true,

    "maximumLineLength": 130,
    "validateLineBreaks": "LF",
    "validateIndentation": 4,

    "disallowKeywords": ["with"],
    "disallowSpacesInsideObjectBrackets": null,
    "disallowShorthandArrowFunctions": false,
    "disallowAnonymousFunctions": false,
    "disallowImplicitTypeConversion": ["string"],
    "requireCamelCaseOrUpperCaseIdentifiers": {"ignoreProperties": true},
    "safeContextKeyword": "that",

    "excludeFiles": [
        "_build/**",
        "config/**",
        "deps/**",
        "lib/**",
        "priv/**",
        "test/**"
    ]
}

Version: 3.0.3

qfox commented 8 years ago

I've made an issue about this: https://github.com/cst/cst/issues/112

qfox commented 8 years ago

@srh-work Btw, why you using:

class NotFound extends Component {
    render = () => {};
}

instead of just

class NotFound extends Component {
    render() {}
}

?

srhwork commented 8 years ago

@zxqfox I'm using that syntax just for fun...nothing special.

After trying a lot, I managed to remove the warning in this way:

1.- Remove the "@class" property of the class block 2.- Using the classic syntax for function properties declaration "from render = () => {}; to render() {}" 3.- Adding "@return" property to blocks for functions with returning value 4.- Declare statics properties outside of the class

/**
 * Error 404 component
 */
class NotFound extends Component {
    /**
     * React DOM rendering
     *
     * @return     {Object}  React DOM object
     */
    render() {
        return (
            <div className='container'>
                <section>
                    <h1 style={codeStyle}>404</h1>
                    <div>
                        <h2>
                            <i className='fa fa-warning' /> Oops! Página no encontrada.
                        </h2>
                        <br />
                        <p>
                            La página que ha solicitado no se encuentra disponible, esto puede ser debido
                            a que la ruta ha cambiado, o la dirección que ha escrito es incorrecta.
                        </p>
                    </div>
                </section>
            </div>
        );
    }
}

NotFound.propTypes = {
   children: PropType.object.isRequired
}
karlhorky commented 8 years ago

@zxqfox since your issue was addressed in cst/cst#119, can this be fixed by updating cst to 0.2.0?

karlhorky commented 8 years ago

I'm also getting this issue with propTypes in React components:

import React from 'react';

// ...

export default class App extends React.Component {
  static propTypes = {
    children: React.PropTypes.element.isRequired
  };

  // ...
}

This is using the latest version of jscs by specifying the repo in package.json:

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

Output:

Cannot iterate using ClassProperty at ./ui/App.js :
     1 |import React from 'react';
--------^
     2 |
     3 |

1 code style error found.

If I remove the class property it runs through without errors.

markelog commented 8 years ago

can this be fixed by updating cst to 0.2.0?

It totally can :)

hzoo commented 8 years ago

What do you think about making 1.0 so we can use ^

markelog commented 8 years ago

I guess.

@mdevils thoughts?

karlhorky commented 8 years ago

@markelog Thanks!