Shellcheck: SC2013 not disabled by directive unless placed at start of file or block

Created on 1 May 2017  路  5Comments  路  Source: koalaman/shellcheck

For bugs

  • Rule Id: SC2013
  • Version: 0.4.6
  • [X] I tried on shellcheck.net and verified that this is still a problem on the latest commit
#! /usr/bin/env bash

# shellcheck disable=2164
cd /
# shellcheck disable=2103
cd ..

shellcheck says:

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)

Here's what I wanted or expected to see:

should properly ignore that line

Most helpful comment

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.

All 5 comments

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"

shellcheck disable=SC2103 disable=SC2164

cd /

shellcheck disable=SC2103

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathaniel112 picture nathaniel112  路  4Comments

ymkjp picture ymkjp  路  3Comments

sobolevn picture sobolevn  路  4Comments

ghost picture ghost  路  4Comments

phagara picture phagara  路  4Comments