tree-sitter / tree-sitter-bash

Bash grammar for tree-sitter
MIT License
211 stars 64 forks source link

Bugs that practically can't be fixed #214

Open amaanq opened 1 year ago

amaanq commented 1 year ago

As mentioned here, a few possible bash expressions are just not feasible to parse, and do have shellcheck emit errors about them too.

First is a command substitution with "$((" which is also used by arithmetic expansions - it's just impossible to distinguish them and shellcheck

$((use fancy || use taamey) && echo ttf)

we cannot know if it's one or the other without some really complex scanner logic - and shells have different behavior regarding this according to shellcheck, some don't allow it and some do, so please, do not do this.

Another one is..this monstrosity:

word="`echo \"${2}\" | sed -e\"s|=.*$||\" -e\"s|^.*opt ||\"`"

This makes me dizzy just thinking about it, but I'm pretty sure statefulness would be needed for stuff within quotes within escaped quotes - that's just too much (the main issue is the $)

Lastly, there's this:

[ -e "${EROOT}"/usr/lib/gtk-2.0/2.[^1]* ]

Which, according to shellcheck -e doesn't even work with globs, and I'm not sure if this is entirely valid anyways. Imo this is the easiest one to fix but I'm just unsure about its validity.

Ordoviz commented 1 year ago

Regarding [ -e "${EROOT}"/usr/lib/gtk-2.0/2.[^1]* ]: This is sloppy but valid code. Bash will expand the glob /usr/lib/gtk-2.0/2.[^1]* (since it's unquoted) and pass the matching filenames as arguments to the [ builtin.