简体   繁体   中英

jscs error : validateLineBreaks: Invalid line break at filename.js

After grunt-jscs it gives following errors for base/index.js file.

Running "jscs:src" (jscs) task
validateLineBreaks: Invalid line break at api/v1/base/index.js :
     1 |var errors = require('restify-errors');
-----------------------------------------------^
     2 |function Base(Model) {

After I remove var errors = require('restify-errors'); this line, it starts giving below error

Running "jscs:src" (jscs) task
validateLineBreaks: Invalid line break at api/v1/base/index.js :
     1 |function Base(Model) {
------------------------------^

How to resolve this?

Workaround found : Created new file and copied all content to it resolves the problem.

Still want to know any specific reason why this is happening?

this is probably an issue with line breaks
You might want to put "validateLineBreaks": null into your .jscsrc file

If your .jscsrs is with the rule "validateLineBreaks":"LF" , It means you must use LF as line breaks, if you are using other line break symbol (such as CRLF ), JSCS will give you an error like:

validateLineBreaks: Invalid line break at api/v1/base/index.js :

There're two ways to resolve the problem, one is to change the jscs' rule, and the other is to always use LF as line breaks.

You can find the different between LF and CR in this link: https://en.wikipedia.org/wiki/Newline

tldr; Change between LF an CRLF, if you are using VScode you can do this by clicking the option at the bottom right: 单击此处并选择顶部的 porper 选项

Detailed: As tomato said, the issue is probably that the line break format of your IDE isn't compatible with jscs, from the eslint documentation:

The linebreaks (new lines) used in windows operating system are usually carriage returns (CR) followed by a line feed (LF) making it a carriage return line feed (CRLF) whereas Linux and Unix use a simple line feed (LF). The corresponding control sequences are "\\n" (for LF) and "\\r\\n" for (CRLF)

You can also try adding *.js text eol=lf to your .gitattributes file if you know this won't affect the project in any meaningful way.

You can read more about the issue here: https://eslint.org/docs/rules/linebreak-style

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM