## 问题描述 目前一直在 Windows 下进行 Web 开发,但是部分项目中用到的 ESLint 默认要求换行符格式为 `LF`,而 Windows 下创建的文件,换行符格式默认是 `CRLF`,这样 ESLint 就总会报告说文件的换行符不正确。 ## 解决方案 Google `eslint linebreak-style cr crlf` 找到了解决方案:[How can I write a ESLint rule for "linebreak-style", changing depending on Windows or Unix?](https://stackoverflow.com/a/53110172/2667665),用下面的代码,让 ESLint 根据当前操作系统来决定什么样的换行符是合法的。 ``` "rules": { "linebreak-style": ["error", (process.platform === "win32" ? "windows" : "unix")], } ```
问题描述
目前一直在 Windows 下进行 Web 开发,但是部分项目中用到的 ESLint 默认要求换行符格式为
LF,而 Windows 下创建的文件,换行符格式默认是CRLF,这样 ESLint 就总会报告说文件的换行符不正确。解决方案
Google
eslint linebreak-style cr crlf找到了解决方案:How can I write a ESLint rule for "linebreak-style", changing depending on Windows or Unix?,用下面的代码,让 ESLint 根据当前操作系统来决定什么样的换行符是合法的。