【问题标题】:JSCS PunctuatorJSCS 标点符号
【发布时间】:2017-01-23 09:58:55
【问题描述】:

我在设置 JSCS 以使用 JSX/React 和 ES6 (stage-0) 时遇到困难。它会抛出这样的错误:

Expected end of node list but "Punctuator" found at ./src/base/react/architecture/components/Dummy.component.jsx :
     1 |import React, { PropTypes, Component } from 'react';
--------^

Expected end of node list but "Punctuator" found at ./src/base/react/architecture/utils/redux-ext.js :
     1 |import React from 'react';
--------^
     2 |import Immutable from 'immutable';
     3 |import * as reactRedux from 'react-redux';

我无法修复它或找到此问题的原因。

我的配置是:

{
  "preset": "airbnb",
  "validateIndentation": 4,
  "fileExtensions": [
    ".js",
    ".jsx"
  ],
  "maxErrors": -1,
  "excludeFiles": [
    "**/ammap.js",
    "**/worldHigh.js",
    "**/worldLow.js",
    "node_modules/*",
    "**/assets/*"
  ]
}

【问题讨论】:

  • 检查您是否拥有最新 (3.0) 版本的 JSCS。另外,考虑切换到ESlint,因为 JSCS 不再维护,而 ESlint 是推荐的迁移方式。
  • 我有 v3.0.7,现在迁移到 eslint 的成本很高,因为它在同一个预设(Airbnb)上发现了很多错误,而 JSCS 只像上面提到的 10 个。我对此感到困惑。

标签: reactjs import ecmascript-6 jscs


【解决方案1】:

我遇到了同样的问题。经过一番挖掘,我把它钉在了我的静态 propTypes 中的分号上。我也在 JSCS 3.0.7 上。 当前的解决方法(仍在寻找更好的解决方法):

import React from 'react';
import {connect} from 'react-redux';

//jscs:disable requireSemicolons
//unfortunately had to disable semicolons
const SomeComponent = WrappedComponent => class SomeComponent extends React.Component {

    static propTypes = {
        somePropType: React.PropTypes.func,
    } //semicolon here caused the 'Punctuator' error 

    constructor (props) {
        super(props); ....

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 2019-01-21
    • 2021-03-31
    相关资源
    最近更新 更多