Skip to content

Sourcing: "strip one leading, dynamic section before trying to locate the rest" #926

Closed
@aarondill

Description

@aarondill

What is the problem this feature will solve?

When writing code like this:

here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
. "$here/config.sh"
. "$here/utils.sh"

shellcheck will understand that it should search the script dir for the files, but bash lsp doesn't.

What is the feature you are proposing to solve the problem?

To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest. That means that ShellCheck will look for config.sh and utils.sh in the same directory as this script when it is being checked:

So, let's strip one leading, dynamic section before trying to locate the rest 😄

This can work with #811 by only taking effect when the variable is truly dynamic, instead using the value if it's constant (ie set earlier in the script)

What alternatives have you considered?

# shellcheck source=./.utils.d/output.sh - this gets quite frustrating when shellcheck understands the location of the file, but bash-lsp doesn't

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions