diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-09-13 20:19:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-13 20:19:10 +0200 |
commit | 0dbeb774ba9ea618ff1e92b63ab31e5caf3003dd (patch) | |
tree | 592244102cf046716acbb144233586c312ee7a7e /cli/main.rs | |
parent | a655a0f3e4201840eda94938fc8d6222c2b94a99 (diff) |
feat(fmt): add support for configuration file (#11944)
This commit adds support for configuration file for "deno fmt"
subcommand. It is also respected by LSP when formatting
files.
Example configuration:
{
"fmt": {
"files": {
"include": ["src/"],
"exclude": ["src/testdata/"]
},
"options": {
"useTabs": true,
"lineWidth": 80,
"indentWidth": 4,
"singleQuote": true,
"textWrap": "preserve"
}
}
}
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/cli/main.rs b/cli/main.rs index 896704eec..55de5a61e 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -805,8 +805,20 @@ async fn format_command( flags: Flags, fmt_flags: FmtFlags, ) -> Result<(), AnyError> { + let program_state = ProgramState::build(flags.clone()).await?; + let maybe_fmt_config = + if let Some(config_file) = &program_state.maybe_config_file { + config_file.to_fmt_config()? + } else { + None + }; + if fmt_flags.files.len() == 1 && fmt_flags.files[0].to_string_lossy() == "-" { - return tools::fmt::format_stdin(fmt_flags.check, fmt_flags.ext); + return tools::fmt::format_stdin( + fmt_flags.check, + fmt_flags.ext, + maybe_fmt_config.map(|c| c.options).unwrap_or_default(), + ); } tools::fmt::format( @@ -814,6 +826,7 @@ async fn format_command( fmt_flags.ignore, fmt_flags.check, flags.watch, + maybe_fmt_config, ) .await?; Ok(()) |