File: README.md

package info (click to toggle)
roodi 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 428 kB
  • sloc: ruby: 1,922; makefile: 4
file content (157 lines) | stat: -rw-r--r-- 5,848 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# roodi

[![Build Status](https://travis-ci.org/roodi/roodi.png?branch=master)](https://travis-ci.org/roodi/roodi)
[![Coverage Status](https://coveralls.io/repos/roodi/roodi/badge.png?branch=master)](https://coveralls.io/r/roodi/roodi?branch=master)

## Description

Roodi stands for Ruby Object Oriented Design Inferometer. It parses your Ruby code and warns you about design issues you have based on the checks that it has configured.

## Install

Open your terminal and type this:

`$ gem install roodi`

Alternatively, you can put it in your Gemfile:

`gem "roodi"`

## Synopsis

To check one or more files using the default configuration that comes with Roodi, use:

`$ roodi [-config=file] [pattern ...]`

## Example Usage

Check all ruby files recursively under the current directory:

`$ roodi` or `$ roodi .`

Check all ruby files in a rails app:

`$ roodi "rails_app/**/*.rb"`

Check one controller and one model file in a rails app:

`$ roodi app/controller/sample_controller.rb app/models/sample.rb`

Check one controller and all model files in a rails app:

`$ roodi app/controller/sample_controller.rb "app/models/*.rb"`

Check all ruby files in a rails app with a custom configuration file:

`$ roodi -config=my_roodi_config.yml "rails_app/**/*.rb"`

If you're writing a check, it is useful to see the structure of a file the way that Roodi tokenizes it (via ruby_parser). Use:

`$ roodi-describe [filename]`

## Running it as part of your build

Add the following to your Rakefile:

    require 'roodi_task'
    task :default => [:roodi]

or if you want to supply your own config file...

    require 'roodi_task'
    RoodiTask.new :config => 'config/roodi.yml'
    task :default => [:roodi]

## Editor integration
You can run Roodi in Atom using the [linter-roodi](https://atom.io/packages/linter-roodi) package.

## Custom Configuration

To change the set of checks included, or to change the default values of the checks, you can provide your own config file.  The config file is a YAML file that lists the checks to be included.  Each check can optionally include a hash of options that are passed to the check to configure it.  For example, the default config file looks like this:

    AssignmentInConditionalCheck:
    CaseMissingElseCheck:
    ClassLineCountCheck:
      line_count: 300
    ClassNameCheck:
      pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
    ClassVariableCheck:
    CyclomaticComplexityBlockCheck:
      complexity: 4
    CyclomaticComplexityMethodCheck:
      complexity: 8
    EmptyRescueBodyCheck:
    ForLoopCheck:
    MethodLineCountCheck:
      line_count: 20
    MethodNameCheck:
      pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
    ModuleLineCountCheck:
      line_count: 300
    ModuleNameCheck:
      pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
    ParameterNumberCheck:
      parameter_count: 5

## Supported Checks

* AssignmentInConditionalCheck - Check for an assignment inside a conditional.  It's probably a mistaken equality comparison.
* CaseMissingElseCheck - Check that case statements have an else statement so that all cases are covered.
* ClassLineCountCheck - Check that the number of lines in a class is below the threshold.
* ClassNameCheck - Check that class names match convention.
* CyclomaticComplexityBlockCheck - Check that the cyclomatic complexity of all blocks is below the threshold.
* CyclomaticComplexityMethodCheck - Check that the cyclomatic complexity of all methods is below the threshold.
* EmptyRescueBodyCheck - Check that there are no empty rescue blocks.
* ForLoopCheck - Check that for loops aren't used (Use Enumerable.each instead)
* MethodLineCountCheck - Check that the number of lines in a method is below the threshold.
* MethodNameCheck - Check that method names match convention.
* ModuleLineCountCheck - Check that the number of lines in a module is below the threshold.
* ModuleNameCheck - Check that module names match convention.
* ParameterNumberCheck - Check that the number of parameters on a method is below the threshold.

## Suggested Checks

* BlockVariableShadowCheck - Check that a block variable does not have the same name as a method parameter or local variable.  It may be mistakenly referenced within the block.

## Contributing

### Bug reporting
Please use the GitHub issue tracker.

### Want to submit some code?
Fantastic! Please follow this procedure:
- Fork the repository
- Create a well-named topic branch
- Add specs for any changes you make
- Write meaningful commit messages explaining why this change is needed
- Create a pull request.

### How to publish a new version (maintainers only)
1. Bump the version in version.rb
1. `$ gem build roodi.gemspec`
1. `$ gem push roodi-X.X.X.gem`

## License

(The MIT License)

Copyright (c) 2015 Marty Andrews, Peter Evjan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.