Table Of Contents

Previous topic

Running and integration

Next topic

System prerequisites

This Page

Validators and linters

Introduction

Here are listed different validator and linting modules supported by VVV.

Text files, generic

Tab policy

Validator name: tabs

Do not allow hard tabs in committed files. Instead, use soft tabs and spaces.

To allow hard tabs in any file add the following in your validator-options.yaml:

tabs:
    enable: false

To allow hard tabs in specific files use validator-files.yaml:

tabs:
  Makefile
  *.mk 

Mass converting tabs to spaces

VVV provides a Python script to expand tabs to spaces in-place.

See vvv-expand-tabs.

Supported files

  • All text files, Makefiles are excluded by default

Options

No options.

Line length

Validator name: linelength

Check that that text file lines are not too long.

Prerequisites

Built-in - no external software needed.

Supported files

  • All text files.

Options

length

Set maximum allowed line length. Defaults to 80 columns.

Example validator-options.yaml:

# Allow long text lines
linelength:
    length: 250

Evil spacebar buster

Validator name:: evilspace

Make sure text files do not contain no-break space (NBS) character.

  • ALT + spacebar inserts non-breaking spacebar on Linux systems. It kind of makes sense ALT means alternative and evil space is the alter ego of normal space. Its invisibly grins when your code falls apart.
  • OPTION + spacebar inserts non-breaking spacebar on OSX systems
  • It is totally possible that you accidentally type plenty of these characters if you are workign on non-US keyboard when you frequently need to press ALT to for characters for proramming grammar. Example. if(foobar || foobar2) {.
  • Non-breaking spacebar (NBSP) character cannot be distinguished from normal space, as they both are, well..., invisible
  • A lot of compilers, linters, Javascript compressors, etc. cannot handle this character properly and fall into very interesting failure modes which are hard to debug
  • This is especially important when creating Javascript code because browsers threat NBS differently

Supported files

All text files.

Options

No options.

Programming languages

Javascript (jshint)

Validator name: jshint

Lint Javascript files using jshint.

Prerequisites

Your system supports Node.js and must have jshint package installed.

Please see prerequisites.

Installation

You must use Node npm to install node-jshint package.

sudo npm install -g jshint

Supported files

  • *.js

Options

Options for jshint section in validation-options.yaml.

Example validation-options.yaml:

jshint:
    configuration: |
        {
            eqeqeq : true
        }

Warning

Make sure configuration is valid JSON. jshint silently ignores these options otherwise.

configuration

Pass in .jshintrc configuration options.

command-line

Pass in extra arguments for the jshint command line.

Mass adding global hints

VVV provides a Python script to add /* global */ hints to several Javascript files once.

See vvv-add-js-globals.

Python (pylint)

Validator name: pylint

Lint Python files using Pylint.

Installation

Warning

pylint installation is broken for Python 3.x - please see notes below

A temporarily virtualenv environment is automatically created where pylint command and its dependencies are is installed. However this is not very good way to run pylint, as if you are using any third party libraries pylint cannot import them and thus fails.

It is recommended to use host-python-env option - this whill install pylint to a Python environment which you enable before running.

Example (assuming you have host-python-env set in validate-options.yaml):

# Activate virtualenv
source venv/bin/activate

# Run vvv and install pylint to now activate Python env
vvv --reinstall

The default pylint checks are very strict. You might want to see a more relaxed configuration example:

* https://github.com/miohtama/vvv/blob/master/validation-options.yaml

Supported files

  • *.py

Options

Example validation-options.yaml:

pylint:
    python3k: true

    command-line: --reports=n
host-python-env

If true do not create a virtualenv for running pylint, but install pylint using the active python environment where vvv is run.

Default is false.

Note

If you change this you need run vvv --reinstall.

pylint-command

A path spec pointing to used pylint command.

Use this command to run pylint. This is for cases where host-python-env is not enough to tame your Python package dependencies.

If this option starts with . it is considered to be a directory reference relative to the project root.

IF this option starts with / it is considered to be absolute directory reference.

Otherwise normal path look behavior is used (UNIX which commmand behavior).

Example:

pylint:
  enabled: true
  python3k: false
  # Points to buildout/bin/pylint command two levels below project folder
  pylint-command: ../../bin/pylint
command-line

Give pylint command line options.

Default:

--reports=n --include-ids=y
configuration

Pass in pylint configuration file data. This is a block of text which gets passed in as pylint .rc file. For rc file example run command:

pylint --generate-rcfile
python3k

If true set-up pylint for Python 3.x. The default is Python 2.x.

Note

If you change this you need run vvv --reinstall.

Other

To disable warning per source code file one can add pylint hints in the .py files using pylint: directives like:

# :R0201: *Method could be a function*
# W0102 Dangerous default value [] as argument
# R0921 Abstract class not referenced
# :W0611: *Unused import %s*
# pylint: disable=R0201, W0102, R0921, W0611

These can be function or module level scoped.

To see all pylint error and warning message ids:

pylint --list-msgs

And to find a message id:

pylint --list-msgs|grep -i "Dangerous default"
:W0102: *Dangerous default value %s as argument*

pylint bugs

Currently you need to manually fix logilab-astng package for Python 3 with trunk version.

The error:

  File "/Users/moo/code/vvv/dist/test/lib/python3.2/site-packages/logilab_astng-0.23.1-py3.2.egg/logilab/astng/scoped_nodes.py", line 249, in file_stream
    return file(self.file)
NameError: global name 'file' is not defined

If you are using a .vvv virtualenv:

cd ~/.vvv
source pylint/pylint-virtualenv/bin/activate
hg clone http://hg.logilab.org/logilab/astng
cd astng
python setup.py install

If you are using host-python-env option:

source YOURVIRTUALENV/bin/activate
hg clone http://hg.logilab.org/logilab/astng
cd astng
python setup.py install

After this re-run vvv and everything should go ok.

Python (pdb breakpoints)

Validator name:: pdb

Do not allow Python pdb breakpoints in the committed files.

E.g. this will fail:

def foo(self):
        import pdb ; pdb.set_trace()

The validator match for pdb.set_trace() in uncommented lines.

Supported files

*.py

Options

No options.

Web development

CSS (W3C validator)

Validator name: css

Validate CSS files against W3C CSS validator.

Prerequisites

Your system must have Java installed and support and java command.

Please see prerequisites.

Installation

CSS validator is Java executable and bunch of JAR files which are downloaded and installed automatically.

Supported files

  • *.css

Options

command-line

Command line arguments passed to W3C validator.

Default:

--profile=css3

Troubleshooting

If you get error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/tools/resources/ProtocolException
Caused by: java.lang.ClassNotFoundException: org.w3c.tools.resources.ProtocolException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

It is probably caused by a broken automatic W3C validator installation and you can fix it with:

rm -rf ~/.vvv/css 

Other mark-up

Restructred Text (rst)

Validator name: rst

Check that .rst files do not contain syntax errors using docutils. Restructured format is used by Sphinx documentatio tool and also supported by Github README files.

Note

Unknown restructured directives errors are ignored, mainly because systems like Sphinx add their own directives.

Installation

Works out of the box.

Supported files

  • *.rst

Options

None.