Overview

% checkws mercurial extension % Angel Ezquerra

checkws mercurial extension

Introduction

The checkws mercurial extension helps you avoid committing files that do not follow a given set of white space rules, such as having consistent white space (all spaces or all tabs), having no trailing white spaces, not mixing spaces and tabs, having consistent EOL characters, etc.

Note that this extension will (try to!) ignore binary files.

Configuration

Follow these steps to enable and configure the extension

  1. Enable the extension in your mercurial config file by adding:

checkws = /path/to/checkws.py

to the [extensions] section in your mercurial config file

  1. Select the "white space rules" by adding a [checkws] section to your mercurial config file, and setting any of the following configuration keys:

    • trailing: [bool] if enabled check that there are no trailing white spaces (spaces or tabs)
    • indent:
      • if not set, do not check indent character consistency
      • if set to an empty value, check that all lines use the same indent character (either spaces or tabs, but not both)
      • if set to 'tabs' (without the quotes), check that all lines are indented using 'tabs', but not 'spaces'
      • if set to 'spaces' (without the quotes), check that all lines are indented using 'spaces', but not 'tabs'
    • tabsize: [int] Number of spaces per indentation level.
      • if set to a value different than 1, check that all lines begin at an indentation level that is a multiple of tabsize
      • this option is normally used with the indent option enabled as well, but it is not strictly necessary.
    • eol:
      • if not set, do not check EOL consistency
      • if set to an empty value, check that all lines use the same EOL character
      • if set to '\n' (without the quotes), check that all lines have '\n' as its EOL character
      • if set to '\r' (without the quotes), check that all lines have '\r' as its EOL character

    All these checks are disabled by default, except the check for 'mixed indent', which is always active.

    • exclude: A list of filenames (and/or globs) that will be ignored from the "white space check"

Usage

The extension is triggered automatically on commit. It will check that the changed lines follow the selected configuration. If any file does not follow it, an error message will be shown and the commit will fail.

Example configurations

check for white space and eol consistency,

but do not force a given indent or EOL character

Run pandoc on all markdown (.md) files whenever you update or commit

[extensions]
checkws = /path/to/checkws.py

[checkws]
indent =
eol =

trailing = true # Check that there are no trailing white spaces (spaces or tabs)

check that there are no trailing white spaces

[extensions]
checkws = /path/to/checkws.py

[checkws]
trailing = true # Check that there are no trailing white spaces (spaces or tabs)

full check

[extensions]
checkws = /path/to/checkws.py

[checkws]
trailing = true # Check that there are no trailing white spaces (spaces or tabs)
indent = spaces
tabsize = 4
eol = \n

License

This extension was created by Angel Ezquerra. This extension is Free Software and licensed under the terms of the GPL v2.