diff --git a/docs/options.md b/docs/options.md index 835c68f..84d5fba 100644 --- a/docs/options.md +++ b/docs/options.md @@ -7633,6 +7633,7 @@ Maximum amount of characters per line (0 = disable) (Supported by Pretty Diff) | `disabled` | :white_check_mark: | | `default_beautifier` | :white_check_mark: | | `beautify_on_save` | :white_check_mark: | +| `end_of_line` | :white_check_mark: | **Description**: @@ -7693,6 +7694,34 @@ Automatically beautify Lua files on save 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Beautify On Save*" and change it to your desired configuration. +##### [End of line](#end-of-line) + +**Namespace**: `lua` + +**Key**: `end_of_line` + +**Default**: `System Default` + +**Type**: `string` + +**Enum**: `CRLF` `LF` `System Default` + +**Supported Beautifiers**: [`Lua beautifier`](#lua-beautifier) + +**Description**: + +Override EOL from line-ending-selector (Supported by Lua beautifier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "lua": { + "end_of_line": "System Default" + } +} +``` + #### [Markdown](#markdown) **Supported Beautifiers**: [`Remark`](#remark) [`Tidy Markdown`](#tidy-markdown) @@ -16831,6 +16860,37 @@ Remove trailing whitespace (Supported by Latex Beautify) ``` +### Lua beautifier + +##### [End of line](#end-of-line) + +**Namespace**: `lua` + +**Key**: `end_of_line` + +**Default**: `System Default` + +**Type**: `string` + +**Enum**: `CRLF` `LF` `System Default` + +**Supported Beautifiers**: [`Lua beautifier`](#lua-beautifier) + +**Description**: + +Override EOL from line-ending-selector (Supported by Lua beautifier) + +**Example `.jsbeautifyrc` Configuration** + +```json +{ + "lua": { + "end_of_line": "System Default" + } +} +``` + + ### Marko Beautifier ##### [Indent size](#indent-size) diff --git a/examples/simple-jsbeautifyrc/lua/expected/test.lua b/examples/simple-jsbeautifyrc/lua/expected/test.lua index 878d1c1..82141da 100644 --- a/examples/simple-jsbeautifyrc/lua/expected/test.lua +++ b/examples/simple-jsbeautifyrc/lua/expected/test.lua @@ -2,6 +2,7 @@ -- and return a closure which can be used for continuing the sort. local a = 'a b c' local b = '12345678' +local x = 1.99e-07 local c = 'a b c' + 'a b c' local t = { a = 1, diff --git a/examples/simple-jsbeautifyrc/lua/original/test.lua b/examples/simple-jsbeautifyrc/lua/original/test.lua index fed0705..edcd1c7 100644 --- a/examples/simple-jsbeautifyrc/lua/original/test.lua +++ b/examples/simple-jsbeautifyrc/lua/original/test.lua @@ -2,6 +2,7 @@ -- and return a closure which can be used for continuing the sort. local a= 'a b c' local b ='12345678' +local x = 1.99e-07 local c = 'a b c' +'a b c' local t = { a = 1, diff --git a/src/beautifiers/lua-beautifier/beautifier.coffee b/src/beautifiers/lua-beautifier/beautifier.coffee index e7aba13..35398ae 100644 --- a/src/beautifiers/lua-beautifier/beautifier.coffee +++ b/src/beautifiers/lua-beautifier/beautifier.coffee @@ -8,7 +8,8 @@ adjust_space = (line) -> # replace all whitespaces inside the string with one space, WARNING: the whitespaces in string will be replace too! line = line.replace /\s?(==|>=|<=|~=|[=><\+\*\/])\s?/g, ' $1 ' # add whitespace around the operator - line = line.replace /([^=|\-|(|\s])\s?\-\s?([^\-|\[])/g, '$1 - $2' + line = line.replace /([^=e\-\(\s])\s?\-\s?([^\-\[])/g, '$1 - $2' + line = line.replace /([^\d])e\s?\-\s?([^\-\[])/g, '$1e - $2' # just format minus, not for -- or negative number or commentary. line = line.replace /,([^\s])/g, ', $1' # adjust ',' @@ -25,7 +26,8 @@ adjust_space = (line) -> DEFAULT_WARN_FN = (msg) -> console.log('WARNING:', msg) -module.exports = (str, indent, warn_fn) -> +module.exports = (str, indent, warn_fn, opts = {}) -> + eol = opts?.eol or '\n' indent = indent or DEFAULT_INDENT warn_fn = if typeof warn_fn == 'function' then warn_fn else DEFAULT_WARN_FN indent = ' '.repeat(indent) if Number.isInteger(indent) @@ -100,4 +102,4 @@ module.exports = (str, indent, warn_fn) -> new_line or undefined warn_fn 'positive indentation at the end' if $currIndent > 0 - new_code.join '\n' + new_code.join eol diff --git a/src/beautifiers/lua-beautifier/index.coffee b/src/beautifiers/lua-beautifier/index.coffee index 24f9376..e9d9445 100644 --- a/src/beautifiers/lua-beautifier/index.coffee +++ b/src/beautifiers/lua-beautifier/index.coffee @@ -16,8 +16,9 @@ module.exports = class Lua extends Beautifier } beautify: (text, language, options) -> + options.eol = @getDefaultLineEnding('\r\n','\n',options.end_of_line) new @Promise (resolve, reject) -> try - resolve format text, options.indent_char.repeat options.indent_size + resolve format text, options.indent_char.repeat(options.indent_size), @warn, options catch error reject error diff --git a/src/languages/lua.coffee b/src/languages/lua.coffee index 236575d..9f5d49b 100644 --- a/src/languages/lua.coffee +++ b/src/languages/lua.coffee @@ -19,4 +19,10 @@ module.exports = { defaultBeautifier: "Lua beautifier" + options: + end_of_line: + type: 'string' + default: "System Default" + enum: ["CRLF","LF","System Default"] + description: "Override EOL from line-ending-selector" } diff --git a/src/options.json b/src/options.json index 453103e..d207c82 100644 --- a/src/options.json +++ b/src/options.json @@ -4576,6 +4576,25 @@ "lua" ], "properties": { + "end_of_line": { + "type": "string", + "default": "System Default", + "enum": [ + "CRLF", + "LF", + "System Default" + ], + "description": "Override EOL from line-ending-selector (Supported by Lua beautifier)", + "title": "End of line", + "beautifiers": [ + "Lua beautifier" + ], + "key": "end_of_line", + "language": { + "name": "Lua", + "namespace": "lua" + } + }, "disabled": { "title": "Disable Beautifying Language", "order": -3,