flint bugfix

Summary:
The check to see if a class had protected inheritance stops
when a '{' is seen. It is therefore possible for multiple classes to
spot the same protected error. Eg ##class foo; class bar : proected foo##

See D1186949

Test Plan:
Run Test.d. The output was rather confusing, but if the
change is disabled then the new test case causes Test.d to fail.

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1193069
First implementation based on the results of a grep for structs and classes + manual entry of <algorithm> methods

Summary:
This first crude implementation builds an associative arrays of 'known' std::xxx types to their C++11 headers.
At the moment, this only supports class XXX and struct YYY but and <algorithm> functions input manually.
There are mistakes/inaccuracies due to the coarseness of the grep, see comments.
Comments may be too verbose ...

Test Plan: Created a unit test, looks good so far.

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1191803
Disable linter rule for include which is too agressive

Summary: People have complained about this new rule, reverting it

Test Plan: none

Reviewed By: ldemailly@fb.com

FB internal diff: D1195413
Flint improvements

Summary:
This diff has two components.

(1) Flint would crash on files which contained invalid UTF-8 characters
inside of comments and strings. To fix this, readFile (which performs
implicit UTF-8 validation) was replaced with read. This will not cause
problems with comment or string-literal tokenization, since those
functions munch their input until finding the correct terminating
character.

(2) Flint's top-level error handinling looks like a crash, since
enforcement errors' toString method returns a stack trace. The string
has been changed to something more obvious to the user.

Test Plan:
Running ##_bin/linters/flint/flint hphp/runtime/ext_zend_compat/php-src/main/build-defs.h##
no longer crashes. The file contains a special character (in the
author's name) in the comments.

Running ##_bin/linters/flint/flint common/i18n/analyzers/StopwordAnalyzer.cpp##
no longer crashes. The file contains a special character inside of a
string.

Running ##_bin/linters/flint/flint external/liblinear-weights-openmp/linear.cpp##
now produces a simple error message instead of a stack trace. The file
containts ##pragma omp for##, which trips an enforcement. A rootfix has
been tasked in t3834286.

Running ##fbconfig linters/flint && fbmake runtests_opt## passes all 36
tests.

Reviewed By: delong.j@fb.com

FB internal diff: D1202592
Add lint rules for incorrect random usage

Summary:
Add lint rules for incorrect/discouraged random usage,
including using random_device or RandomInt32/64 to generate random numbers

Test Plan: add unit test in Test.d and passed it

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1203181

Blame Revision: v1
Add CONTRIBUTING.md to flint

Summary: Instructions for external contributors.

Test Plan: stared at it

Reviewed By: jpearce@fb.com

FB internal diff: D1208006
Lint rule that detects EXPR == EXPR and EXPR != EXPR

Summary: I implement a lint rule that detects EXPR == EXPR and EXPR != EXPR. The current code includes my attempt to implement EXPR {<, <=, >, >=} EXPR. However, since I haven't implemented a full-fledged parser, the code will fail at expressions similar to "vector<vector<int> >." It will be great if anyone can give me some comments on this (e.g., shall we focus on == and != for now?).

Test Plan:
1. fbconfig linters/flint.

2. fbmake --fast dbg.

3. _bin/linters/flint/flint <target_file.cpp>.

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1183425
Modify flint to tokenize #pragma and #error preprocessor directives.

Summary: Flint currently attempts to lint #pragma and #error preprocessor directives, which can contain constructs that would be invalid in other contexts, but should be ignored in preprocessor directives. This change tokenizes these directives separately so that they don't inadvertently trigger other lint rules.

Test Plan: Verify all unit tests for flint pass.

Reviewed By: njormrod@fb.com

FB internal diff: D1211135
Unique-ify filename

Summary:
flint occasionally fails its test in contbuild, though never
reproduces these failures locally. The code which breaks is performing
reads and writes to a temporary file. My guess is that parallel builds
are causing a race condition on the tmpfile. This diff creates
unique(-ish) filenames, which should reduce the errors to practically
zero.

The original test code has been disabled, since the D tests now deal
with it. This was also a point of race contention, since the new and the
old tests use the same filename.

Test Plan:
fbconfig -r linters && fbmake opt && fbmake runtests_opt
before and after the change. Before, /tmp/cxx_replace_testing was being
created. After the random-number portion of the diff was added, both
/tmp/cxx_replace_testing and /tmp/cxx_replace_testing[random-numbers]
were being generated. After disabling the original test, only the
randomed file is being generated, and that file is no longer a permanent
biproduct of the test after the file.remove line was added.

Reviewed By: robbert@fb.com

FB internal diff: D1217516
Add #warning to flint

Summary:
D1221384 brought #warning to my attention, which I had
neglected to consider in D1211135. Even though #warning is a
compiler-specific extension, fbgs shows that we are using in at
facebook. This diff adds #warning to the list of special preprocessor
directives in the tokenizer.

Test Plan: fbconfig -r linters/flint && fbmake opt && fbmake runtests_opt

Reviewed By: robbert@fb.com

FB internal diff: D1221423
Fix tokenizer linenumbers

Summary:
The tokenizer was not doing line numbers properly. These issues
have been fixed, and verification code has been added to the
tokenization method.

I also changed the assert(0) to be a throw, which lets flint continue
processing other files if one contains invalid input.

Test Plan:
fbconfig linters/flint && fbmake runtests_opt
success

find . | egrep "\.(h|cpp)$" | xargs _bin/linters/flint/flint
^ no longer crashes halfway through on illegal characters

Reviewed By: robbert@fb.com

FB internal diff: D1232976
Implementing command line opt-in, looking up include with same prefix and aggregation of warning in a single message

Summary:
Implemented the following

command line argument to easily opt-in / opt-out on a per project basis
also tokenize the corresponding XXX.h if it exists and use the includes in there too
at most 1 warning per file, aggregate all missing includes in a single warning to reduce occurrences and duplicate messages

Test Plan:
Additionally added a test_files directory with a single test file to test the chaining of includes (point 2)
Messages should now be much less intrusive and opt-in only.

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D1221254
Fixing locks

Summary:
Fixing mutex locks for c++
Error text improvement

https://github.com/facebook/flint/pull/11

Test Plan: fbconfig -r linters/flint && fbmake runtests_opt

Reviewed By: njormrod@fb.com
Added 'nolint' capability to checkAssiciatedHeader

Summary:
Headers which are supposed to be included before the associated
header may now do so, by having a ##nolint## comment after the include
line.

Test Plan: fbconfig linters/flint && fbmake runtests_opt

Reviewed By: andrewjcg@fb.com

FB internal diff: D1295026
Eliminate inaccessible URL, allow compilation without warnings

Summary: Flint had a couple of fburl.com links that are not accessible. Also adjusted the code to avoid the warning "unreachable code".

Test Plan: tested output against the baseline on a bunch of C++ files.

Reviewed By: njormrod@fb.com

FB internal diff: D1311709