Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: array globs not parsed correctly #850

Closed
philsc opened this issue Apr 19, 2022 · 3 comments
Closed

syntax: array globs not parsed correctly #850

philsc opened this issue Apr 19, 2022 · 3 comments

Comments

@philsc
Copy link

philsc commented Apr 19, 2022

The following script is rejected by shfmt:

#!/bin/bash
readonly -a new_patches=( [0-9][0-9][0-9][0-9]-*.patch )

The intent is to glob up all the patch files generated with git format-patch.

We get this error:

$ shfmt foo.sh
foo.sh:2:27: "[x]" must be followed by =

I'm assuming that it thinks we're using associative arrays here.

This is on the latest version as far as I can tell:

$ shfmt -version
v3.4.3
@mvdan
Copy link
Owner

mvdan commented Apr 19, 2022

Yep, this is a known limitation of the parser; see #558. It is fixable, but not trivially so, as it requires support for ambiguous syntax parsing (e.g. backtracking).

@mvdan mvdan closed this as completed Apr 19, 2022
@philsc
Copy link
Author

philsc commented Apr 20, 2022

Is there a way via a comment or something to disable formatting on a certain line?
Similar to clang-format's // clang-format: off?

@mvdan
Copy link
Owner

mvdan commented May 9, 2022

I'm afraid not, but you can split your code between multiple files as an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants