Skip to content

Commit f2cc7c8

Browse files
committed
refactor: extract options
1 parent d14cfe6 commit f2cc7c8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/format_text.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ use anyhow::Result;
88
use jsonc_parser::CollectOptions;
99
use jsonc_parser::ParseOptions;
1010

11+
const COLLECT_OPTIONS: CollectOptions = CollectOptions {
12+
comments: false,
13+
tokens: false,
14+
};
15+
16+
const PARSE_OPTIONS: ParseOptions = ParseOptions {
17+
allow_comments: true,
18+
allow_loose_object_property_names: true,
19+
allow_trailing_commas: true,
20+
};
21+
1122
pub fn format_text(
1223
input_text: &str,
1324
format_with_host: impl FnMut(&Path, String) -> Result<Option<String>>,
1425
) -> Result<Option<String>> {
15-
let parse_result = jsonc_parser::parse_to_ast(
16-
input_text,
17-
&CollectOptions {
18-
comments: false,
19-
tokens: false,
20-
},
21-
&ParseOptions {
22-
allow_comments: true,
23-
allow_loose_object_property_names: true,
24-
allow_trailing_commas: true,
25-
},
26-
)?;
26+
let parse_result = jsonc_parser::parse_to_ast(input_text, &COLLECT_OPTIONS, &PARSE_OPTIONS)?;
2727
let Some(root_value) = parse_result.value else {
2828
return Ok(None);
2929
};

0 commit comments

Comments
 (0)