Shellcheck: JetBrains Webstorm Integration

Created on 25 Apr 2015  Â·  9Comments  Â·  Source: koalaman/shellcheck

I really do love this tool and I'm wondering if you have a thought to make this tool available as plugin in https://www.jetbrains.com/ IDEs?

Thanks

Most helpful comment

I have a usage in WebStorms.

Go to _File | Settings | Tools | External Tools_ for Windows and Linux, or _WebStorm | Preferences | Tools | External Tools_ for OS X, and click + to add a new tool.

  • Name set Shellcheck
  • Program set shellcheck
  • Parameters set $FilePathRelativeToProjectRoot$
  • Working directory set $ProjectFileDir$

screenshot from 2017-07-02 02-07-26

If you add hotkey for it.
Go to _File | Settings | Keymap_ for Windows and Linux, _WebStorm | Preferences | Keymap_ for OS X, and type external tool name in search box.

This usage also applies to other JetBrains series(IntelliJ IDEA, PyCharm,PhpStorm, etc.).

All 9 comments

There's probably already a CheckStyle plugin for these, in which case you can use it with shellcheck's CheckStyle compatible xml output.

@koalaman , I could not find any plugins for WebStorm that can validate source code as good as shellcheck, not even close. The only plugin available for bash in WebStorm is: http://plugins.jetbrains.com/plugin/?id=4230

I meant that the plugin wouldn't have to support bash at all. You can use a plugin that only supports validating for example C or Java code.

This works because shellcheck can mimic some of the underlying tools these plugins use:

$ gcc file.c
file.c:2:3: error: ‘foo’ undeclared (first use in this function)

$ clang file.c
file.c:2:3: error: use of undeclared identifier 'foo'; did you mean 'for'?

$ shellcheck -f gcc file.sh
file.sh:2:3: error: Double quote array expansions. [SC2068]

Since all these error messages have the same format, any plugin that supports showing errors from gcc or clang for C code also supports showing errors from ShellCheck, even if they were never intended to support shell scripts.

Similarly, ShellCheck can output CheckStyle XML, which your site lists an IDEA plugin for (but not a WebStorms plugin).

I don't have access to WebStorms so I can't test or suggest which plugins work well this way. However, it works fine in other editors that nominally only supports gcc, like Vim.

I have a usage in WebStorms.

Go to _File | Settings | Tools | External Tools_ for Windows and Linux, or _WebStorm | Preferences | Tools | External Tools_ for OS X, and click + to add a new tool.

  • Name set Shellcheck
  • Program set shellcheck
  • Parameters set $FilePathRelativeToProjectRoot$
  • Working directory set $ProjectFileDir$

screenshot from 2017-07-02 02-07-26

If you add hotkey for it.
Go to _File | Settings | Keymap_ for Windows and Linux, _WebStorm | Preferences | Keymap_ for OS X, and type external tool name in search box.

This usage also applies to other JetBrains series(IntelliJ IDEA, PyCharm,PhpStorm, etc.).

@WindomZ thanks for this post, I have set up clang-format in a similar fashion.

This is a generic way to proceed when there's a binary available, but no inline linter.

You can also use the method above by @WindomZ in conjunction with output filters, so that errors are hyperlinked to the file, line and column.

_Settings | Tools | External Tools_

  • Program: shellcheck
  • Parameters: -f gcc $FilePath$
  • Working directory: $ProjectFileDir$

Output Filters...

  • Name: gcc
  • Description: The gcc output format.
  • Regular expression to match output: $FILE_PATH$:$LINE$:$COLUMN$

screen shot 2017-08-31 at 4 00 51 pm

Hello fellow Googler. Here's what you came for:

Step 1

Set up external command. Important thing is that the working dir is the root of your system (or your harddrive letter on Windows).
Step 1

Step 2

Set output filter. It only matches the file name with full path, which is why we run shellcheck in the root dir.
Step 2

Step 3

Optionally set up hooks or key bindings.
Step 3

Profit

Sample result:
Profit

I've linked to this thread from https://github.com/koalaman/shellcheck/wiki/Contrib

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathaniel112 picture nathaniel112  Â·  4Comments

arth1 picture arth1  Â·  4Comments

ghost picture ghost  Â·  4Comments

szepeviktor picture szepeviktor  Â·  4Comments

erwinkramer picture erwinkramer  Â·  5Comments