Norminette 空行或不在末尾
为什么 VStudio 上带有 norminette 突出显示的人会在末尾添加一个空行。 当他们在 iTerm 中执行norminette时,它就可以工作
当您使用Vim并在末尾放置一个空行时,norminette会说Error extra line。
昨天和今天发生这种情况,我的 Vstdio 要求在末尾添加一行,当我在 iTerm 中执行 Norminette 时,它说错误额外一行。我回到 vim,删除该行并再次说错误以删除多余的行。我需要打开文件,添加行,然后删除并保存以使norminette工作。所以现在有时穆林内特在服务器上说“KO”,但我这边还好。当我在 vstdio 上工作时,我每次都需要添加/删除最后一行,
所以如果有人知道这个问题,我希望有一个更好的解决方案,而不是在接下来的 3 周甚至 3 年里仔细检查 vim
Why people on VStudio with norminette highlights put an empty line at end.
And when they do norminette in iTerm it’s Works
When you use Vim and put an empty line at end the norminette say Error extra line.
This happen yesterday and today my Vstdio ask for a line at end and when I do norminette in iTerm it’s say error extra line. I go back to vim, delete the line and norminette say error again to remove extra line. I need to open back the file, add line and then delete and save to have norminette working. So now sometime moulinette say KO on server but OK my side. I need to add/remove last line every time with vim when I work on vstdio
So if someone know the issue i would like to have a better solution than double check on vim for the next 3 week and maybe 3 years ???? thx all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个话题已经被讨论得死去活来了。
无论您使用什么系统,文本文件中的行通常以一两个不可见字符结尾。在某些系统上,它是一个“回车符”
CR
,后跟一个“换行符”LF
,在其他系统上,它只是一个CR
,在在其他系统中,它只是一个LF
,并且这只适用于最不奇异的系统。该字符或字符对有一些通俗的名称:“newline”、“EOL”等。从现在开始我将使用“EOL”。现在,EOL 有两种语义解释。在某些情况下,EOL 被认为是“行终止符”,这意味着不对它后面的内容做出任何假设,而在其他一些情况下,EOL 被认为是“行分隔符”,这意味着总是有一个其后一行。
还有一个相关的问题是文本流应该如何结束。对于第一种解释,如果只是为了能够在两个流之间建立边界,那么流的最后一行应该以 EOL 结尾。根据上面的第二种解释,流的最后一行不应以 EOL 结尾,因为这意味着……最后一行并不是真正的最后一行。
因此,基本上,这段文本:
可以编码为(第一种解释):
或(第二种解释):
几十年来,大多数类 Unix 工具都采用第一种解释,并且通常期望最后一行 EOL,但许多更现代的工具已经采用了第二种解释,这给那些在 GUI 编辑器和 CLI 工具之间周旋的新一代人带来了很多困惑。
将一些带有最终 EOL 的文本提供给将其解释为“行分隔符”的工具,您会在文件末尾显示一条假想行:
将一些没有最终 EOL 的文本提供给将其解释为“行终止符”的工具”,你可以得到任何东西,从合理的显示(如下)到响亮的抱怨(git):
加上像“newline”这样令人困惑的名字,你就会得到像这样永无休止的问题流的秘诀。
所以……这就是这里正在发生的事情:
让我们一一解决这些问题。
好吧,我们都这样做
¯\_(ツ)_/¯
。在现代 GUI 编辑器中,文件底部看起来像是额外的一行不太可能是额外的一行。它更有可能是第二种解释的产物。假设您使用的是某种类 Unix 系统,并且预期的 EOL 是
LF
,您可以执行$ xxd filename
以十六进制形式检查其内容:a0
表示您的文件以 EOL 结尾,a0a0
表示您的文件有一个额外的空行,a0
意味着它是由严格遵循第二种解释的编辑者编写的。第二种情况会让你的 linter 生气:
但它似乎并不特别关心其他两种情况。
因为您在 GUI 编辑器中看到文件末尾似乎是一个空行,但这并不意味着 a) 该行实际上存在以及 b) 您必须在文件末尾添加一个Vim 或任何其他编辑器。
正确的做法是:
That topic has already been discussed to death.
No matter what system you are on, lines in text files generally end with one or two invisible characters. On some systems, it's a "carriage return"
CR
followed by a "line feed"LF
, on other systems it's only aCR
, on other systems it's only aLF
, and that's only for the least exotic ones. That character or pair of characters has a few colloquial names: "newline", "EOL", etc. I will use "EOL" from now on.Now, EOL has two semantic interpretations. In some contexts, EOL is considered to be a "line terminator", meaning that no assumption is made about what comes after it, and in some other contexts, EOL is considered to be a "line separator", meaning that there is always a line after it.
And then there is the related problem of how a stream of text should end. With the first interpretation, the last line of a stream should end with EOL, if only to be able to establish a boundary between two streams. With the second interpretation above, the last line of a stream shouldn't end with EOL because it would mean… that the last line is not really the last line.
So, basically, this text:
could be encoded as (first interpretation):
or as (second interpretation):
Most Unix-like tools have adopted the first interpretation for decades and generally expect EOL on the last line but many more modern tools have adopted the second interpretation, which leads to much confusion among new generations who juggle between GUI editors and CLI tools.
Feed some text with a final EOL to a tool that interprets it as a "line separator" and you get an imaginary line displayed at the end of the file:
Feed some text without a final EOL to a tool that interprets it as "line terminator" and you can get anything from a reasonable display (as follows) to loud complaints (git):
Add to that confusing names like "newline" and you have a recipe for a never-ending stream of questions like this one.
So… this is what seems to be going on, here:
Let's address these one-by-one.
Well, we all do so
¯\_(ツ)_/¯
.What appears like an extra line at the bottom of your file in a modern GUI editor is unlikely to be an extra line. It is more likely to be an artefact of the second interpretation. Assuming you are on some kind of Unix-like system and the expected EOL is
LF
, you can do$ xxd filename
to inspect its content in hexadecimal form:a0
at the end means that your file ends with EOL,a0a0
at the end means that your file has an extra empty line,a0
at the end means that it was written by a an editor that firmly adheres to the second interpretation.The second case will angry your linter:
but it doesn't seem to particularly care about the other two cases.
Because you see what appears to be an empty line at the end of a file in a GUI editor it doesn't mean that a) that line actually exists and b) that you must add one at the end of the file in Vim or any other editor.
The correct approach is to: