如何编写复杂/多行的hlint规则?

时间:2017-11-28 14:40:39

标签: haskell hlint

匹配以下代码模式的方法是什么......

class Button extends PureComponent {
    render() {
        const {
            size,
            width,
            variation,
            disabled,
            loading,
            position,
            children,
            className,
            component,
            ...otherProps
        } = this.props;

        // Here lies the problem, "button" is not defined here, how to use the default html element while not loosing props specified below?
        const Button = component || button; 

        return (
            <Button
                className={classnames(
                    "BUTTON",
                    {
                        [`BUTTON-size--${size}`]: size,
                        [`BUTTON-width--${width}`]: width,
                        [`BUTTON-variation--${variation}`]: variation,
                        [`BUTTON-position--${position}`]: position,
                        "BUTTON-state--disabled": disabled,
                        "BUTTON-state--loading": loading
                    },
                    className
                )}
                disabled={disabled || loading}
                {...otherProps}
            >
                {children}
            </Button>
        );
    }
}

...并建议以下替换:

do 
  x <- createModel a b
  case x of
    Left e -> throwM $ ValidationErrors e
    Right y -> ...

我尝试了以下操作,但它不起作用:

withThrow $ createModel a b

1 个答案:

答案 0 :(得分:1)

问题是HLint匹配是基于表达式的,而您尝试定义的规则实际上是基于语句的 - 您希望在do中相邻地匹配这两个语句。可能会修改HLint来做到这一点,并且您认为这很有用,请raise an HLint issue