0

使用来自我们的最新规则,eslint-config-react-app我们得到以下 linting 错误:

{
  [componentWidth > VIEW_DESKTOP && componentWidth <= VIEW_LARGE]: MAX_TICKS_LARGE
}

error Parsing error: Unexpected token

问题似乎位于<=计算的密钥中。

有谁知道是什么导致这引发错误?代码应该是合法的。

更新:有趣的是,linting 错误不会出现在我的 IDE 中,只会出现在控制台中。

更新 2:似乎是 eslint 最新版本的问题,而不是与 eslint-config-react-app 相关的任何问题。使用 eslint-config-react-app 指定的 eslint 版本可以正常工作,只是不能使用最新版本的 eslint。

更新 3

为了为问题提供更好的上下文,这里是该代码所在的函数:

const getTicksToDisplay = (componentWidth) => {
    const truthMap = {
        [true]: MIN_TICKS_ON_SCREEN,
        [componentWidth > VIEW_LARGE]: MAX_TICKS_XLARGE,
        [componentWidth > VIEW_DESKTOP && componentWidth <= VIEW_LARGE]: MAX_TICKS_LARGE,
        [componentWidth > VIEW_TABLET && componentWidth <= VIEW_DESKTOP]: MAX_TICKS_DESKTOP,
        [componentWidth > VIEW_MOBILE && componentWidth <= VIEW_TABLET]: MAX_TICKS_TABLET,
        [componentWidth <= VIEW_MOBILE]: MAX_TICKS_MOBILE
    };

    return truthMap[true];
};

更新 4

问这个问题时的 eslint 版本是 3.11.1。该代码在 eslint 3.8.1 中工作,自从提出这个问题以来,eslint 3.12.0 已经发布(我还不能测试)

更新 5

经过进一步测试,这可能是 babel-eslint 7.1.1 的问题。我提出了一个问题:https ://github.com/babel/babel-eslint/issues/428

4

0 回答 0