【问题标题】:.jsbeautifyrc does not accept "\crlf" as eol.jsbeautifyrc 不接受 "\crlf" 作为 eol
【发布时间】:2023-03-16 05:11:01
【问题描述】:

我在 Windows 10 中将此配置与 jsbeautify 1.10.2 一起使用。

{
  "indent_size": "2",
  "indent_char": " ",
  "max_preserve_newlines": "1",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse-preserve-inline",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "160",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false,
  "wrap-attributes": "force-aligned",
  "end-with-newline": "true",
  "eol": "\crlf"
}`

并以这种方式调用jsbeautity:

js-beautify --config ./.jsbeautifyrc --replace ./apps/**/*.html

它会抛出这个错误:

SyntaxError: Unexpected token c in JSON at position 599
    at JSON.parse (<anonymous>)
    at exports.parse (c:\center\node_modules\config-chain\index.js:54:19)
    at exports.json (c:\center\node_modules\config-chain\index.js:70:10)
    at module.exports (c:\center\node_modules\config-chain\index.js:17:15)
    at Object.exports.interpret (c:\center\node_modules\js-beautify\js\lib\cli.js:279:15)
    at Object.<anonymous> (c:\center\node_modules\js-beautify\js\bin\js-beautify.js:4:5)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
Error while loading beautifier configuration.
Configuration file chain included:
c:\center\.jsbeautifyrc
c:\center\.jsbeautifyrc
c:\center\node_modules\js-beautify\js\lib/../config/defaults.json

如果我删除 eol 键,它可以工作,但当然它会以我不希望的方式设置行尾。

我已尝试使用 \\crlf /\crlfcrlf。但这只是在每个新行中都进行了精确的测试。

这是一个已知问题吗?是不是声明错了?

【问题讨论】:

    标签: js-beautify


    【解决方案1】:

    回车符是 \r (ASCII 13),换行符是 \n (ASCII 10)。 试试:

    "eol": "\r\n"
    

    CRLF 只是缩写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 2012-01-14
      相关资源
      最近更新 更多