Norminette 空行或不在末尾

发布于 2025-01-10 16:12:23 字数 476 浏览 0 评论 0原文

为什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2025-01-17 16:12:23

这个话题已经被讨论得死去活来了。

无论您使用什么系统,文本文件中的行通常以一两个不可见字符结尾。在某些系统上,它是一个“回车符”CR,后跟一个“换行符”LF,在其他系统上,它只是一个 CR,在在其他系统中,它只是一个LF,并且这只适用于最不奇异的系统。该字符或字符对有一些通俗的名称:“newline”、“EOL”等。从现在开始我将使用“EOL”。

现在,EOL 有两种语义解释。在某些情况下,EOL 被认为是“行终止符”,这意味着不对它后面的内容做出任何假设,而在其他一些情况下,EOL 被认为是“行分隔符”,这意味着总是有一个其后一行。

还有一个相关的问题是文本流应该如何结束。对于第一种解释,如果只是为了能够在两个流之间建立边界,那么流的最后一行应该以 EOL 结尾。根据上面的第二种解释,流的最后一行不应以 EOL 结尾,因为这意味着……最后一行并不是真正的最后一行。

因此,基本上,这段文本:

foo
bar
baz

可以编码为(第一种解释):

foo<EOL>
bar<EOL>
baz<EOL>

或(第二种解释):

foo<EOL>
bar<EOL>
baz

几十年来,大多数类 Unix 工具都采用第一种解释,并且通常期望最后一行 EOL,但许多更现代的工具已经采用了第二种解释,这给那些在 GUI 编辑器和 CLI 工具之间周旋的新一代人带来了很多困惑。

将一些带有最终 EOL 的文本提供给将其解释为“行分隔符”的工具,您会在文件末尾显示一条假想行:

1 foo
2 bar
3 baz
4

将一些没有最终 EOL 的文本提供给将其解释为“行终止符”的工具”,你可以得到任何东西,从合理的显示(如下)到响亮的抱怨(git):

1 foo
2 bar
3 baz

加上像“newline”这样令人困惑的名字,你就会得到像这样永无休止的问题流的秘诀。

所以……这就是这里正在发生的事情:

  1. 您正在使用以不同方式解释 EOL 的多种工具,
  2. 您错误地解释了其中一种解释,
  3. 并且根据这种误解采取了行动,结果令人困惑。

让我们一一解决这些问题。

  1. 好吧,我们都这样做¯\_(ツ)_/¯

  2. 在现代 GUI 编辑器中,文件底部看起来像是额外的一行不太可能是额外的一行。它更有可能是第二种解释的产物。假设您使用的是某种类 Unix 系统,并且预期的 EOL 是 LF,您可以执行 $ xxd filename 以十六进制形式检查其内容:

    • 末尾有一个 a0 表示您的文件以 EOL 结尾,
    • 末尾的 a0a0 表示您的文件有一个额外的空行,
    • 末尾没有 a0 意味着它是由严格遵循第二种解释的编辑者编写的。

    第二种情况会让你的 linter 生气:

    错误:EMPTY_LINE_EOF(行:7,列:1):文件末尾有空行
    

    但它似乎并不特别关心其他两种情况。

  3. 因为您在 GUI 编辑器中看到文件末尾似乎是一个空行,但这并不意味着 a) 该行实际上存在以及 b) 您必须在文件末尾添加一个Vim 或任何其他编辑器。

    正确的做法是:

    • 让 Vim 做它开箱即用的事情,编写末尾带有 EOL 的文件,因为这是您的工具链(包括 Norminette)所期望的,
    • 设置您的 GUI 编辑器执行相同操作(即使它们仍然显示该假想线),
    • 删除项目中可能存在的任何无关的空行,
    • 切勿在文件末尾添加无关的空行,因为它充其量是无用的,充其量是被禁止的。

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 a CR, on other systems it's only a LF, 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:

foo
bar
baz

could be encoded as (first interpretation):

foo<EOL>
bar<EOL>
baz<EOL>

or as (second interpretation):

foo<EOL>
bar<EOL>
baz

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:

1 foo
2 bar
3 baz
4

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):

1 foo
2 bar
3 baz

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:

  1. you are using a mix of tools that interpret EOL differently,
  2. you are interpreting one of those interpretations incorrectly,
  3. and you act upon that misinterpretation, with confusing results.

Let's address these one-by-one.

  1. Well, we all do so ¯\_(ツ)_/¯.

  2. 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:

    • a single a0 at the end means that your file ends with EOL,
    • a a0a0 at the end means that your file has an extra empty line,
    • no 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:

    Error: EMPTY_LINE_EOF       (line:   7, col:   1):   Empty line at end of file
    

    but it doesn't seem to particularly care about the other two cases.

  3. 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:

    • let Vim do what it does out the box, write files with an EOL at the end, because that's what your toolchain (including Norminette) expects,
    • set up your GUI editors to do the same (even if they still show that imaginary line),
    • get rid of any extraneous empty line you might have in one of your projects,
    • NEVER add an extraneous empty line at the end of your files, as it useless at best and forbidden at worst.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文