[Solved] Expected linebreaks to be ‘LF’ but found ‘CRLF’.

Solutions

Add in rules

"linebreak-style": [0 ,"error", "windows"], 

If you need to know the principle, please see the following

Principle

CR LF CRLF

When many people have different editors, VCs applications, and operating systems, different end of line writes may occur by any of the above

Line breaks in different systems

The newline character used in Windows operating system is usually a carriage return character (CR), followed by a newline character (LF), which makes it a carriage return newline character (CRLF)

Linux UNIX uses the simple line feed (LF). The corresponding control sequences are “[n] for LF and” [R] n “for CRLF

Many version control systems, such as GIT and subversion, can automatically ensure the correct outcome. But to cover all unexpected situations, you can activate this rule (linebreak style)

linebreak-style

this rule enforces a uniform end of line, independent of the operating system, VCs, or editors used throughout the code base
Options

“UNIX” (default) forces the use of UNIX line endings for LF

“windows” enforces the use of the windows line terminator for CRLFunix

Error examples

"unix"(Default) Force Unix line endings: \n for LF.
"windows" forces the use of Windows line terminators: \r\n for CRLF.

Correct example

/*eslint linebreak-style: ["error", "unix"]*/

var a = 'a', // \n
    b = 'b'; // \n
// \n
function foo(params) { // \n
    // do stuff \n
}// \n

windows

Wrong Example

/*eslint linebreak-style: ["error", "windows"]*/

var a = 'a'; // \n

Correct example

*eslint linebreak-style: ["error", "windows"]*/

var a = 'a', // \r\n
    b = 'b'; // \r\n
// \r\n
function foo(params) { // \r\n
    // do stuff \r\n
} // \r\n

use this rule in version control system

For example, the default behavior of GIT on Windows systems is to convert lf newline to CRLF when checking out a file, but store the newline as lf when committing changes. Linebreak style if this “UNIX” setting is configured, this will cause the rule to report an error because the file seen by eslint will have a CRLF newline character. If you use git, you can add a line to your. Gitattributes file to prevent git from converting line breaks in. JS files

*.js text eol=lf

Similar Posts: