Skip to content

Latest commit

 

History

History

PlainTextLinter

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

OVERVIEW

ptlint.pl version 1.05

This is a linter for plain text files. It helps you keep your text files tidy by checking rules like "there should be no whitespace at the end of the lines" or "do not indent with tab characters, but with spaces".

It is not very sophisticated, but it covers my needs with a minimum of fuss.

You need a Perl interpreter installed on your system to run this script.

USAGE

perl ptlint.pl [options] [--] <filename...>

Options are read from environment variable PTLINT_OPTIONS first, and then from the command line.

NON-LINT OPTIONS

  • -h, --help

    Print this help text.

  • --help-pod

    Preprocess and print the POD section. Useful to generate the README.pod file.

  • --version

    Print this tool's name and version number (1.05).

  • --license

    Print the license.

  • --

    Terminate options processing. Useful to avoid confusion between options and filenames that begin with a hyphen ('-'). Recommended when calling this script from another script, where the filename comes from a variable or from user input.

  • --verbose

    Show more progress information.

LINT OPTIONS

You need to specify at least one lint options. Otherwise, this script will not really lint the files.

  • --eol=mode

    The end-of-line modes are:

    ignore = do not check the end-of-line characters

    consistent = all end-of-line characters must be the same (the default)

    only-lf = all end-of-line characters must be LF (10 = 012 = 0x0A, UNIX style)

    only-crlf = all end-of-line characters must be CR, LF (13, 10 = 015, 012 = 0x0D, 0x0A, DOS style)

    There are many ways to change the EOL characters in a text file. One option is to use tools 'dos2unix' and 'unix2dos'.

  • --no-trailing-whitespace

    Check that the text lines have no trailing whitespace, as it is often unwelcome.

    Git Gui, for example, highlights trailing whitespace in red colour.

    Whitespace actually means spaces or tab characters.

    There are many ways to remove trailing whitespace from text files. For example:

    sed --in-place 's/[ \t]\+$//' *.txt
  • --no-tabs

    Check that the text lines have no tab characters.

    This normally means that you will be indenting with spaces.

    There are many ways to replace tab characters with spaces in text files. For example:

    expand --tabs=8 "old.txt" >"new.txt"
  • --only-ascii

    Check that no characters are >= 127 (>= 0x7F).

  • --no-control-codes

    Check that no characters are < 32 (0x20, space). Exceptions are tab (9), CR (13) and LF (10).

  • --max-line-len=n

    The maximum allowed line length in characters.

    Note that one UTF-8 character may be encoded with several bytes.

  • --encoding=utf8

    Assumes that all text files are encoded in UTF-8. Invalid UTF-8 character encodings will be reported as lint warnings.

    Note that the presence of a UTF-8 BOM in any file will automatically enable the UTF-8 encoding mode for that file, regardless of the '--encoding' option.

  • --bom=type

    The types of "byte order mark" are:

    • no-check

      Do not enforce the presence or the type of BOM (the default).

      Note that the presence of a UTF-8 BOM in any file will automatically enable the UTF-8 encoding mode for that file.

    • utf8

      There must be a UTF-8 BOM. Otherwise, a lint warning will be generated.

OUTPUT

All lint messages go to stdout.

The lint message format is the same as GCC compilation errors, so Emacs' compilation-mode will recognise and hyperlink them to their file locations.

EXIT CODE

Exit code:

0 means success without any lint warnings.

1 means some lint warnings were generated.

2 means some other error.

CAVEATS

  • This tool does not fix any rule violations, it just reports them.

  • Processing is line oriented, so you only get 1 warning of each type per text line.

  • Only the default system encoding and UTF-8 are supported at the moment.

    There is no support for UTF-16 or UTF-32 BOMs, and there is no way yet to specify a particular character encoding for text files.

FEEDBACK

Please send feedback to rdiezmail-tools at yahoo.de

LICENSE

Copyright (C) 2022 R. Diez

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License version 3 for more details.

You should have received a copy of the GNU Affero General Public License version 3 along with this program. If not, see http://www.gnu.org/licenses/.