Skip to content

Wrong optional access order #97

@KP64

Description

@KP64

Describe the bug

When optionally accessing something, from e.g. $env, nufmt is confuses the question mark and the attribute's positions.

Steps To Reproduce

Steps to reproduce the behavior:

Input File

def start_zellij [] {
  if "ZELLIJ" in $env {
    return
  }

  if ($env.ZELLIJ_AUTO_ATTACH? | default "false") == "true" {
    zellij attach -c
  } else {
    zellij
  }

  if ($env.ZELLIJ_AUTO_EXIT? | default "false") == "true" {
    exit
  }
}

Incorrect Formatted File

def start_zellij [] {
    if "ZELLIJ" in $env { return }
    if ($env.?ZELLIJ_AUTO_ATTACH | default "false") == "true" { zellij attach -c } else { zellij }
    if ($env.?ZELLIJ_AUTO_EXIT | default "false") == "true" { exit }
}

Expected behavior

Accessing optionally should not reorder attribute and question mark:

def start_zellij [] {
    if "ZELLIJ" in $env { return }
    if ($env.ZELLIJ_AUTO_ATTACH? | default "false") == "true" { zellij attach -c } else { zellij }
    if ($env.ZELLIJ_AUTO_EXIT? | default "false") == "true" { exit }
}

Environment

Please run rustc --version and paste the result.

[user@system:~]$ rustc --version
rustc 1.93.0 (254b59607 2026-01-19) (built from a source tarball)

If using Nix please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.18.13-zen1, NixOS, 26.05 (Yarara), 26.05.20260318.b40629e`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.34.1`
 - nixpkgs: `/nix/store/ap9dpkyzikzzh04259wlsvha2mw455x4-source

Notify maintainers

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions