Skip to content

Commit 56c6730

Browse files
committed
refactor: Rename statements.X config properties to module.X as it's better.
1 parent 2e52db1 commit 56c6730

12 files changed

+28
-24
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript code formatting plugin for dprint."
44
keywords = ["formatting", "formatter", "typescript"]
5-
version = "0.34.0"
5+
version = "0.35.0"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"
@@ -24,7 +24,7 @@ panic = "abort"
2424
wasm = ["serde_json", "dprint-core/wasm"]
2525

2626
[dependencies]
27-
dprint-core = { version = "0.31.0", features = ["formatting"] }
27+
dprint-core = { version = "0.33.1", features = ["formatting"] }
2828
swc_common = "0.10.6"
2929
swc_ecmascript = { version = "0.14.4", features = ["parser"] }
3030
serde = { version = "1.0.88", features = ["derive"] }

src/configuration/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl ConfigurationBuilder {
6666
.quote_style(QuoteStyle::PreferDouble)
6767
.ignore_node_comment_text("deno-fmt-ignore")
6868
.ignore_file_comment_text("deno-fmt-ignore-file")
69-
.statements_sort_import_declarations(SortOrder::Maintain)
70-
.statements_sort_export_declarations(SortOrder::Maintain)
69+
.module_sort_import_declarations(SortOrder::Maintain)
70+
.module_sort_export_declarations(SortOrder::Maintain)
7171
}
7272

7373
/// The width of a line the printer will try to stay under. Note that the printer may exceed this width in certain cases.
@@ -408,15 +408,15 @@ impl ConfigurationBuilder {
408408
/// Alphabetically sorts the import declarations based on their module specifiers.
409409
///
410410
/// Default: Case insensitive
411-
pub fn statements_sort_import_declarations(&mut self, value: SortOrder) -> &mut Self {
412-
self.insert("statements.sortImportDeclarations", value.to_string().into())
411+
pub fn module_sort_import_declarations(&mut self, value: SortOrder) -> &mut Self {
412+
self.insert("module.sortImportDeclarations", value.to_string().into())
413413
}
414414

415415
/// Alphabetically sorts the export declarations based on their module specifiers.
416416
///
417417
/// Default: Case insensitive
418-
pub fn statements_sort_export_declarations(&mut self, value: SortOrder) -> &mut Self {
419-
self.insert("statements.sortExportDeclarations", value.to_string().into())
418+
pub fn module_sort_export_declarations(&mut self, value: SortOrder) -> &mut Self {
419+
self.insert("module.sortExportDeclarations", value.to_string().into())
420420
}
421421

422422
/// Alphabetically sorts the import declaration's named imports.
@@ -892,8 +892,8 @@ mod tests {
892892
.type_literal_separator_kind_single_line(SemiColonOrComma::Comma)
893893
.type_literal_separator_kind_multi_line(SemiColonOrComma::Comma)
894894
/* sorting */
895-
.statements_sort_import_declarations(SortOrder::Maintain)
896-
.statements_sort_export_declarations(SortOrder::Maintain)
895+
.module_sort_import_declarations(SortOrder::Maintain)
896+
.module_sort_export_declarations(SortOrder::Maintain)
897897
.import_declaration_sort_named_imports(SortOrder::Maintain)
898898
.export_declaration_sort_named_exports(SortOrder::Maintain)
899899
/* ignore comments */

src/configuration/resolve_config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
4444
let prefer_single_line = prefer_single_line_nullable.unwrap_or(false);
4545
let type_literal_separator_kind = get_value(&mut config, "typeLiteral.separatorKind", SemiColonOrComma::SemiColon, &mut diagnostics);
4646

47+
// todo: remove these two lines after 2021-03
48+
handle_renamed_config_property(&mut config, "statements.sortImportDeclarations", "module.sortImportDeclarations", &mut diagnostics);
49+
handle_renamed_config_property(&mut config, "statements.sortExportDeclarations", "module.sortExportDeclarations", &mut diagnostics);
50+
4751
let resolved_config = Configuration {
4852
line_width: get_value(&mut config, "lineWidth", global_config.line_width.unwrap_or(DEFAULT_GLOBAL_CONFIGURATION.line_width), &mut diagnostics),
4953
use_tabs: get_value(&mut config, "useTabs", global_config.use_tabs.unwrap_or(DEFAULT_GLOBAL_CONFIGURATION.use_tabs), &mut diagnostics),
@@ -58,8 +62,8 @@ pub fn resolve_config(config: ConfigKeyMap, global_config: &GlobalConfiguration)
5862
type_literal_separator_kind_single_line: get_value(&mut config, "typeLiteral.separatorKind.singleLine", type_literal_separator_kind, &mut diagnostics),
5963
type_literal_separator_kind_multi_line: get_value(&mut config, "typeLiteral.separatorKind.multiLine", type_literal_separator_kind, &mut diagnostics),
6064
/* sorting */
61-
statements_sort_import_declarations: get_value(&mut config, "statements.sortImportDeclarations", SortOrder::CaseInsensitive, &mut diagnostics),
62-
statements_sort_export_declarations: get_value(&mut config, "statements.sortExportDeclarations", SortOrder::CaseInsensitive, &mut diagnostics),
65+
module_sort_import_declarations: get_value(&mut config, "module.sortImportDeclarations", SortOrder::CaseInsensitive, &mut diagnostics),
66+
module_sort_export_declarations: get_value(&mut config, "module.sortExportDeclarations", SortOrder::CaseInsensitive, &mut diagnostics),
6367
import_declaration_sort_named_imports: get_value(&mut config, "importDeclaration.sortNamedImports", SortOrder::CaseInsensitive, &mut diagnostics),
6468
export_declaration_sort_named_exports: get_value(&mut config, "exportDeclaration.sortNamedExports", SortOrder::CaseInsensitive, &mut diagnostics),
6569
/* ignore comments */

src/configuration/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ pub struct Configuration {
273273
#[serde(rename = "typeLiteral.separatorKind.multiLine")]
274274
pub type_literal_separator_kind_multi_line: SemiColonOrComma,
275275
/* sorting */
276-
#[serde(rename = "statements.sortImportDeclarations")]
277-
pub statements_sort_import_declarations: SortOrder,
278-
#[serde(rename = "statements.sortExportDeclarations")]
279-
pub statements_sort_export_declarations: SortOrder,
276+
#[serde(rename = "module.sortImportDeclarations")]
277+
pub module_sort_import_declarations: SortOrder,
278+
#[serde(rename = "module.sortExportDeclarations")]
279+
pub module_sort_export_declarations: SortOrder,
280280
#[serde(rename = "importDeclaration.sortNamedImports")]
281281
pub import_declaration_sort_named_imports: SortOrder,
282282
#[serde(rename = "exportDeclaration.sortNamedExports")]

src/parsing/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4877,8 +4877,8 @@ fn parse_statements<'a>(inner_span_data: Span, stmts: Vec<Node<'a>>, context: &m
48774877
context: &Context<'a>,
48784878
) -> Option<Box<dyn Fn((usize, Option<&Node<'a>>), (usize, Option<&Node<'a>>), &Context<'a>) -> std::cmp::Ordering>> {
48794879
match group_kind {
4880-
StmtGroupKind::Imports => get_node_sorter_from_order(context.config.statements_sort_import_declarations),
4881-
StmtGroupKind::Exports => get_node_sorter_from_order(context.config.statements_sort_export_declarations),
4880+
StmtGroupKind::Imports => get_node_sorter_from_order(context.config.module_sort_import_declarations),
4881+
StmtGroupKind::Exports => get_node_sorter_from_order(context.config.module_sort_export_declarations),
48824882
StmtGroupKind::Other => None,
48834883
}
48844884
}

tests/specs/statements/sorting/Statements_SortExportDeclarations_CaseInsensitive.txt renamed to tests/specs/file/sorting/Statements_SortExportDeclarations_CaseInsensitive.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ statements.sortExportDeclarations: caseInsensitive ~~
1+
~~ module.sortExportDeclarations: caseInsensitive ~~
22
== should sort the export declarations ==
33
export {} from "a1.ts";
44
export {} from "A2.ts";

tests/specs/statements/sorting/Statements_SortExportDeclarations_CaseSensitive.txt renamed to tests/specs/file/sorting/Statements_SortExportDeclarations_CaseSensitive.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ statements.sortExportDeclarations: caseSensitive ~~
1+
~~ module.sortExportDeclarations: caseSensitive ~~
22
== should sort the export declarations ==
33
export {} from "a1.ts";
44
export {} from "A2.ts";

tests/specs/statements/sorting/Statements_SortExportDeclarations_Maintain.txt renamed to tests/specs/file/sorting/Statements_SortExportDeclarations_Maintain.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ statements.sortExportDeclarations: maintain ~~
1+
~~ module.sortExportDeclarations: maintain ~~
22
== should keep the imports declaration sort order as-is ==
33
export {} from "b.ts";
44
export {} from "a.ts";

tests/specs/statements/sorting/Statements_SortImportDeclarations_CaseInsensitive.txt renamed to tests/specs/file/sorting/Statements_SortImportDeclarations_CaseInsensitive.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ statements.sortImportDeclarations: caseInsensitive ~~
1+
~~ module.sortImportDeclarations: caseInsensitive ~~
22
== should sort the import declarations ==
33
import {} from "a1.ts";
44
import {} from "A2.ts";

tests/specs/statements/sorting/Statements_SortImportDeclarations_CaseSensitive.txt renamed to tests/specs/file/sorting/Statements_SortImportDeclarations_CaseSensitive.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ statements.sortImportDeclarations: caseSensitive ~~
1+
~~ module.sortImportDeclarations: caseSensitive ~~
22
== should sort the import declarations ==
33
import {} from "a1.ts";
44
import {} from "A2.ts";

0 commit comments

Comments
 (0)