linter: add cpplint
This PR adds cpplint to linter all the c/c++ files. It can be run from
npm test or directly from npm run lint. There are still a few linter errors which I have included below:
✗ src/module.cc
3: Include the directory when naming .h files
16: Using C-style cast. Use static_cast<int>(...) instead
266: Using C-style cast. Use static_cast<int>(...) instead
✗ src/node_report.cc
2: Include the directory when naming .h files
15: Include the directory when naming .h files
16: Include the directory when naming .h files
365: Using C-style cast. Use reinterpret_cast<char ***>(...) instead
589: Using C-style cast. Use reinterpret_cast<LPBYTE *>(...) instead
1038: Storage class (static, extern, typedef, etc) should be first.
1096: Using C-style cast. Use reinterpret_cast<FILE*>(...) instead
1120: Using C-style cast. Use reinterpret_cast<char*>(...) instead
1129: Using C-style cast. Use reinterpret_cast<char*>(...) instead
1138: Using C-style cast. Use reinterpret_cast<ld_info*>(...) instead
1164: Using C-style cast. Use reinterpret_cast<HMODULE*>(...) instead
364: Add #include <string> for string
✗ src/node_report.h
5: Include the directory when naming .h files
7: Found C system header after other header. Should be: node_report.h, c system, c++ system, other.
8: Found C system header after other header. Should be: node_report.h, c system, c++ system, other.
10: Found C system header after other header. Should be: node_report.h, c system, c++ system, other.
so I have added the cpplint.py to run the python suite that node.js use: https://github.com/nodejs/node/blob/master/tools/cpplint.py
I wonder if there is any reason not to use clang-format in this project? Linting is good, but fixing issues with one commands is better in my opinion
Having had a local discussion about this I think the concern was that clang-format wouldn't be available when running citgm builds. (I'd be happy with something that a developer just ran before creating a PR personally but I can see why other people want to integrate it into builds.)
I think the main concern with this pull request at the moment is cpplint.py is 6153 lines long as it's copied from Node.js it's likely to get out of sync.
I think ideally we want an npm module we can just have as a devDependency, one that can automatically fix stuff would be great. Not sure if there are any good ones though.
My main objection to clang-format is that it isn't part of the standard Node.js addon development environment on platforms such as Windows nor is it (I believe) an installable npm module.
@gdams Where is this version of cpplint.py from? It doesn't match the one currently in https://github.com/nodejs/node/blob/master/tools/cpplint.py (e.g. missing https://github.com/nodejs/node/commit/fadf66a02bcbb7cafa480756eeb8df91e1aaaae3).
I've had trouble getting clang-format installed when we used it once before for formatting checking. IIRC, it also had continuously changing formats, so you needed the exact correct version installed. The pain outweighed the gain.
This PR LGTM, except that the copyright header comments don't refer to anyone who can hold copyright... does the linter require them?