Skip to content

syntax: support IFS=,; echo ... on a single line #1243

@bstrdsmkr

Description

@bstrdsmkr

I'm using shfmt through this VSCode extension: https://marketplace.visualstudio.com/items?itemName=lumirelle.shell-format-rev

I have a few lines where I believe the resulting formatting is worse than the original, so I'd like to have those lines not formatted without throwing the baby out with the bathwater and ignoring the whole thing.

An example line before formatting:

SQL_EXTENSIONS_FLAG="--conf spark.sql.extensions=$(IFS=,; echo "${SPARK_SQL_EXTENSIONS[*]}")"

And after formatting:

SQL_EXTENSIONS_FLAG="--conf spark.sql.extensions=$(
                                                   IFS=,
                                                          echo "${SPARK_SQL_EXTENSIONS[*]}"
)"

And the flags currently in use:

"--indent=2 --binary-next-line --keep-padding --simplify"

I'd expected to be able to ignore this line via pragma comments like most other formatters, but was disappointed to see in #700 that it was a conscious decision to ignore this feature.

The advice at the end of that thread was to open an issue for cases that don't seem easily handled in other ways, so here I am 😁

As a secondary issue that would be resolved by supporting such pragma comments, it's often difficult as a user to describe the issue you're seeing and search for existing issues that might cover your case, thus generating more duplicate issues.

I believe no automated action can be perfect, so they all need an escape hatch. With that, I'd like to advocate for reconsideration of pragma comments as that escape hatch. It seems like # fmt: on/off/skip comments are the most common in the formatter communities, so that's what I'd personally prefer.

The central issue against them in #700 seemed to be in deciding the appropriate action in edge cases. To aid in that, I believe the ruff developers have had some publicly available discussions and decisions around that, such as: astral-sh/ruff#6338

So in summary:

  1. Advocating for pragma comment support for re-format suppression
  2. Seeking alternatives for the code example provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions