简体   繁体   English

jscs 错误:validateLineBreaks:filename.js 处的换行符无效

[英]jscs error : validateLineBreaks: Invalid line break at filename.js

After grunt-jscs it gives following errors for base/index.js file.grunt-jscs它给出了base/index.js文件的以下错误。

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');在我删除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 您可能需要将"validateLineBreaks": null放入您的.jscsrc文件中

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: 如果您的.jscsrs带有规则"validateLineBreaks":"LF" ,则意味着您必须使用LF作为换行符,如果您使用其他换行符(例如CRLF ),则JSCS将给您以下错误:

validateLineBreaks: Invalid line break at api/v1/base/index.js : validateLineBreaks:在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. 有两种方法可以解决问题,一种是更改jscs的规则,另一种是始终使用LF作为换行符。

You can find the different between LF and CR in this link: https://en.wikipedia.org/wiki/Newline 您可以在此链接中找到LFCR之间的区别: https : //en.wikipedia.org/wiki/Newline

tldr; tldr; Change between LF an CRLF, if you are using VScode you can do this by clicking the option at the bottom right:在 LF 和 CRLF 之间切换,如果您使用的是 VScode,则可以通过单击右下角的选项来执行此操作: 单击此处并选择顶部的 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:详细:正如番茄所说,问题可能是您的 IDE 的换行符格式与 jscs 不兼容,来自 eslint 文档:

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). Windows 操作系统中使用的换行符(新行)通常是回车 (CR) 后跟换行 (LF),使其成为回车换行 (CRLF),而 Linux 和 Unix 使用简单换行 (LF)。 The corresponding control sequences are "\\n" (for LF) and "\\r\\n" for (CRLF)对应的控制序列是“\\n”(对于LF)和“\\r\\n”对于(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.如果您知道这不会以任何有意义的方式影响项目,您也可以尝试将*.js text eol=lf到您的 .gitattributes 文件中。

You can read more about the issue here: https://eslint.org/docs/rules/linebreak-style您可以在此处阅读有关该问题的更多信息: https : //eslint.org/docs/rules/linebreak-style

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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