• Stars
    star
    305
  • Rank 136,879 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 10 months ago

Reviews

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

Repository Details

code complexity metrics visualization and exploration tool for ruby and javascript

Logo

Attractor

A code complexity metrics visualization and exploration tool for Ruby and JavaScript


Ruby Tests Action Status Forks Stargazers Issues MIT License Twitter follow

All Contributors

Become a Patron!

attractor_v0 6 1

Table of Contents

Introduction

Many authors (Michael Feathers, Sandi Metz) have shown that an evaluation of churn vs complexity of files in software projects provide a valuable metric towards code quality. This is another take on the matter, for ruby code, using the churn and flog projects.

Here's an article on medium explaining the approach in greater detail.

Installation

Attractor's installation is standard for a Ruby gem:

gem install attractor

You'll also want to install some plugins to go along with the main gem:

gem install attractor-ruby # https://github.com/julianrubisch/attractor-ruby
gem install attractor-javascript # https://github.com/julianrubisch/attractor-javascript

You will most likely want to install Attractor using Bundler:

gem 'attractor'
gem 'attractor-ruby'
gem 'attractor-javascript'

And then execute:

bundle

Usage

To create a HTML report in attractor_output/index.html:

attractor report

If you'd like to specify a directory, use the file prefix option:

attractor report --file_prefix app/models

Or shorter:

attractor report -p app/models

Check JavaScript:

attractor report -p app/javascript -t js

Watch for file changes:

attractor report -p app/models --watch

Serve at http://localhost:7890:

attractor serve -p app/models

Enable rack-livereload:

attractor serve -p app/models --watch

Make sure you prefix these commands with bundle exec if you are using Bundler.

Live Reloading

If you have guard-livereload (or a similar service) running on your project, you can leverage the hot reloading functionality by specifying --watch|-w. Attractor will then live-reload the browser window when a file watched by guard-livereload changes.

CI Usage

To use this CLI in a CI environment, use the --ci option, which will suppress automatic opening of a browser window.

Github Action

There is a dedicated Github Action that will compile Attractor's output.

You can quickly integrate it into your action's workflow by grabbing it on the Marketplace.

Gitlab Example

The simplest use case is to store the attractor_output directory as an artifact.

attractor:
  stage: your-stage-label
  image: ruby:latest
  script:
    - gem install attractor
    - attractor report --ci
  artifacts:
    when: on_success
    paths:
      - attractor_output

CLI Commands and Options

Initialize the local cache:

attractor init
  --file_prefix|-p app/models
  --type|-t rb|js
  --start_ago|-s  (e.g. 5y, 3m, 7w)
  --minimum_churn|-c (minimum times a file must have changed to be processed)
  --ignore|-i 'spec/*_spec.rb,db/schema.rb,tmp'

Print a simple output to console:

attractor calc
  --file_prefix|-p app/models
  --type|-t rb|js
  --watch|-w
  --start_ago|-s  (e.g. 5y, 3m, 7w)
  --minimum_churn|-c (minimum times a file must have changed to be processed)
  --ignore|-i 'spec/*_spec.rb,db/schema.rb,tmp'

Generate a full report

attractor report
  --file_prefix|-p app/models
  --type|-t rb|js
  --watch|-w
  --no-open-browser|--ci
  --start_ago|-s  (e.g. 5y, 3m, 7w)
  --minimum_churn|-c (minimum times a file must have changed to be processed)
  --ignore|-i 'spec/*_spec.rb,db/schema.rb,tmp'

Serve the output on http://localhost:7890

attractor serve
  --file_prefix|-p app/models
  --watch|-w
  --no-open-browser|--ci
  --start_ago|-s  (e.g. 5y, 3m, 7w)
  --minimum_churn|-c (minimum times a file must have changed to be processed)
  --ignore|-i 'spec/*_spec.rb,db/schema.rb,tmp'

Clear the local cache:

attractor clean

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To run all tests, run bin/test. You can run the specs by themselves with bundle exec rspec, and the cucumber features with bundle exec cucumber.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub.

Logo Attribution

Black Hole by Eynav Raphael from the Noun Project

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Julian Rubisch

πŸ’» πŸ“–

Olivier

🚧

Andrew Mason

πŸ’» πŸ‘€ πŸ“–

Ernesto Tagwerker

πŸ’»

Manuel Tancoigne

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

better-stimulus

An opinionated collection of StimulusJS best practices
SCSS
250
star
2

solder

Simplistic UI State Management for Rails Apps using Hotwire and Caching
Ruby
73
star
3

cubism

Lightweight Resource-Based Presence Solution with CableReady
Ruby
55
star
4

maxy-gen

A commandline tool to generate max patches in an emmet-like fashion
Ruby
29
star
5

attractor-rails

attractor (code complexity metrics visualization and exploration tool for ruby and javascript) running in a rails engine
Ruby
20
star
6

express-asset-file-cache-middleware

An express.js middleware to locally cache assets (images, videos, audio, etc.) for faster access and proxying, for use in e.g. Electron apps
JavaScript
13
star
7

contentful-nextjs-now-boilerplate

A boilerplate for a contentful setup with next.js and now.sh
JavaScript
10
star
8

stimulus_reflex_profiler

A Rails engine with profiling options for StimulusReflex
Ruby
7
star
9

pronto-standardrb

pronto runner for standardrb
Ruby
7
star
10

chatter-ios

Twitter Clone with Stimulus Reflex gone Hybrid Native App with Turbolinks-iOS
Swift
7
star
11

bridgetown-media-transformation

Ruby
6
star
12

futurism_nice_partials

Ruby
5
star
13

attractor-action

A Github action to run an Attractor report on your project
Shell
4
star
14

bridgetown-automation-lazyload

An automation for adding vanilla-lazyload to a project
Ruby
4
star
15

bridgetown-automation-swiperjs

Ruby
4
star
16

trix-tables-turbo-frames

A demo on how to implement a simple trix table editor using turbo frames
Ruby
4
star
17

stimulus_reflex_form_patterns

Two patterns for form submissions via StimulusReflex/CableReady
Ruby
4
star
18

attractor-ruby

code complexity metrics visualization and exploration tool for ruby
Ruby
2
star
19

cable_ready_callbacks

Supercharge your model with CableReady functionality
Ruby
2
star
20

flycheck-standardrb

Flycheck checker for standardrb
Emacs Lisp
2
star
21

cable_ready_browser_extension

JavaScript
2
star
22

bullet_train-billing-paddle

Ruby
2
star
23

pronto.el

an Emacs compilation mode for pronto
Emacs Lisp
2
star
24

toy_train

Simple Ruby on Rails Gamification Toolkit
Ruby
1
star
25

sr-template-reflex

Ruby
1
star
26

sr-wizard-reflex

Ruby
1
star
27

sr-filterable-reflex

Ruby
1
star
28

toy_train-site

JavaScript
1
star
29

stimulus_reflex_importmaps

Ruby
1
star
30

bridgetown-avatar

Simple port of jekyll-avatar
Ruby
1
star
31

attractor-javascript

code complexity metrics visualization and exploration tool for javascript
Ruby
1
star
32

sr-dynamic-form-reflex

Ruby
1
star