diff --git a/docs/options.md b/docs/options.md index fc61e74..bf9d82f 100644 --- a/docs/options.md +++ b/docs/options.md @@ -586,6 +586,15 @@ Indentation size/length (Supported by autopep8) **Description**: do not fix these errors/warnings (Supported by autopep8) +### Rust - Rustfmt path + +**Key**: `rust_rustfmt_path` + +**Type**: `string` + +**Description**: + +Path to rustfmt program (Supported by rustfmt) ### SQL - Indent size **Key**: `sql_indent_size` @@ -1469,6 +1478,37 @@ Default Beautifier to be used for Ruby **Description**: Automatically beautify Ruby files on save +### Language Config - Rust - Disable Beautifying Language + +**Key**: `language_rust_disabled` + +**Type**: `boolean` + +**Description**: + +Disable Rust Beautification +### Language Config - Rust - Default Beautifier + +**Key**: `language_rust_default_beautifier` + +**Default**: `rustfmt` + +**Type**: `string` + +**Enum**: `rustfmt` + +**Description**: + +Default Beautifier to be used for Rust +### Language Config - Rust - Beautify On Save + +**Key**: `language_rust_beautify_on_save` + +**Type**: `boolean` + +**Description**: + +Automatically beautify Rust files on save ### Language Config - Sass - Disable Beautifying Language **Key**: `language_sass_disabled` diff --git a/examples/nested-jsbeautifyrc/rust/expected/test.rs b/examples/nested-jsbeautifyrc/rust/expected/test.rs new file mode 100644 index 0000000..e8e7787 --- /dev/null +++ b/examples/nested-jsbeautifyrc/rust/expected/test.rs @@ -0,0 +1,3 @@ +fn main() { + println!("hello, world"); +} \ No newline at end of file diff --git a/examples/nested-jsbeautifyrc/rust/original/_test.rs b/examples/nested-jsbeautifyrc/rust/original/_test.rs new file mode 100644 index 0000000..e8e7787 --- /dev/null +++ b/examples/nested-jsbeautifyrc/rust/original/_test.rs @@ -0,0 +1,3 @@ +fn main() { + println!("hello, world"); +} \ No newline at end of file diff --git a/src/beautifiers/beautifier.coffee b/src/beautifiers/beautifier.coffee index a105aa3..f1c1f5b 100644 --- a/src/beautifiers/beautifier.coffee +++ b/src/beautifiers/beautifier.coffee @@ -9,7 +9,7 @@ readFile = Promise.promisify(fs.readFile) module.exports = class Beautifier ### - + ### Promise: Promise diff --git a/src/beautifiers/index.coffee b/src/beautifiers/index.coffee index 32acbfc..77e3581 100644 --- a/src/beautifiers/index.coffee +++ b/src/beautifiers/index.coffee @@ -46,6 +46,7 @@ module.exports = class Beautifiers 'prettydiff' 'rubocop' 'ruby-beautify' + 'rustfmt' 'sqlformat' 'tidy-markdown' 'typescript-formatter' diff --git a/src/beautifiers/rustfmt.coffee b/src/beautifiers/rustfmt.coffee new file mode 100644 index 0000000..27711a8 --- /dev/null +++ b/src/beautifiers/rustfmt.coffee @@ -0,0 +1,27 @@ +### +Requires https://github.com/nrc/rustfmt +### + +"use strict" +Beautifier = require('./beautifier') + +module.exports = class rustfmt extends Beautifier + + name: "rustfmt" + + options: { + Rust: true + } + + beautify: (text, language, options) -> + program = options.rustfmt_path or "rustfmt" + @run(program, [ + tmpFile = @tempFile("tmp", text) + ], help: { + link: "https://github.com/nrc/rustfmt" + program: "rustfmt" + pathOption: "Rust - Rustfmt Path" + }) + .then(=> + @readFile(tmpFile) + ) diff --git a/src/languages/index.coffee b/src/languages/index.coffee index 2bdd382..9de6d53 100644 --- a/src/languages/index.coffee +++ b/src/languages/index.coffee @@ -39,6 +39,7 @@ module.exports = class Languages "php" "python" "ruby" + "rust" "sass" "scss" "spacebars" diff --git a/src/languages/rust.coffee b/src/languages/rust.coffee new file mode 100644 index 0000000..9a7641c --- /dev/null +++ b/src/languages/rust.coffee @@ -0,0 +1,27 @@ +module.exports = { + + name: "Rust" + namespace: "rust" + + ### + Supported Grammars + ### + grammars: [ + "Rust" + ] + + ### + Supported extensions + ### + extensions: [ + "rs" + "rlib" + ] + + options: + rustfmt_path: + type: 'string' + default: "" + description: "Path to rustfmt program" + +} \ No newline at end of file