Skip to content

Commit 9757710

Browse files
committed
Document how to run static analysis tools
1 parent df10d7a commit 9757710

File tree

2 files changed

+160
-0
lines changed

2 files changed

+160
-0
lines changed

.reek.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
detectors:
2+
UncommunicativeVariableName:
3+
enabled: false # we're happy with short variable names
4+
UncommunicativeParameterName:
5+
enabled: false # we're happy with short parameter names
6+
LongParameterList:
7+
enabled: false # we're often meeting an existing Ruby API with fixed parameters
8+
UncommunicativeModuleName:
9+
enabled: false # we're often meeting an existing Ruby API with fixed module names
10+
UncommunicativeMethodName:
11+
enabled: false # we're often meeting an existing Ruby API with fixed method names
12+
BooleanParameter:
13+
enabled: false # we're often meeting an existing Ruby API with boolean parameters
14+
TooManyStatements:
15+
enabled: false # yes we often write longer methods
16+
FeatureEnvy:
17+
enabled: false # we don't want to add new public methods to Ruby API classes to better encapsulate behaviour
18+
UnusedParameters:
19+
enabled: false # primitives mean that the use of parameters can be hidden
20+
NilCheck:
21+
enabled: false # our code is often too low level to factor this away
22+
ManualDispatch:
23+
enabled: false # manual dispatch is often part of Ruby internal semantics
24+
IrresponsibleModule:
25+
enabled: false # we don't comment all modules because we're implementing an existing interface so they do not need a raison d'être
26+
ControlParameter:
27+
enabled: false # we're often meeting an existing Ruby API with control parameters
28+
DataClump:
29+
enabled: false # we're often meeting an existing Ruby API with 'data clumps'
30+
TooManyMethods:
31+
enabled: false # we're often meeting an existing Ruby API with an existing set of methods
32+
TooManyConstants:
33+
enabled: false # we're often meeting an existing Ruby API with an existing set of constants
34+
UtilityFunction:
35+
enabled: false # we're often meeting an existing Ruby API with utility functions
36+
MissingSafeMethod:
37+
enabled: false # we're often meeting an existing Ruby API without safe equivalents, or the safe equivalent is implemented in Java
38+
Attribute:
39+
enabled: false # we're often meeting an existing Ruby API with writable attributes
40+
InstanceVariableAssumption:
41+
enabled: false # we often set instance variables lazily
42+
NestedIterators:
43+
enabled: false # yes we often write nested iterators
44+
TooManyInstanceVariables:
45+
enabled: false # yes we sometimes use a lot of instance variables
46+
RepeatedConditional:
47+
enabled: false # we don't want to add new public methods to Ruby API classes to better encapsulate behaviour
48+
DuplicateMethodCall:
49+
enabled: false # needs investigation - sometimes legitimate due to Ruby semantics, but lots of failures

doc/contributor/static-analysis.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)