Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'readme-check'

  • Loading branch information...
commit 1812cb31259b83e49a5b8f519dbce61e71ffbd31 2 parents d23e3e6 + dac4ded
@xaviershay xaviershay authored
View
60 lib/cane.rb
@@ -1,58 +1,2 @@
-require 'parallel'
-
-require 'cane/violation_formatter'
-
-module Cane
- def run(*args)
- Runner.new(*args).run
- end
- module_function :run
-
- def task_runner(opts)
- if opts[:parallel]
- Parallel
- else
- SimpleTaskRunner
- end
- end
- module_function :task_runner
-
- # Mirrors the Parallel gem's interface but does not provide any parralleism.
- # This is faster for smaller tasks since it doesn't incur any overhead for
- # creating new processes and communicating between them.
- class SimpleTaskRunner
- def self.map(enumerable, &block)
- enumerable.map(&block)
- end
- end
-
- # Orchestrates the running of checks per the provided configuration, and
- # hands the result to a formatter for display. This is the core of the
- # application, but for the actual entry point see `Cane::CLI`.
- class Runner
- def initialize(spec)
- @opts = spec
- @checks = spec[:checks]
- end
-
- def run
- outputter.print ViolationFormatter.new(violations)
-
- violations.length <= opts.fetch(:max_violations)
- end
-
- protected
-
- attr_reader :opts, :checks
-
- def violations
- @violations ||= checks.
- map {|check| check.new(opts).violations }.
- flatten
- end
-
- def outputter
- opts.fetch(:out, $stdout)
- end
- end
-end
+require 'cane/cli'
+require 'cane/version'
View
1  lib/cane/abc_check.rb
@@ -2,6 +2,7 @@
require 'set'
require 'cane/file'
+require 'cane/task_runner'
module Cane
View
2  lib/cane/cli.rb
@@ -1,4 +1,4 @@
-require 'cane'
+require 'cane/runner'
require 'cane/version'
require 'cane/cli/parser'
View
27 lib/cane/doc_check.rb
@@ -1,4 +1,5 @@
require 'cane/file'
+require 'cane/task_runner'
module Cane
@@ -13,11 +14,12 @@ def self.key; :doc; end
def self.name; "documentation checking"; end
def self.options
{
- doc_glob: ['Glob to run doc checks over',
- default: '{app,lib}/**/*.rb',
- variable: 'GLOB',
- clobber: :no_doc],
- no_doc: ['Disable documentation checking', cast: ->(x) { !x }]
+ doc_glob: ['Glob to run doc checks over',
+ default: '{app,lib}/**/*.rb',
+ variable: 'GLOB',
+ clobber: :no_doc],
+ no_readme: ['Disable readme checking', cast: ->(x) { !x }],
+ no_doc: ['Disable documentation checking', cast: ->(x) { !x }]
}
end
@@ -29,7 +31,7 @@ def self.options
def violations
return [] if opts[:no_doc]
- worker.map(file_names) {|file_name|
+ missing_file_violations + worker.map(file_names) {|file_name|
find_violations(file_name)
}.flatten
end
@@ -50,6 +52,19 @@ def find_violations(file_name)
end.compact
end
+ def missing_file_violations
+ result = []
+ unless opts[:no_readme]
+ unless ['', '.txt', '.md'].any? {|x| Cane::File.exists?("README#{x}") }
+ result << {
+ description: 'Missing documentation',
+ label: 'No README found'
+ }
+ end
+ end
+ result
+ end
+
def file_names
Dir[opts.fetch(:doc_glob)]
end
View
40 lib/cane/runner.rb
@@ -0,0 +1,40 @@
+require 'parallel'
+
+require 'cane/violation_formatter'
+
+module Cane
+ def run(*args)
+ Runner.new(*args).run
+ end
+ module_function :run
+
+ # Orchestrates the running of checks per the provided configuration, and
+ # hands the result to a formatter for display. This is the core of the
+ # application, but for the actual entry point see `Cane::CLI`.
+ class Runner
+ def initialize(spec)
+ @opts = spec
+ @checks = spec[:checks]
+ end
+
+ def run
+ outputter.print ViolationFormatter.new(violations)
+
+ violations.length <= opts.fetch(:max_violations)
+ end
+
+ protected
+
+ attr_reader :opts, :checks
+
+ def violations
+ @violations ||= checks.
+ map {|check| check.new(opts).violations }.
+ flatten
+ end
+
+ def outputter
+ opts.fetch(:out, $stdout)
+ end
+ end
+end
View
1  lib/cane/style_check.rb
@@ -1,6 +1,7 @@
require 'set'
require 'cane/file'
+require 'cane/task_runner'
module Cane
View
19 lib/cane/task_runner.rb
@@ -0,0 +1,19 @@
+module Cane
+ def task_runner(opts)
+ if opts[:parallel]
+ Parallel
+ else
+ SimpleTaskRunner
+ end
+ end
+ module_function :task_runner
+
+ # Mirrors the Parallel gem's interface but does not provide any parralleism.
+ # This is faster for smaller tasks since it doesn't incur any overhead for
+ # creating new processes and communicating between them.
+ class SimpleTaskRunner
+ def self.map(enumerable, &block)
+ enumerable.map(&block)
+ end
+ end
+end
View
1  spec/cane_spec.rb
@@ -3,6 +3,7 @@
require 'cane/cli'
require 'cane/rake_task'
+require 'cane/task_runner'
# Acceptance tests
describe 'The cane application' do
View
15 spec/doc_check_spec.rb
@@ -53,4 +53,19 @@ class Doc; end
file_name, 4, "AlsoNoDoc"
]
end
+
+ it 'creates a violation for missing README' do
+ file = fire_replaced_class_double("Cane::File")
+ stub_const("Cane::File", file)
+ file.should_receive(:exists?).with("README").and_return(false)
+ file.should_receive(:exists?).with("README.md").and_return(false)
+ file.should_receive(:exists?).with("README.txt").and_return(false)
+
+ violations = check("").violations
+ violations.length.should == 1
+
+ violations[0].values_at(:description, :label).should == [
+ "Missing documentation", "No README found"
+ ]
+ end
end
View
5 spec/parser_spec.rb
@@ -97,4 +97,9 @@ def run(cli_args)
output.should include("Usage:")
result.should_not be
end
+
+ it 'handles no_readme option' do
+ _, result = run("--no-readme")
+ result[:no_readme].should be
+ end
end
View
2  spec/runner_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-require 'cane'
+require 'cane/runner'
describe Cane::Runner do
describe '#run' do
Please sign in to comment.
Something went wrong with that request. Please try again.