如果你正在寻找一种方式来做到这一点在命令行中,你可以管的awk
或ts
输出到tee
(如果它们可用您的操作系统)。下面的选项将归在你的文件中的空白,并覆盖现有文件:
(!警告这将覆盖的file.js
内容)
选项#1:tr -s " " < file.js | tee file.js
选项2:awk '{$2=$2};1' file.js | tee file.js
假设你有一个file.js
文件具有以下内容:
// there are lots of spaces
// in this file
var a = b || 10;
if ( a === 10 ) {
// ....
}
运行上面的命令之一后,file.js
文件将是这样的:
// there are lots of spaces
// in this file
var a = b || 10;
if (a === 10) {
// ....
}
如果你只是想打印的修正空白内容到终端的结果不覆盖文件,只是不管道输出到tee
,像这样:
选项#1:tr -s " " < file.js
选项2:awk '{$2=$2};1' file.js
否则,如果你想内容输出到一个新文件:
选项#1:tr -s " " < file.js | tee newfile.js
选项#2:awk '{$2=$2};1' file.js | tee newfile.js
输出到一个相同的文件
选项#1:tr -s " " < file.js | tee file.js
选项#2:awk '{$2=$2};1' file.js | tee file.js
话虽这么说,你应该永远是超级小心,你在你的源代码文件信任的命令行操作之前进行详细的测试。
检查更好的细节和更多的选择了this post。
当我粘贴代码到http://danml.com/slim/,然后单击工具>美化,它消除了额外的空间。 – dandavis
我应该指定我正在寻找命令行工具 – IggY
您使用的是什么eslint规则? – Gyandeep