匹配以下代码模式的方法是什么......
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
答案 0 :(得分:1)
问题是HLint匹配是基于表达式的,而您尝试定义的规则实际上是基于语句的 - 您希望在do
中相邻地匹配这两个语句。可能会修改HLint来做到这一点,并且您认为这很有用,请raise an HLint issue。