且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么根据CodeSniffer我的行尾仍然错误?

更新时间:2023-11-28 08:13:59

使用regex搜索\r\n不会返回实例,因此我认为问题在于git.

Searching for \r\n with regex on does not return instances, so I believe the problem to lie with git.

不一定是git.

IDE(PhpStorm)使用标准化的行分隔符(\n/LF)将所有行存储在内存中,当您保存文件时,它将用文件打开时检测到的实际行分隔符替换它们.这也意味着,如果您碰巧在一个文件中有混合的行尾(例如CRLFLF)..保存后,它将仅使用一种样式(例如仅LF).

IDE (PhpStorm) stores all lines in memory with normalized line separator (which is \n / LF) and when you saving the file it replaces them with actual line separator symbol detected on file opening. This also means that if you happen to have mixed line endings in one file (e.g. both CRLF and LF) .. after save it will use only one style (e.g. only LF).

归一化的行尾允许您以更简单的方式执行正则表达式搜索/替换-无需担心实际符号是什么.

Normalized line ending allows you to execute your regex searches/replaces in a bit more simpler way -- no need to worry about what the actual symbol is.

现在-Code Style设置页面-如您在该字段下方的提示中看到的那样,它说:应用于新文件".这意味着此设置不会以任何方式影响现有文件.

Now -- the Code Style settings page -- as you can see in that hint below the field, it says: "Applied to new files". This means that this setting does NOT affect existing files in any way.

要更改特定现有文件的行尾::打开文件,然后通过状态栏中的相应部分..或通过File | Line Separators

To change line ending for a particular existing file: open the file and either change it via appropriate section in Status Bar .. or via File | Line Separators

那为什么PhpStorm无法正常工作?

So why does PhpStorm not work properly?

它正常工作-您碰巧不知道如何更改行分隔符样式.

It works properly -- you just happen to not know how to change the line separator style.