我正在使用打字稿和反应材料-UI。我正在以类似Hook的方式使用Material的样式解决方案(CSS在JS中),这是如何在文档中解释的:
const useStyles = makeStyles({
root: {
background: 'linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)',
border: 0,
borderRadius: 3,
boxShadow: '0 3px 5px 2px rgba(255, 105, 135, .3)',
color: 'white',
height: 48,
padding: '0 30px',
},
});
export default function Hook() {
const classes = useStyles();
return <Button className={classes.root}>Hook</Button>;
}我希望Eslint检测对象属性是否在任何地方都没有被使用。因为在拥有超过6个属性(CSS规则)之后,很难检测哪些属性正在被使用,哪些属性曾经被使用过。我尝试了eslint-plugin-unicorn并打开了它们的no-unused-properties规则,尽管它可以检测对象中未使用的属性,如果对象是声明的,并且它的一个属性是通过点表示法访问的:
const styles = {
success: { … },
danger: { … } // <- Property `danger` is defined but never used
};
console.log(styles.success)但是,在第一个代码示例中,我将一个对象作为参数传递给另一个函数和其他一些步骤,它无法检测classes的属性(现在是一个具有样式属性的对象)是否被使用。我想知道为什么会这样,原因是什么?(我对类型记录也很陌生)我希望能解释一下为什么linter不能在第一个示例中警告我classes对象中未使用的属性。提前谢谢。
发布于 2021-03-31 01:35:06
https://stackoverflow.com/questions/65943198
复制相似问题