Skip to main content

Simple source code validator with file reformatting option (remove trailing WS, pretty print XML, ..)

Project description

Simple source code validator with file reformatting option (remove trailing WS, pretty print XML, ..).

For Python code formatting it can either use autopep8 or the builtin copy of PythonTidy.

Requirements

  • Python 2.7+

  • lxml (for XML formatting)

  • pep8 (for Python checking)

  • autopep8 (for Python formatting)

  • pyflakes (for static Python code checking)

  • Jalopy (for Java code formatting)

  • coffeelint (for CoffeeScript validation)

  • PHP_CodeSniffer (for PHP style checking)

  • Puppet (for Puppet manifest validation)

  • sqlparse

  • jshint (for JavaScript checking)

On Ubuntu you can install most packages easily:

sudo apt-get install python-lxml pep8 pyflakes nodejs npm
sudo npm install -g jshint

Getting Started

Validating test files with builtin default configuration:

./codevalidator.py test/*

Fixing test files (removing trailing whitespace, XML format):

./codevalidator.py -f test/*

Using custom configuration file:

./codevalidator.py -c test/config.json test/*

Validate and fix a whole directory tree:

./codevalidator.py -c myconfig.json -rf /path/to/mydirectory

Validate a single PHP file and print detailed error messages (needs PHP_CodeSniffer with PSR standards installed!):

./codevalidator.py -v test/test.php

Running in very verbose (debug) mode to see what is validated:

./codevalidator.py -vvrc test/config.json test

Using the filter mode to “fix” stdin and write to stdout:

echo 'print 1' | ./codevalidator.py --fix --filter foobar.py && echo success

If you are annoyed by the .XX.pre-cvfix backup files you can disable them either on the command line (--no-backup) or in the config file.

Advanced Usages

You can use the --fix --filter combination to directly filter your current buffer in VIM:

:%!codevalidator.py --fix --filter %

The --fix --filter was also designed to be used with GIT filters.

To apply a formatting rule once without changing you configuration file, you can use the -a option. Formatting a Python file once with the pythontidy rule looks like:

./codevalidator.py -a pythontidy myfile.py

Known Issues

  • PythonTidy cannot parse dict comprehensions. As a workaround you can use list comprehensions and wrap it with dict.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codevalidator-0.8.tar.gz (32.9 kB view details)

Uploaded Source

File details

Details for the file codevalidator-0.8.tar.gz.

File metadata

  • Download URL: codevalidator-0.8.tar.gz
  • Upload date:
  • Size: 32.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for codevalidator-0.8.tar.gz
Algorithm Hash digest
SHA256 10cc1b3ea3edd11db4b00bb0b7e3ef5f32379bf23ee5c58594df6148f626a90c
MD5 119fd2b2929d37d5fe212c6d9ffec3d2
BLAKE2b-256 ac587493f7b21689422ad8e5532169115d6278bf98ff86a7c99c2f4e14099de7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page