Programmatically Run Lint
While most people prefer to run SmallLint (Smalltalk Code Critics) from within OmniBrowser, the question arises from time to time on how to do the same from within a workspace script:
- Select one or more rules to run from the class hierarchy below
RBLintRule. For example, the following expression would instantiate a single rule that searches for questionable message sends:
The following expression could be used to search for both classes that implement #= but not #hash and methods that do float equality comparisons:
rule := RBCompositeLintRule rules: (Array
with: RBDefinesEqualNotHashRule new
with: RBFloatEqualityComparisonRule new)
- Next select the scope to run the rules in. In the most simple case this is the complete image:
You can however restrict the scope further, for example to the collection hierarchy:
If you have the OmniBrowser refactoring tools installed you can easily browse a restricted environment by evaluating:
- Finally you perform the actual search by evaluating the following expression:
Note that this might take a while depending on the size of the environment and the number of rules you run.
- If you have the OmniBrowser refactoring tools installed you can have a look at the result by evaluating the following expression:
If you have an image without OmniBrowser loaded open an Inspector on the result to see the matching code. If you are running a transformation rule, use the following script to perform the change in your system: