• Stars
    star
    757
  • Rank 59,989 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Static analysis tool for checking Ruby code for Sandi Metz' rules.

SandiMeter

Build Status Gem Version

Static analysis tool for checking your Ruby code for Sandi Metz' four rules.

  • 100 lines per class
  • 5 lines per method
  • 4 params per method call (and don't even try cheating with hash params)
  • 1 instance variable per controller action

CLI mode

gem install sandi_meter

sandi_meter --help
    -d, --details                    CLI mode. Show details (path, line number)
    -g, --graph                      HTML mode. Create folder, log data and output stats to HTML file.
        --json                       Output as JSON
    -l, --log                        Show syntax error and indentation log output
    -o, --output-path PATH           Path for storing generated output files (default: ./sandi_meter/)
    -p, --path PATH                  Path to folder or file to analyze
    -q, --quiet                      Do not open HTML report for graph option in browser.
    -t, --thresholds THRESHOLD       Thresholds for each rule (default: "90,90,90,90" or in config.yml)
    -r, --rules                      Show rules
    -v, --version                    Gem version
    -h, --help                       Help

cd ~/your/ruby/or/rails/project
sandi_meter -d

1. 85% of classes are under 100 lines.
2. 45% of methods are under 5 lines.
3. 99% of method calls accepted are less than 4 parameters.
4. 66% of controllers have one instance variable per action.

Classes with 100+ lines
  Class name                 | Size  | Path
  SandiMeter::Analyzer       | 219   | ./lib/sandi_meter/analyzer.rb:7
  SandiMeter::Calculator     | 172   | ./lib/sandi_meter/calculator.rb:2
  SandiMeter::HtmlGenerator  | 135   | ./lib/sandi_meter/html_generator.rb:5
  Valera                     | 109   | ./spec/test_classes/12.rb:1

Misindented classes
  Class name        | Path
  MyApp::TestClass  | ./spec/test_classes/1.rb:2
  OneLinerClass     | ./spec/test_classes/5.rb:1

Methods with 5+ lines
  Class name                          | Method name                   | Size  | Path
  SandiMeter::Analyzer                | initialize                    | 10    | ./lib/sandi_meter/analyzer.rb:10
  SandiMeter::Analyzer                | analyze                       | 13    | ./lib/sandi_meter/analyzer.rb:22

Misindented methods
  Class name        | Method name  | Path
  MyApp::TestClass  | blah         | ./spec/test_classes/1.rb:3

Method calls with 4+ arguments
  # of arguments  | Path
  5               | ./lib/sandi_meter/html_generator.rb:55
  5               | ./lib/sandi_meter/html_generator.rb:71

Controllers with 1+ instance variables
  Controller name         | Action name  | Instance variables
  AnotherUsersController  | index        | @users, @excess_variable

HTML mode

Try using gem with -g (--graph) option, so it will create a folder with beautiful html output and log file with results of any scan.

SandiMeter HTML mode pie charts SandiMeter HTML mode details

Add ignore files and folders in sandi_meter/.sandi_meter file.

Ruby script mode

require 'sandi_meter/file_scanner'
require 'pp'

scanner = SandiMeter::FileScanner.new
data = scanner.scan(PATH_TO_PROJECT)
pp data
# {:first_rule=>
#   {:small_classes_amount=>916,
#    :total_classes_amount=>937,
#    :misindented_classes_amount=>1},
#  :second_rule=>
#   {:small_methods_amount=>1144,
#    :total_methods_amount=>1833,
#    :misindented_methods_amount=>0},
#  :third_rule=>{:proper_method_calls=>5857, :total_method_calls=>5894},
#  :fourth_rule=>{:proper_controllers_amount=>17, :total_controllers_amount=>94}}

More Repositories

1

guitar_bro

Guitar Bro – browser game that helps you learn notes on guitar
JavaScript
145
star
2

youtube_time_tracker

Chrome Extension that tracks time you spent on Youtube.
JavaScript
99
star
3

prcop

A Github action for linting Pull Requests.
JavaScript
30
star
4

russian_sex

Gender detector for russian names
Ruby
28
star
5

tag-it-autocomplete

Tag select with Tag-it! and Autocomplete
Ruby
25
star
6

focused_youtube

Chrome Extension to be more focused on Youtube.
JavaScript
23
star
7

melkman

Ruby implementation of Melkman's algorithm with GIF animation
Ruby
18
star
8

triads

Triads guitar explorer
JavaScript
8
star
9

img-lint

Lightweight gem that detects heavy images in your project.
Ruby
6
star
10

notenote

A CLI tool to organize daily notes.
Ruby
5
star
11

rad-workout-app

5 min agility workout browser app built with Vue.js
Vue
5
star
12

chat_timer

Tool for time tracking via Skype
Ruby
5
star
13

willpower

A browser extension that allows you to take a breath before visiting unwanted websites.
Vue
5
star
14

page-speed-insights-dashboard

Vue
4
star
15

lobby

Ruby
2
star
16

flappy_block_js

JS implementation of Flappy Block game
JavaScript
2
star
17

Back_player

Ruby
2
star
18

talks

Collection of programming related talks
2
star
19

sql_bro

Ruby
1
star
20

Mongoid-carrierwave-mini_magick-crop

Test application for cropping photos using carrierwave and jCrop
JavaScript
1
star
21

jquery-rails-confirm-count

Gem that extends jquery-rails for it to have confirm-count param
Ruby
1
star
22

Happy-Birthday-page-with-image-slider-and-form

Ruby
1
star
23

web_audio_fft_meets_d3

A bunch of Web Audio API visualisations from Guitar Bro
JavaScript
1
star
24

vscode-settings

My personal settings for Visual Studio Code
1
star