So, after installing cpplint, here's the summary output I get from the summary source tree:
> time cpplint.py --counting=detailed --root=src --extension=hpp $(find src/stan -name '*.hpp') 2>&1 | grep -e "Category" -e "Total error"
Category 'runtime/indentation_namespace' errors found: 1503
Category 'readability/casting' errors found: 63
Category 'whitespace/semicolon' errors found: 60
Category 'runtime/references' errors found: 856
Category 'whitespace/operators' errors found: 50
Category 'whitespace/comments' errors found: 514
Category 'build/include_what_you_use' errors found: 130
Category 'whitespace/line_length' errors found: 1130
Category 'legal/copyright' errors found: 800
Category 'build/namespaces' errors found: 4
Category 'build/include' errors found: 36
Category 'whitespace/empty_loop_body' errors found: 1
Category 'whitespace/end_of_line' errors found: 7290
Category 'runtime/int' errors found: 21
Category 'whitespace/comma' errors found: 4404
Category 'readability/namespace' errors found: 1588
Category 'whitespace/indent' errors found: 443
Category 'runtime/explicit' errors found: 205
Category 'whitespace/newline' errors found: 1532
Category 'readability/braces' errors found: 225
Category 'readability/todo' errors found: 6
Category 'build/include_order' errors found: 1100
Category 'whitespace/forcolon' errors found: 3
Category 'build/storage_class' errors found: 3
Category 'whitespace/blank_line' errors found: 841
Category 'whitespace/parens' errors found: 386
Category 'whitespace/braces' errors found: 116
Total errors found: 23310
real 0m37.399s
user 0m35.911s
sys 0m1.177s
It takes under a minute to run, so I think it's well worth it. I think we should filter out these error messages:
- runtime/indentation_namespace: wants there to be no indentation with namespaces. Since some of us use emacs to indent, this isn't the default.
- readability/namespace: wants "// namespace <name>" to end each namespace. We haven't been following this.
- legal/copyright: wants a copyright notice on each file
- whitespace/line_length: is set to 80 characters. Should we make it longer?
- whitespace/indent: wants 'public:' in class definitions to be indented by 1 space. There is a google style emacs file that could help with this sort of indentation. I'm ok without it indented.
Some key problems this will find:
- whitespace/newline: WINDOWS NEWLINES!
- whitespace/parens: "if(", "foo (", "for("
This I can go either way, but can suppress for now:
- runtime/reference:
src/stan/agrad/autodiff.hpp:198: Is this a non-const reference? If so, make const or use a pointer: Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& H [runtime/references] [2]
the function signature looks like:
template <typename F>
void
hessian(const F& f,
const Eigen::Matrix<double,Eigen::Dynamic,1>& x,
double& fx,
Eigen::Matrix<double,Eigen::Dynamic,1>& grad,
Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& H) {