I want to write a Python (3.12) script to check indentation in files.
The indentation of the files being searched should use tabs.
I am looking for lines that use space, mixed, empty or alignment indentation.
Space indentation is when the indentation contains only spaces, followed by a non whitespace character.
Mixed indentation is when the indentation contains both tabs and spaces, followed by a non whitespace character.
Empty indentation is when a line only contains tabs and/or spaces and is not followed by a non whitespace character.
Alignment indentation is when the indentation uses tabs from the start of the line and spaces at the end of indentation (for vertical alignment), and the number of spaces is less than the size of a tab stop.
Output should be in the format filepath:lineno: issue_type: 'line'
For example:
C:\GitHub\file1.cpp:1: Space Indentation: ' file1 line.'
C:\GitHub\file2.cpp:2: Mixed Indentation: ' file2 line.'
C:\GitHub\file3.cpp:3: Empty Indentation: ' '
C:\GitHub\file4.cpp:4: Alignment Indentation: ' file4 line.'
An option to process one or more (nargs='*') files or directories (default current directory).
An option to apply one or more (nargs='*') include filters (default none).
An option to apply one or more (nargs='*') exclude filters (default none).
An option to not recurse directories (default false).
An option to set tab stop size (default 4).
An option to set an output file (default stdout).
An option to ignore alignment indentation (default false), the option should accept an optional pattern match (default none).
If no pattern is provided it should ignore all alignment matches.
If a pattern is provided it should be compared against the previous line and only ignored when it also matches.
An example would be to ignore alignment, only if the previous line ended with a comma.
An option to ignore indentation inside C++ style /* */ comments, where they span over multiple lines (default false).
This should ignore indentation (inclusive) from the second line of a multi-line comment, to the line containing the end of the comment.
Accurately track the start/end position of comments, the order matters, it's not sufficient to just use is value in line.
Observe C++ style // single-line comments, to prevent false matches.
Comments cannot be nested.
The comment characters /*, */, and // have no special meaning within a comment.
For example:
This is a C++ style single-line comment and not the start of C++ style multi-line comment:
//**************************************************************************
This is the start of a C++ style multi-line comment and not a C++ style single-line comment:
///***********************************************************************
Comments can start mid-line:.
foo(); /*
* Multi-line comment
*/
There may be more than one comment on a line:
bar(); /* Single multi-line comment 1 / / Single multi-line comment 2 / /
Multi-line comment */
An option to ignore indentation inside XML style comments, where they span over multiple lines (default false).
This will ignore indentation (inclusive) from the second line of a multi-line comment, to the line containing the end of the comment.