按照 Javascript书写规范 的要求,分号被禁用。
为什么js里不要写分号呢? 且看 seven-things-you-should-stop-doing-with-node-js 第五点 Stop using semicolons
对于已经写了分号的文件, Javascript书写规范 提供一个简单的指令 standard --fix
将你的js文件规范化。当然,你需要先安装 npm install standard --save-dev
。 顺便补充一点,不是全局安装的模块,可执行文件在 ./node_modules/.bin/
下面,所以这样运行 ./node_modules/.bin/standard --fix
如何去掉.vue里的分号呢?
standard --fix
只能去掉.js里的分号,然而.vue是这样的格式
<template>
<div>
<h1>hello {{ name }}</h1>
</div>
</template>
<script>
export default {
data() {
return {
name: 'William'
};
}
};
</script>
<style lang='scss' scoped>
div {
margin: 10px 8px;
background-color: steelblue;
}
</style>
分析: 对于上面的文件,只能去掉 script 标签里的分号,style 标签中的分号是不能去掉的。
该召唤伟大的 sed(强大的文本处理工具) 了。 用法请参考这里.
直接写结果的话是这样: sed -i "/script/, /script/s/;$//" file.vue
,表示对file.vue的script之间的内容,将每行末尾的分号替换(s)为空,即删除。
如果要删除一批.vue中的分号,则可这样
sed -i "/script/,/script/s/;$//" `find . -name '*vue'`
find . -name '*vue'
将列出当前目录下所有的.vue文件, 像下面这样:
./deal.vue
./world.vue
./sub/hello.vue
./tea.vue
./hello.vue
— done —