lint381
checks your EECS 381 projects for coding style errors.
See http://umich.edu/~eecs381/ for the course homepage. The coding standards can be found here:
Here's lint381
in action:
See CONTRIBUTING.md for information on how to contribute to the project. Patches welcome!
lint381
requires Python 3, so you may want to install it inside a virtualenv
or use pip3
instead of pip
.
Install it:
$ pip install lint381
Pass source files to lint381
to have it check them. Typically you'll just use
a pattern like *.cpp *.h
to match all source files in the current directory.
$ lint381 *.cpp *.h
If lint381
detected any errors, it will exit with a non-zero status and print
the errors. Otherwise it will exit with zero and produce no output.
By default, lint381
assumes your source files are in C++. You can explicitly
set the language with --lang=c
or --lang=cpp
:
$ lint381 --lang=c *.c *.h
The C linter flags the following:
- Use of prohibited types (such as
unsigned
andfloat
). - Macros that start with an underscore, as they are reserved by the implementation.
- Non-uppercase
#defines
(#define foo
is wrong,#define FOO
is right). struct
s andenum
s that aren't capitalized.enum
s that don't end with_e
.typedef
s that don't end with_t
.- Non-idiomatic comparison to
NULL
(such asif (foo == NULL)
). - Enum members that aren't all-caps.
- Casting the result of
malloc
(such asfoo = (char*) malloc(...)
). - Defining string constants as an array instead of a pointer.
- Use of
sizeof(char)
. - Putting user includes after system includes.
- Not including the module header as the first include in the file.
The C++ linter flags the following:
- All C checks above, except those that are obviated (e.g. we now use
nullptr
instead ofNULL
, and don't usemalloc
). - Comments with three asterisks (
***
) as those are provided by Kieras and should be removed. - Use of
NULL
instead ofnullptr
. - Use of
malloc
/free
instead ofnew
/delete
. - Use of
typedef
instead ofusing
. - Use of prohibited functions such as
memmove
orexit
. - Creating a type alias for an iterator instead of its container (i.e.
using Foo_t = std::vector<int>::iterator
instead ofusing Foo_t = std::vector<int>; /* ... */ Foo_t::iterator
). - Use of
#define
to create constants. - Use of
class
instead oftypename
in template parameters. - Use of
0
or1
in loop conditions instead oftrue
orfalse
. - Use of
string::compare
. - Comparing
size()
to0
instead of usingempty
. - Use of post-increment instead of pre-increment for iterators.
- Catching exceptions by value instead of by reference.
- Unused
using
-statements, such asusing std::cout;
. - Using
enum
s instead ofenum class
es. - Naming
enum class
es with a trailing_e
, which is the convention for C but not C++. - Uppercase
enum class
members, which is unnecessary because they are scoped.
lint381 can now be used for inline style checking within emacs using flycheck. Download and follow the directions in lint381.el to set it up.
lint381 can also be used for inline style checking within vim using Syntastic. Download and follow the directions in lint381.vim to set it up.
lint381
is licensed under GPLv3.