ESLint: A Quick Way to Solve "Wrong Spaces Not Allowed"

I am trying to use ESLint to provide a coding style in a project, and I have many errors Irregular whitespace not allowedcaused by code like this:

var a = b ||  10; //note the 2 spaces between || and 10
if (a === 10)  {  // again, 2 spaces between ) and {

I did not find a way to easily solve this problem for all my files. I think that the basic regular expression will not work, because in some situations double spaces are acceptable (indentation of a column of a JSON object, indentation with soft tabs, lines).

I tried a tool like js-beautify, but did not find any options to solve this problem. Is there a tool that could help me?

+4
source share
1 answer

, 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

, .

.

+1

Source: https://habr.com/ru/post/1619243/


All Articles