Giter Club home page Giter Club logo

cane's Introduction

Cane

Fails your build if code quality thresholds are not met.

Discipline will set you free.

Cane still technically works, but for new projects you're probably better off using Rubocop and customizing it to your liking. It is far more comprehensive and more widely used.

Usage

gem install cane
cane --abc-glob '{lib,spec}/**/*.rb' --abc-max 15

Your main build task should run this, probably via bundle exec. It will have a non-zero exit code if any quality checks fail. Also, a report:

> cane

Methods exceeded maximum allowed ABC complexity (2):

  lib/cane.rb  Cane#sample    23
  lib/cane.rb  Cane#sample_2  17

Lines violated style requirements (2):

  lib/cane.rb:20   Line length >80
  lib/cane.rb:42   Trailing whitespace

Class definitions require explanatory comments on preceding line (1):
  lib/cane:3  SomeClass

Customize behaviour with a wealth of options:

> cane --help
Usage: cane [options]

Default options are loaded from a .cane file in the current directory.

-r, --require FILE               Load a Ruby file containing user-defined checks
-c, --check CLASS                Use the given user-defined check

    --abc-glob GLOB              Glob to run ABC metrics over (default: {app,lib}/**/*.rb)
    --abc-max VALUE              Ignore methods under this complexity (default: 15)
    --abc-exclude METHOD         Exclude method from analysis (eg. Foo::Bar#method)
    --no-abc                     Disable ABC checking

    --style-glob GLOB            Glob to run style checks over (default: {app,lib,spec}/**/*.rb)
    --style-measure VALUE        Max line length (default: 80)
    --style-exclude GLOB         Exclude file or glob from style checking
    --no-style                   Disable style checking

    --doc-glob GLOB              Glob to run doc checks over (default: {app,lib}/**/*.rb)
    --doc-exclude GLOB           Exclude file or glob from documentation checking
    --no-readme                  Disable readme checking
    --no-doc                     Disable documentation checking

    --lt FILE,THRESHOLD          Check the number in FILE is < to THRESHOLD (a number or another file name)
    --lte FILE,THRESHOLD         Check the number in FILE is <= to THRESHOLD (a number or another file name)
    --eq FILE,THRESHOLD          Check the number in FILE is == to THRESHOLD (a number or another file name)
    --gte FILE,THRESHOLD         Check the number in FILE is >= to THRESHOLD (a number or another file name)
    --gt FILE,THRESHOLD          Check the number in FILE is > to THRESHOLD (a number or another file name)

-f, --all FILE                   Apply all checks to given file
    --max-violations VALUE       Max allowed violations (default: 0)
    --json                       Output as JSON
    --parallel                   Use all processors. Slower on small projects, faster on large.
    --color                      Colorize output

-v, --version                    Show version
-h, --help                       Show this message

Set default options using a .cane file:

> cat .cane
--no-doc
--abc-glob **/*.rb
> cane

It works exactly the same as specifying the options on the command-line. Command-line arguments will override arguments specified in the .cane file.

Integrating with Rake

begin
  require 'cane/rake_task'

  desc "Run cane to check quality metrics"
  Cane::RakeTask.new(:quality) do |cane|
    cane.abc_max = 10
    cane.add_threshold 'coverage/covered_percent', :>=, 99
    cane.no_style = true
    cane.abc_exclude = %w(Foo::Bar#some_method)
  end

  task :default => :quality
rescue LoadError
  warn "cane not available, quality task not provided."
end

Loading options from a .cane file is supported by setting canefile= to the file name.

Rescuing LoadError is a good idea, since rake -T failing is totally frustrating.

Adding to a legacy project

Cane can be configured to still pass in the presence of a set number of violations using the --max-violations option. This is ideal for retrofitting on to an existing application that may already have many violations. By setting the maximum to the current number, no immediate changes will be required to your existing code base, but you will be protected from things getting worse.

You may also consider beginning with high thresholds and ratcheting them down over time, or defining exclusions for specific troublesome violations (not recommended).

Integrating with SimpleCov

Any value in a file can be used as a threshold:

> echo "89" > coverage/.last_run.json
> cane --gte 'coverage/.last_run.json,90'

Quality threshold crossed

  coverage/covered_percent is 89, should be >= 90

Implementing your own checks

Checks must implement:

  • A class level options method that returns a hash of available options. This will be included in help output if the check is added before --help. If your check does not require any configuration, return an empty hash.
  • A one argument constructor, into which will be passed the options specified for your check.
  • A violations method that returns an array of violations.

See existing checks for guidance. Create your check in a new file:

# unhappy.rb
class UnhappyCheck < Struct.new(:opts)
  def self.options
    {
      unhappy_file: ["File to check", default: [nil]]
    }
  end

  def violations
    [
      description: "Files are unhappy",
      file:        opts.fetch(:unhappy_file),
      label:       ":("
    ]
  end
end

Include your check either using command-line options:

cane -r unhappy.rb --check UnhappyCheck --unhappy-file myfile

Or in your rake task:

require 'unhappy'

Cane::RakeTask.new(:quality) do |c|
  c.use UnhappyCheck, unhappy_file: 'myfile'
end

Protips

Writing class level documentation

Classes are commonly the first entry point into a code base, often for an oncall engineer responding to an exception, so provide enough information to orient first-time readers.

A good class level comment should answer the following:

  • Why does this class exist?
  • How does it fit in to the larger system?
  • Explanation of any domain-specific terms.

If you have specific documentation elsewhere (say, in the README or a wiki), a link to that suffices.

If the class is a known entry point, such as a regular background job that can potentially fail, then also provide enough context that it can be efficiently dealt with. In the background job case:

  • Should it be retried?
  • What if it failed 5 days ago and we're only looking at it now?
  • Who cares that this job failed?

Writing a readme

A good README should include at a minimum:

  • Why the project exists.
  • How to get started with development.
  • How to deploy the project (if applicable).
  • Status of the project (spike, active development, stable in production).
  • Compatibility notes (1.8, 1.9, JRuby).
  • Any interesting technical or architectural decisions made on the project (this could be as simple as a link to an external design document).

Compatibility

Requires CRuby 2.0, since it depends on the ripper library to calculate complexity metrics. This only applies to the Ruby used to run Cane, not the project it is being run against. In other words, you can run Cane against your 1.8 or JRuby project.

Support

Make a new github issue.

Contributing

Fork and patch! Before any changes are merged to master, we need you to sign an Individual Contributor Agreement (Google Form).

cane's People

Contributors

benmoss avatar chrishunt avatar coffeejunk avatar danielheath avatar fnd avatar fredwu avatar girasquid avatar jaredbeck avatar jsoref avatar justincampbell avatar loganhasson avatar marten avatar mipearson avatar mislav avatar myronmarston avatar orien avatar packetmonkey avatar parndt avatar pitr avatar salimane avatar svoynow avatar turboladen avatar xaviershay avatar yob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cane's Issues

Rake task `add_threshold` API is confusing

On a new project I naively tried to do this:

desc "Run cane to check quality metrics"
Cane::RakeTask.new(:cane) do |cane|
  cane.add_threshold 'coverage/covered_percent.txt', :==, 100 
end

...and cane didn't complain when the coverage percent was not 100%.

Looking at the code, I can see now that it only supports >=, but this was counterintuitive to me: why accept an operator argument if you're only going to support one operator? Worse, it did not give me a warning or an error that my threshold check wasn't being run at all.

False positive for "coding" declaration regex

The regex is too liberal. It finds the following class as undocumented:

module FaradayMiddleware
  # Public: Parse a Transfer-Encoding: Chunked response to just the original data
  class Chunked < FaradayMiddleware::ResponseMiddleware
    TRANSFER_ENCODING = 'transfer-encoding'.freeze
    # ...
  end
end

bug: stack level too deep

** Invoke cane (first_time)
** Invoke cane:quality (first_time)
** Execute cane:quality
/Users/me/somedir/tmp/bundle/ruby/2.1.0/gems/cane-2.6.2/lib/cane/abc_check.rb:103: stack level too deep (SystemStackError)

Rspec integration in spec_helper.rb

Assuming I've understood the point at which cane hooks into the testing lifecycle, it would be nice if we could drop a require 'cane' statement (or similar) into the Rspec spec_helper.rb, and have cane automatically execute as part of the Rspec suite without having to invoke a separate command.

"Classes not documented" gives false positives

I use the magic_encoding gem to automatically insert 'magic' UTF-8 comments into all of my Ruby files.

All of the files that have had a magic encoding line inserted are reported by cane to be documented, which they definitely are not. It looks like cane is fooled by simply having a comment on the line preceding the declaration of a class.

magic encoding line:

# -*- encoding : utf-8 -*-

Re-opened Classes Trigger Doc Violation

It's not uncommon to re-open a class in another file, but Cane considers these doc violations if no documentation is included (even if the class is documented elsewhere). Cane could track documented classes (and delete previously-reported violations as it goes if a class is documented in a later file), but I'm not sure if that's the best way to handle things.

Allow Cane::RakeTask to pick up .cane files in subdirectories

As it stands, when I put .cane files in subdirectories, those preferences are reflected for files that fall in or under the same branch of directory hierarchy when I run cane from the command line. However, Cane::RakeTask only picks up preferences established in a .cane file in the root folder rather than subfolders.

If you want to use cane for CI but have certain checks you want to ignore for certain folders, that doesn't seem possible right now with a single rake task.

Invalid byte sequence in UTF-8 (ArgumentError)

Running against cane 2.5.2

on osx snowleopard, cruby 2.0.0-p195 installed via rvm, run via metric_fu 4.4.0

~/.rvm/gems/ruby-2.0.0-p195@global/gems/cane-2.5.2/lib/cane/style_check.rb:57:in `violations_for_line': invalid byte sequence in UTF-8 (ArgumentError)
        from ~/.rvm/gems/ruby-2.0.0-p195@global/gems/cane-2.5.2/lib/cane/style_check.rb:40:in `block (2 levels) in violations'

It would appear this was fixed by cane 2.6.0, but I didn't see a ticket for that, so am creating an issue to document it.

My guess it was the Bugfix: better handling of invalid strings

invalid byte sequence in UTF-8

when I execute:

bundle exec cane --abc-glob '{lib,spec}/*/.rb' --abc-max 15

this error appears:

gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:28:in `violations_for_line': invalid byte sequence in UTF-8 (ArgumentError)
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:14:in `block (2 levels) in violations'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:42:in `each_line'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:42:in `each'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:42:in `map'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:42:in `with_index'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:42:in `map_lines'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:13:in `block in violations'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:12:in `map'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/style_check.rb:12:in `violations'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:41:in `block in violations'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:39:in `each'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:39:in `map'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:39:in `violations'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:29:in `run'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane.rb:9:in `run'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/lib/cane/cli.rb:13:in `run'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/gems/cane-1.4.0/bin/cane:5:in `<top (required)>'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/bin/cane:19:in `load'
    from /home/nicolas/.rvm/gems/ruby-1.9.2-p290/bin/cane:19:in `<main>'

any help would be appreciated.

RUBYGEMS VERSION: 1.8.10
RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i686-linux]

thanks!

Allow custom checks to be specified on the command-line

Copy how rspec allows custom formatters. For bonus points, figure out a way to allow those custom formatters to also support CLI options i.e. cane --check MyCheck --help shows --mycheck-some-var in the output. (This might be too ugly a thing to be done with OptionParser.)

ABC violation output is weird for classes defined using `Struct.new do...end`

I've got a class defined like so:

module Packrat
  CollectionContainer = Struct.new(:collection_occurrence) do
    def metadata
      # some code that violates my ABC threshold
    end
  end
end

The output from the ABC check is:

Methods exceeded maximum allowed ABC complexity (1):

  lib/packrat/structs.rb  Packrat > metadata  12

Notice that the method is listed as Packrat > metadata rather than Packrat > CollectionContainer > metadata. I can easily see why: I'm defining the method in the block passed to Struct.new, and cane doesn't realize that it's being defined on the CollectionContainer class since it's not the normal class CollectionContainer ... end style class definition.

It'd be reasonable to simply say "this isn't supported by cane", but if it wasn't too difficult, it'd be nice. I prefer defining struct classes using this block form over class CollectionContainer < Struct.new because the latter form subclasses a subclass of Struct (since Struct.new returns a Struct subclass) and therefore has an extra class in the ancestor chain, which can slow down method dispatch a bit by giving ruby an extra stop on the list of ancestors it traverses when dispatching methods.

If something is done to handle this case, it can be applied to defining classes using Class.new { ... } as well, since it's basically the same issue.

tailor 1.0 broke cane

The stack trace


uninitialized constant Tailor::FileLine
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/rake/ext/module.rb:36:in `const_missing'
/Users/ywen/.rvm/gems/ruby-1.9.3-p125@galaxy-interactors/gems/cane-1.2.0/lib/cane/style_check.rb:38:in `<module:Cane>'
/Users/ywen/.rvm/gems/ruby-1.9.3-p125@galaxy-interactors/gems/cane-1.2.0/lib/cane/style_check.rb:5:in `<top (required)>'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/gems/ruby-1.9.3-p125@galaxy-interactors/gems/cane-1.2.0/lib/cane.rb:2:in `<top (required)>'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/gems/ruby-1.9.3-p125@galaxy-interactors/gems/cane-1.2.0/lib/cane/cli.rb:1:in `<top (required)>'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/ywen/.rvm/gems/ruby-1.9.3-p125@galaxy-interactors/gems/cane-1.2.0/lib/cane/rake_task.rb:52:in `block in initialize'

Cane breaks on Ruby 1.8.7; contains 1.9-specific code.

/Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/runner.rb:3:in `require': /Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/violation_formatter.rb:13: syntax error, unexpected ':', expecting ')' (SyntaxError)
        v.merge(file_and_line: v[:line] ?
                              ^
/Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/violation_formatter.rb:16: syntax error, unexpected ')', expecting kEND
/Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/violation_formatter.rb:61: syntax error, unexpected $end, expecting kEND
    from /Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/runner.rb:3
    from /Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/cli.rb:1:in `require'
    from /Library/Ruby/Gems/1.8/gems/cane-2.4.0/lib/cane/cli.rb:1
    from /Library/Ruby/Gems/1.8/gems/cane-2.4.0/bin/cane:3:in `require'
    from /Library/Ruby/Gems/1.8/gems/cane-2.4.0/bin/cane:3
    from /usr/bin/cane:23:in `load'
    from /usr/bin/cane:23

--max-violations is ignored

I found that --max-violations is being ignored whether I give is as a cli input or in a .cane file, for a single file (specified with -f) or for an entire project.

I'm simply running

cane --max-violations 222

Let me know if you need more details or an example file - it's just that the option is being ignored on anything I try.

readme.md fails README check

I have a file called readme.md and it is failing the documentation check because its not all-caps. GitHub doesn't seem to mind, is there any reason cane does?

Why does this method have such a high B score?

I have a hash used to generate a vcard that looks like this:

def vcard_params
    {
        :first_name => first_name,
        :last_name => last_name,
        :org => organization,
        :title => title,
        :email => email,
        :phone => office,
        :mobile => mobile,
        :fax => fax,
        :website => website,
        :address => address,
        :city => city,
        :state => state,
        :zip => zip,
        :country => country
    }.delete_if{ |k,v| v.blank? }
end

And it gets an ABC score of A = 1, B = 18, C = 0. Why is the B score so high?

edit: delete_if isn't causing the problem, I removed it and the score stayed the same.

HTML generated output

Most of the good metric tools out there have some way to generate HTML reports. It'd be nice if cane did that.

Is there a way to extend cane?

I prefer to place a limit on the size of my classes and methods. I can do this in tailor, but it is incredibly slow compared to cane, plus, I'd prefer to have just one command to run, outside of rake to check the quality on a pre-commit hook.

Besides forking/monkey patching... is there anything built in?

Recursively run cane over a directory of files

Would be helpful if cane had a -r option to scan files in a directory recursively.

Would be even better if this were on by default, so that cane . did something a bit more useful than:

$ cane .
(no output)

for a directory containing hundreds of unlinted Ruby files.

Global .cane file

It'd be nice to have a global .cane file that's loaded from the home directory, similar to guard and the .gemrc file. Any thoughts on this?

AmbiguousOption errors should be handled gracefully

The following should not leak an OptionParser error. Should display --help the same way as when an unknown option is specified.

> cane -abc-max                                                      
gems/cane-2.0.0/lib/cane/cli/spec.rb:46:in `parse': ambiguous option: -abc-max (OptionParser::AmbiguousOption)

JsonFormatter not working from rake task

wrong number of arguments (2 for 1)
/Users/jsmith/.rvm/gems/ruby-1.9.3-p448@myapp/gems/cane-2.6.0/lib/cane/json_formatter.rb:8:in `initialize'

It looks like when output colorization was added in 652c2f8
an options hash parameter was added to the call to initialize the formatter, but it wasn't added to the initializer for JsonFormatter.

Pull Request forthcoming

Strange naming of options and values to set them with Rake task

The names of the options used in the Rake task seem to not reflect their usage. For instance, this sets the quality check to not check ABC metrics. When it seems the opposite would be true.

Cane::RakeTask.new(:quality) do |cane|
  cane.no_abc = false
end

option to check individual files

I like to use Cane to check just the file I'm currently working on - which, AFAICT, currently requires specifying the filename for three options separately:

$ cane --abc-glob $filename --style-glob $filename --doc-glob $filename

It might be nice to provide a shortcut for this - e.g. accepting individual filenames as regular (non-option) arguments:

$ cane /path/to/file_a /path/to/file_b

I'd be happy to take a crack at implementing this if it was deemed desirable.

undefined method `[]' for nil:NilClass

09:37:53 $ cane
/Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/abc_check.rb:30:in `process_ast': undefined method `[]' for nil:NilClass (NoMethodError)
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/abc_check.rb:22:in `find_violations'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/abc_check.rb:13:in `block in violations'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/abc_check.rb:12:in `map'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/abc_check.rb:12:in `violations'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:41:in `block in violations'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:39:in `each'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:39:in `map'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:39:in `violations'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:29:in `run'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane.rb:9:in `run'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/lib/cane/cli.rb:13:in `run'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/cane-1.0.0/bin/cane:9:in `<top (required)>'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/bin/cane:19:in `load'
    from /Users/sobrinho/.rbenv/versions/1.9.3-p0/bin/cane:19:in `<main>'

What you need to debug the reason? :)

Classes with no methods still require a comment if they are defined within a class

Is this intentional?

# Bar!
class Foo
  class WorldError < StandardError; end

  # I need a comment even though I have no methods =(
  class UnusedError < StandardError; end

  def bar(the_sky_is_falling = false)
    if the_sky_is_falling
      raise WorldError.new('oh noes!')
    else
      puts 'hello world!'
    end
  end
end
cane -f foo.rb

Class definitions require explanatory comments on preceding line (1):

  foo.rb:3  WorldError

Total Violations: 1

Can I get write access?

People still email me about this repo, I want to clean it up a bit (merge some PRs, close some issues)

thx ❤️

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

value "class" raises exception in multiline definition of array using %w

The value "class" raises exception in a multi-line definition of an array using %w.

HTML_ATTRS = %w[
  class
  style
  ...
]

raises undefined method `[]' for nil:NilClass (NoMethodError) in line

line.match(/class\s+([^\s;]+)/)[1]

In method find_violations the condition

class_definition?(line) && !comment?(last_line)

is not specific enough. Something like

class_definition?(line) && !comment?(last_line) && !array_context?

would be great.

A workaround is, to make non-class-definition-lines not match

/^\s*class\s+/

For the example above, this means:

HTML_ATTRS = %w[ class
  style
  ...
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.