【发布时间】:2018-11-23 14:01:10
【问题描述】:
我有一个使用create-react-app 创建的应用程序。默认情况下,它似乎检查对象键是否按字母顺序排序。当我自己键入代码时,这还不错,但是当我从其他来源复制'n'paste 时,这很疯狂。这是一个例子:
const styles = theme => ({
appBar: {
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen
})
},
appBarShift: {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(['width', 'margin'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen
})
},
content: {
flexGrow: 1,
backgroundColor: theme.palette.background.default,
padding: theme.spacing.unit * 3
},
drawerPaper: {
position: 'relative',
whiteSpace: 'nowrap',
width: drawerWidth,
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen
})
},
drawerPaperClose: {
overflowX: 'hidden',
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen
}),
width: theme.spacing.unit * 7,
[theme.breakpoints.up('sm')]: {
width: theme.spacing.unit * 9
}
},
hide: {
display: 'none'
},
menuButton: {
marginLeft: 12,
marginRight: 36
},
root: {
flexGrow: 1,
height: 430,
zIndex: 1,
overflow: 'hidden',
position: 'relative',
display: 'flex'
},
toolbar: {
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
padding: '0 8px',
...theme.mixins.toolbar
}
});
我对第一级键进行了排序,但它似乎也检查了嵌套的键!现在我得到了
C:/Source/portal/src/components/MenuAppBar.js
(19,5): The key 'transition' is not sorted alphabetically
我似乎找不到启用 JS linting 的方法。有关于禁用 tslint 的提示,但在这种情况下我没有使用 Typescript。
我正在使用 VS Code 并尝试过 Sort JS object keys 和 Sort JSON objects。不幸的是,它们都没有对嵌套键进行排序。
【问题讨论】:
-
那么你的项目根目录中有 .eslintrc 文件吗? eslint 是 create-react-app 的依赖,所以它应该是。你需要在那里禁用sort-keys 规则
-
是的,我在其中添加了
"sort-keys": false,但没有任何效果。我猜我做错了。 -
尝试将其设置为
0而不是false。根据我过去的经验,我的.eslintrc文件完全被create-react-app所忽略。除了弹出您的应用程序 (npm run eject) 之外,可能没有其他解决方案,我不建议这样做。 -
刚试过
0,但也没有用。我正在使用 VS Code 并尝试过Sort JS object keys和Sort JSON objects。不幸的是,它们都没有对嵌套键进行排序。
标签: javascript eslint create-react-app lint