0

I want to ignore shellcheck when writing a LaTeX document while using minted package. I know, when using shellcheck I can easily ignore warnings or errors globally by placing a line right at the beginning of the document. E.g.# shellcheck disable=SC2148 to ignore an error for not giving a shebang.

Note, I am using sublime text on Mac. I furthermore installed shellcheck, chktex and pygmentize. (As there is also chktex written in the sublime status bar I don't know if this also plays into it)

A minimal working example

\documentclass[a4paper]{article}
\usepackage{minted}
\begin{document}
\begin{minted}{shell}
  ls -al
\end{minted}
\end{document}

This complains for not mentioning a shebang.

If I do

\documentclass[a4paper]{article}
\usepackage{minted}
\begin{document}
\begin{minted}{shell}
  # shellcheck disable=SC2148
  ls -al
\end{minted}
\end{document}

everything works just fine. But as I am having numerous minted environments I want to disable errors globally.

EDIT

Of course I could just disable shellcheck for the whole project. This is done by editing the corresponding project file

{   
    "folders":
    [
     ...
    ],
    "SublimeLinter":
    {
        "linters":
        {
            "shellcheck": {
                "disable": true
            }
        }
    }
}

However, I am searching for a way to disable it on a per file basis, not on project basis.

  • Welcome to TeX.SX! I'm not sure what's the purpose of running shellcheck over a LaTeX file. When you include the scripts in the LaTeX document, you will already have checked them. – egreg May 16 '18 at 7:30
  • Actually me neither. I am using shellcheck for my scripts. I was also surprised when I learned that shellcheck is applied kind of automatically to minted environment. I actually never specified to run it on my latex files. – Stefan May 16 '18 at 8:43
  • I have the impression that Sublime Text tries to outsmart users. – egreg May 16 '18 at 8:51
  • I updated my post, to specify the problem further and added a possible workaround. – Stefan May 16 '18 at 9:47
0

What you have here is a sort of interference between two well-intentioned features. On the one hand, SublimeLinter-shellcheck will run shellcheck against almost all code that Sublime scopes as being shell script. This allows the linter to support non-standard shell syntax and shell syntax embedded in other files. On the other hand, the LaTeX syntax scopes minted blocks to the appropriate syntax so you get syntax highlighting while editing the file.

As you discovered, you can use the "disable" setting to disable the longer altogether, but you have a couple of other options. The first is to change the "selector" setting from the default of "source.shell - source.makefile - source.shell.fish" to "source.shell - source.makefile - source.shell.fish - text.tex". This will stop shellcheck from being run on any TeX / LaTeX document. The other option is to change the ”excludes" setting to something like "*/*.tex", which should stop it from running on any file with the extension .tex. Either of these settings can go in the same place you put the "disable" setting or in your user settings, etc.

  • Thanks. We are almost there. With this I can exclude certain files. However, as you mentioned, this configuration need to be placed either in the project configuration or in the SublimeLinter configuration under linters. Are you aware of a way to just add a line to the beginning of the document I want to exclude from being shellchecked? – Stefan May 17 '18 at 6:47
  • @Stefan: AFAIK, no, there’s nothing like that. – ig0774 May 17 '18 at 13:36
  • Ok, thanks. As it seems that we have covered all options, I'll accept it as an answer to my question. – Stefan May 18 '18 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.