├── test
├── test_helper.rb
└── lib
│ └── guard
│ └── rubycritic
│ └── version_test.rb
├── lib
├── guard
│ ├── rubycritic
│ │ ├── version.rb
│ │ └── templates
│ │ │ └── Guardfile
│ └── rubycritic.rb
└── rubycritic
│ └── generators
│ ├── html
│ └── current_code_file.rb
│ └── html_guard_report.rb
├── Gemfile
├── Rakefile
├── .gitignore
├── SPEC.md
├── LICENSE.txt
├── guard-rubycritic.gemspec
├── README.md
└── CONTRIBUTING.md
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | require "minitest/autorun"
2 | require "minitest/pride"
3 | require "mocha/setup"
4 |
--------------------------------------------------------------------------------
/lib/guard/rubycritic/version.rb:
--------------------------------------------------------------------------------
1 | module Guard
2 | module RubyCriticVersion
3 | VERSION = "2.9.3"
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source "https://rubygems.org"
2 |
3 | # Specify your gem's dependencies in guard-rubycritic.gemspec
4 | gemspec
5 |
--------------------------------------------------------------------------------
/lib/guard/rubycritic/templates/Guardfile:
--------------------------------------------------------------------------------
1 | guard "rubycritic" do
2 | watch(%r{^app/(.+)\.rb$})
3 | watch(%r{^lib/(.+)\.rb$})
4 | end
5 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require "bundler/gem_tasks"
2 | require "rake/testtask"
3 |
4 | Rake::TestTask.new do |t|
5 | t.libs.push "lib"
6 | t.libs.push "test"
7 | t.pattern = "test/**/*_test.rb"
8 | end
9 |
10 | task :default => :test
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.gem
2 | *.rbc
3 | .bundle
4 | .config
5 | .yardoc
6 | Gemfile.lock
7 | InstalledFiles
8 | _yardoc
9 | coverage
10 | doc/
11 | lib/bundler/man
12 | pkg
13 | rdoc
14 | spec/reports
15 | test/tmp
16 | test/version_tmp
17 | tmp
18 |
--------------------------------------------------------------------------------
/test/lib/guard/rubycritic/version_test.rb:
--------------------------------------------------------------------------------
1 | require "test_helper"
2 | require "guard/rubycritic/version"
3 |
4 | describe Guard::RubyCriticVersion do
5 | it "is defined" do
6 | Guard::RubyCriticVersion::VERSION.wont_be_nil
7 | end
8 | end
9 |
--------------------------------------------------------------------------------
/lib/rubycritic/generators/html/current_code_file.rb:
--------------------------------------------------------------------------------
1 | require "rubycritic/generators/html/code_file"
2 |
3 | module RubyCritic
4 | module Generator
5 | module Html
6 |
7 | class CurrentCodeFile < CodeFile
8 | def file_directory
9 | @file_directory ||= root_directory
10 | end
11 |
12 | def file_name
13 | "current_file.html"
14 | end
15 | end
16 |
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/rubycritic/generators/html_guard_report.rb:
--------------------------------------------------------------------------------
1 | require "rubycritic/generators/html_report"
2 | require "rubycritic/generators/html/current_code_file"
3 |
4 | module RubyCritic
5 | module Generator
6 |
7 | class HtmlGuardReport < HtmlReport
8 | def generate_report
9 | create_directories_and_files
10 | copy_assets_to_report_directory
11 | report_location
12 | end
13 |
14 | private
15 |
16 | def generators
17 | file_generator
18 | end
19 |
20 | def file_generator
21 | @file_generator ||= Html::CurrentCodeFile.new(@analysed_modules.first)
22 | end
23 |
24 | def report_location
25 | file_generator.file_href
26 | end
27 | end
28 |
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/SPEC.md:
--------------------------------------------------------------------------------
1 | Guard::RubyCritic
2 | =================
3 |
4 | Guard::RubyCritic is a tool that detects and reports smells in Ruby code in real-time.
5 |
6 | Inspired by [RuboCop][1], [Rails Best Practices][2] and [Code Climate][3], Ruby Critic aims to better help you refactor your code. By making use of Ruby's rich ecosystem of code metrics tools, Ruby Critic generates high-quality visualizations and insightful code quality reports.
7 |
8 | [1]: https://github.com/bbatsov/rubocop/
9 | [2]: https://github.com/railsbp/rails_best_practices
10 | [3]: https://codeclimate.com/
11 |
12 | Installation
13 | ------------
14 |
15 | Add this line to your application's Gemfile:
16 |
17 | ```ruby
18 | gem "guard-rubycritic"
19 | ```
20 |
21 | And then execute:
22 |
23 | ```bash
24 | $ bundle
25 | ```
26 |
27 | Next, generate a default `Guardfile` in your root directory:
28 |
29 | ```bash
30 | $ guard init rubycritic
31 | ```
32 |
33 | Usage
34 | -----
35 |
36 | Change your `Guardfile` to your heart's content and simply run `guard` to get instant feedback on your code quality:
37 |
38 | ```bash
39 | $ guard
40 | ```
41 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013 Guilherme Simoes
2 |
3 | MIT License
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/guard-rubycritic.gemspec:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | lib = File.expand_path("../lib", __FILE__)
3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4 | require "guard/rubycritic/version"
5 |
6 | Gem::Specification.new do |spec|
7 | spec.name = "guard-rubycritic"
8 | spec.version = Guard::RubyCriticVersion::VERSION
9 | spec.authors = ["Guilherme Simoes"]
10 | spec.email = ["guilherme.rdems@gmail.com"]
11 | spec.description = <<-EOF
12 | Ruby Critic is a tool that listens to modifications in Ruby classes, modules and methods and
13 | reports any new code smells it finds.
14 | EOF
15 | spec.summary = "Listens to modifications and detects smells in Ruby files"
16 | spec.homepage = "https://github.com/whitesmith/guard-rubycritic"
17 | spec.license = "MIT"
18 |
19 | spec.files = Dir.glob("{lib}/**/*") + %w[LICENSE.txt README.md]
20 | spec.test_files = `git ls-files -- test/*`.split("\n")
21 | spec.require_path = "lib"
22 |
23 | spec.add_runtime_dependency "guard", "~> 2.6"
24 | spec.add_runtime_dependency "rubycritic", ">= 2.9.3"
25 |
26 | spec.add_development_dependency "bundler", "~> 1.3"
27 | spec.add_development_dependency "rake"
28 | spec.add_development_dependency "minitest", "~> 5.3"
29 | spec.add_development_dependency "mocha", "~> 1.0"
30 | end
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Guard::RubyCritic
2 | =================
3 |
4 | [](http://badge.fury.io/rb/guard-rubycritic)
5 | [](https://codeclimate.com/github/whitesmith/guard-rubycritic)
6 |
7 |
8 |
9 | Guard::RubyCritic is a tool that uses [RubyCritic](https://github.com/whitesmith/rubycritic) to detect and report smells in Ruby code in real-time.
10 |
11 | Installation
12 | ------------
13 |
14 | Add this line to your application's Gemfile:
15 |
16 | ```ruby
17 | gem "guard-rubycritic"
18 | ```
19 |
20 | And then execute:
21 |
22 | ```bash
23 | $ bundle
24 | ```
25 |
26 | Next, generate a default `Guardfile` in your root directory:
27 |
28 | ```bash
29 | $ guard init rubycritic
30 | ```
31 |
32 | Usage
33 | -----
34 |
35 | Change your `Guardfile` to your heart's content and start it with the following command:
36 |
37 | ```bash
38 | $ guard
39 | ```
40 |
41 | Each time you save a file, that file will be analysed and its report will be available at `YOUR_PROJECT_ROOT/tmp/rubycritic/current_file.html`.
42 |
43 | Improving Guard::RubyCritic
44 | ---------------------------
45 |
46 | See Guard::RubyCritic's [contributing guidelines](CONTRIBUTING.md) about how to proceed.
47 |
--------------------------------------------------------------------------------
/lib/guard/rubycritic.rb:
--------------------------------------------------------------------------------
1 | require "guard"
2 | require "guard/plugin"
3 | require "rubycritic"
4 | require "rubycritic/generators/html_guard_report"
5 |
6 | module Guard
7 |
8 | class RubyCritic < Plugin
9 | # Called once when Guard starts. Please override initialize method to init stuff.
10 | #
11 | # @raise [:task_has_failed] when start has failed
12 | # @return [Object] the task result
13 | #
14 | def start
15 | @rubycritic = ::RubyCritic::CommandFactory.create
16 | @rubycritic.extend(AdditionalMethodsForGuard)
17 | UI.info "Guard::RubyCritic is critiquing"
18 | end
19 |
20 | # Default behaviour on file(s) changes that the Guard plugin watches.
21 | # @param [Array] paths the changes files or paths
22 | # @raise [:task_has_failed] when run_on_change has failed
23 | # @return [Object] the task result
24 | #
25 | def run_on_changes(paths)
26 | report_location = report(critique(paths))
27 | UI.info "New critique at #{report_location}"
28 | end
29 |
30 | def critique(paths)
31 | @rubycritic.paths = paths
32 | @rubycritic.critique
33 | end
34 |
35 | def report(analysed_modules)
36 | ::RubyCritic::Generator::HtmlGuardReport.new(analysed_modules).generate_report
37 | end
38 | end
39 |
40 | module AdditionalMethodsForGuard
41 | # This is necessary to inject new paths into the RubyCritic Command class.
42 | # Otherwise we would have to create a new class instance everytime a user changed a file.
43 | attr_writer :paths
44 | end
45 |
46 | end
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ============
3 |
4 | Guard::RubyCritic is open source and contributions from the community are encouraged! No contribution is too small. Please consider:
5 |
6 | * [Writing some Code](#writing-some-code)
7 | * [Improving the Documentation](#improving-the-documentation)
8 | * [Reporting a Bug](#reporting-a-bug)
9 |
10 | Writing some Code
11 | -----------------
12 |
13 | If you want to squash a bug or add a new feature, please:
14 |
15 | 1. Fork the project.
16 |
17 | 2. Create a feature branch (`git checkout -b my-new-feature`).
18 |
19 | 3. Make your changes. Include tests for your changes, otherwise I may accidentally break them in the future.
20 |
21 | 4. Run the tests with the `rake` command. Make sure that they are still passing.
22 |
23 | 5. Stage partial-file changesets (`git -p`).
24 |
25 | 6. Commit your changes (`git commit`).
26 | Make exactly as many commits as you need.
27 | Each commit should do one thing and one thing only. For example, all whitespace fixes should be relegated to a single commit.
28 |
29 | 7. Write descriptive commit messages, in accordance with [these guidelines][1].
30 |
31 | 8. [Hide the sausage making][3]. Squash, split and reorder commits if necessary (`git rebase -i`).
32 | For a more in-depth look at interactive rebasing, be sure to check [how to rewrite history][4].
33 |
34 | 9. Push the branch to GitHub (`git push origin my-new-feature`).
35 |
36 | 10. Create a new [Pull Request][5] and send it to be merged with the master branch.
37 |
38 | Improving the Documentation
39 | ---------------------------
40 |
41 | You are welcome to clarify how something works or simply fix a typo. Please include `[ci skip]` on a new line in each of your commit messages. This will signal [Travis][2] that running the test suite is not necessary for these changes.
42 |
43 | Reporting a Bug
44 | ---------------
45 |
46 | If you are experiencing unexpected behavior and, after having read RubyCritic's documentation, are convinced this behavior is a bug, please:
47 |
48 | 1. Search the [issues tracker][6] to see if it was already reported / fixed.
49 |
50 | 2. Include the Ruby, RubyCritic and Guard:RubyCritic versions in your report. Here's a little table to help you out:
51 |
52 | ```
53 | | | Version |
54 | |-------------------|---------|
55 | | Ruby | 2.1.2 |
56 | | RubyCritic | 1.0.0 |
57 | | Guard::RubyCritic | 1.0.0 |
58 | ```
59 |
60 | The more information you provide, the easier it will be to track down the issue and fix it.
61 |
62 | 3. Create a new issue.
63 |
64 | [1]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
65 | [2]: https://travis-ci.org
66 | [3]: http://sethrobertson.github.io/GitBestPractices/#sausage
67 | [4]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages
68 | [5]: https://help.github.com/articles/creating-a-pull-request
69 | [6]: https://github.com/whitesmith/guard-rubycritic/search?type=Issues
70 |
--------------------------------------------------------------------------------