Skip to content

Commit 815affc

Browse files
committed
fix(formatter): default null-type-hint to question mark syntax for PER-CS compliance
closes #771 Signed-off-by: azjezz <[email protected]>
1 parent 6c0884a commit 815affc

File tree

11 files changed

+22
-9
lines changed

11 files changed

+22
-9
lines changed

crates/formatter/src/settings.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,21 @@ pub struct FormatSettings {
555555

556556
/// How to format null type hints.
557557
///
558-
/// With `NullPipe`:
558+
/// With `Question`:
559559
/// ```php
560-
/// function foo(null|string $bar) {
560+
/// function foo(?string $bar) {
561561
/// return $bar;
562562
/// }
563563
/// ```
564564
///
565-
/// With `Question`:
565+
/// With `NullPipe`:
566566
/// ```php
567-
/// function foo(?string $bar) {
567+
/// function foo(null|string $bar) {
568568
/// return $bar;
569569
/// }
570570
/// ```
571571
///
572-
/// Default: `NullPipe`
572+
/// Default: `Question`
573573
#[serde(default)]
574574
pub null_type_hint: NullTypeHint,
575575

@@ -1083,9 +1083,9 @@ impl FromStr for EndOfLine {
10831083
/// Specifies null type hint style.
10841084
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord, JsonSchema)]
10851085
pub enum NullTypeHint {
1086-
#[default]
10871086
#[serde(alias = "null_pipe", alias = "pipe", alias = "long", alias = "|")]
10881087
NullPipe,
1088+
#[default]
10891089
#[serde(alias = "question", alias = "short", alias = "?")]
10901090
Question,
10911091
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
..Default::default()
34
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
FormatSettings::default()
1+
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
3+
..Default::default()
4+
}

crates/formatter/tests/cases/issue_166/settings.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
preserve_breaking_parameter_list: true,
34
break_promoted_properties_list: false,
45
..Default::default()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
always_break_named_arguments_list: true,
34
..Default::default()
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
empty_line_before_return: true,
34
..Default::default()
45
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
FormatSettings::default()
1+
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
3+
..Default::default()
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
always_break_named_arguments_list: true,
34
..Default::default()
45
}

crates/formatter/tests/cases/spacing_options_flipped/settings.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FormatSettings {
2+
null_type_hint: NullTypeHint::NullPipe,
23
always_break_named_arguments_list: true,
34
space_around_assignment_in_declare: true,
45
space_within_grouping_parenthesis: true,

crates/formatter/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs;
44

55
use mago_formatter::Formatter;
66
use mago_formatter::settings::FormatSettings;
7+
use mago_formatter::settings::NullTypeHint;
78
use mago_php_version::PHPVersion;
89

910
#[macro_export]

0 commit comments

Comments
 (0)