Integrate Typoscript linter into VIM

As more and more people like to lint their files, it’s obvious that we also should lint our Typoscript files in TYPO3 projects. Therefore Martin Helmich has created a Typoscript parser and Typoscript linter.

In this blog post you will learn how to integrate this linter into vim and neovim by using syntastic as a plugin.

Install dependencies

First of all you need syntastic to be installed properly, refer to their docs for installation guideline.

Also you need to have the linter installed. We prefer composer:

composer require --dev helmich/typo3-typoscript-lint

That will install the linter package with all dependencies into your project. By default the binary will be installed into vendor/bin/typoscript-lint. But the concrete path depends on your composer settings. Also it’s possible to install the package globally.

Configure VIM

After all dependencies are installed, we need to add the syntax checker for Typoscript. The file has to be located at syntax_checkers/typoscript/lint.vim inside your runtimepath, e.g. ~/.vim/syntax_checkers/typoscript/lint.vim.

The file has the following content:

if exists('g:loaded_syntastic_typoscript_lint_checker')
    finish
endif
let g:loaded_syntastic_typoscript_lint_checker = 1

let s:save_cpo = &cpo
set cpo&vim

function! SyntaxCheckers_typoscript_lint_GetLocList() dict
    let makeprg = self.makeprgBuild({
        \ "exe": self.getExec(),
        \ "args": '--format=checkstyle',
        \ })

    let errorformat = '%f:%t:%l:%c:%m'

    return SyntasticMake({
        \ 'makeprg': makeprg,
        \ 'errorformat': errorformat,
        \ 'preprocess': 'checkstyle',
        \ 'postprocess': ['guards'] })
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
    \ 'filetype': 'typoscript',
    \ 'name': 'lint'})

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: set sw=4 sts=4 et

Also add the path to your installed executable, e.g. inside of ~/.vimrc like so:

let g:syntastic_typoscript_lint_exec='./vendor/bin/typoscript-lint'

If you have installed the binary on a per project base with default paths. Otherwise adjust accordingly. If your path is different on a project level, take a look at Folder specific settings in Vim.

Further reading