#! /usr/bin/env bash
# shellcheck disable=2164
cd /
# shellcheck disable=2103
cd ..
gives a 2103 on the cd .. despite the disable directive on top of it - warning appears on the comment line instead of the cd .. line. This is also the case on the online version.
(cd to / is just for demonstration, I was using a cd to a variable in my actual script)
should properly ignore that line
Writing your code as the following removes the warning:
# shellcheck disable=2164 disable=2103
cd /
cd ..
Is that an issue? As far as I understand, all shellcheck flags are written this way—you must disable the check on a block of code involved, not just the offending line.
Oh wow, it marks the wrong line:
Line 5:
# shellcheck disable=2103
^-- SC2103: Use a ( subshell ) to avoid having to cd back.
It should be marking the cd but instead marks the comment. That's probably why it fails.
@Nightfirecat It's not that it destroys my workflow :P I worked around it already. It's that it's behavior that's unexpected and an obvious bug and worth reporting.
@koalaman It marks the correct line if the directive isn't there though. I didn't dig into the parser code but it feels more like parsing for 2103 specifically ignores comments that have a directive for 2103 (as if it finds them, recognizes them as directives then skips ahead). If it was all comments, then the line would be way off (I've got a 40-50% comment to code ratio). It was the only mistake shellcheck made as well.
In version 0.6.0 the issue still exists.
```#!/bin/bash
echo "anything"
cd /
cd ..```
I have to either add the directive at the top of the file or add checking for output status.
This was fixed in eeb7ea01c. Thanks!
Most helpful comment
Oh wow, it marks the wrong line:
It should be marking the
cdbut instead marks the comment. That's probably why it fails.