|
| 1 | +# Static Analysis of TruffleRuby |
| 2 | + |
| 3 | +We apply static analysis to the production code that we maintain - |
| 4 | +`lib/truffle`, `lib/cext`, `src/annotations`, `src/launcher`, `src/main`, |
| 5 | +`src/services` (some parts of static analysis are also applied to other files, |
| 6 | +but these are the key ones). |
| 7 | + |
| 8 | +## C |
| 9 | + |
| 10 | +The [Clang Static Analyzer](https://clang-analyzer.llvm.org) finds bugs in C |
| 11 | +code. We occasionally run this tool locally but only take its output as a |
| 12 | +suggestion. We use a default configuration. |
| 13 | + |
| 14 | +``` |
| 15 | +$ scan-build --use-analyzer `which clang` -analyze-headers clang -c --std=c99 -Ilib/cext/include src/main/c/cext/ruby.c src/main/c/truffleposix/truffleposix.c |
| 16 | +$ scan-view ...as instructed by scan-build... |
| 17 | +``` |
| 18 | + |
| 19 | +## Java |
| 20 | + |
| 21 | +### DSL usage |
| 22 | + |
| 23 | +We have a tool to check that some use of our internal annotations and the |
| 24 | +Truffle DSL are correct. Passing this is enforced in our CI gate. |
| 25 | + |
| 26 | +``` |
| 27 | +$ jt check_dsl_usage |
| 28 | +``` |
| 29 | + |
| 30 | +### CheckStyle |
| 31 | + |
| 32 | +[CheckStyle](http://checkstyle.sourceforge.net) enforces a Java style guide. |
| 33 | +Passing CheckStyle is enforced in our CI gate. |
| 34 | + |
| 35 | +``` |
| 36 | +$ mx checkstyle |
| 37 | +``` |
| 38 | + |
| 39 | +### FindBugs |
| 40 | + |
| 41 | +[FindBugs](http://findbugs.sourceforge.net) looks for potential Java |
| 42 | +programming errors. We run it with the default Graal project configuration. |
| 43 | +Passing FindBugs is enforced in our CI gate. |
| 44 | + |
| 45 | +``` |
| 46 | +$ mx findbugs |
| 47 | +``` |
| 48 | + |
| 49 | +## Ruby |
| 50 | + |
| 51 | +### Rubocop |
| 52 | + |
| 53 | +[Rubocop](https://github.com/rubocop-hq/rubocop) enforces a Ruby style guide. |
| 54 | +It's configured in `.rubocop.yml`, and can be run locally as `jt rubocop`. |
| 55 | +Passing Rubocop is enforced in our CI gate. |
| 56 | + |
| 57 | +``` |
| 58 | +$ jt rubocop |
| 59 | +``` |
| 60 | + |
| 61 | +### Fasterer |
| 62 | + |
| 63 | +[Fasterer](https://github.com/DamirSvrtan/fasterer) looks for potential |
| 64 | +performance improvements. We occasionally run this tool locally but only take |
| 65 | +its output as a suggestion. We use a default configuration. |
| 66 | + |
| 67 | +``` |
| 68 | +$ gem install fasterer |
| 69 | +$ fasterer lib/truffle lib/cext src/main |
| 70 | +``` |
| 71 | + |
| 72 | +### Reek |
| 73 | + |
| 74 | +[Reek](https://github.com/troessner/reek) looks for patterns of Ruby code |
| 75 | +which could be improved - generally around making it simpler and more clear. |
| 76 | +We occasionally run this tool locally but only take its output as a |
| 77 | +suggestion. We disable a lot of the defaults in `.reek.yml`, either because |
| 78 | +we're implementing a set API, because we're doing something low-level or |
| 79 | +outside normal Ruby semantics, or for performance reasons. |
| 80 | + |
| 81 | +``` |
| 82 | +$ gem install reek |
| 83 | +$ reek lib/truffle lib/cext src/main |
| 84 | +``` |
| 85 | + |
| 86 | +### Flog |
| 87 | + |
| 88 | +[Flog](http://ruby.sadi.st/Flog.html) lists methods by complexity. You can |
| 89 | +check that your methods do not appear near the top of this list. We |
| 90 | +occasionally run this tool locally but only take its output as a suggestion. |
| 91 | + |
| 92 | +``` |
| 93 | +$ gem install flog |
| 94 | +$ flog lib/truffle lib/cext src/main |
| 95 | +``` |
| 96 | + |
| 97 | +### Flay |
| 98 | + |
| 99 | +[Flay](http://ruby.sadi.st/Flay.html) finds similar or identical code, which |
| 100 | +could potentially be factored out. We occasionally run this tool locally but |
| 101 | +only take its output as a suggestion. |
| 102 | + |
| 103 | +``` |
| 104 | +$ gem install flay |
| 105 | +$ flay lib/truffle lib/cext src/main |
| 106 | +``` |
| 107 | + |
| 108 | +### Tools we don't use |
| 109 | + |
| 110 | +* [Brakeman](https://github.com/presidentbeef/brakeman) appears to only be |
| 111 | + applicable to Rails applications. |
0 commit comments