morecane 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.rdoc +67 -0
- data/lib/morecane.rb +6 -0
- data/lib/morecane/encoding_check.rb +41 -0
- data/lib/morecane/must_match_check.rb +43 -0
- data/lib/morecane/must_not_match_check.rb +43 -0
- metadata +102 -0
data/CHANGELOG
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= Morecane
|
2
|
+
|
3
|
+
== What?
|
4
|
+
|
5
|
+
The cane gem provides a great framework for running quality checks over your
|
6
|
+
ruby project as part of continuous integration build. It comes with a few
|
7
|
+
checks out of the box, but also provides an API for loading custom checks.
|
8
|
+
|
9
|
+
This gem provides a set of additional checks that I use across my projects.
|
10
|
+
Maybe you'll find the useful as well.
|
11
|
+
|
12
|
+
== How?
|
13
|
+
|
14
|
+
Install this project like any rubygem:
|
15
|
+
|
16
|
+
gem install morecane
|
17
|
+
|
18
|
+
Or add it to your Gemfile:
|
19
|
+
|
20
|
+
gem 'morecane'
|
21
|
+
|
22
|
+
Then create a new rake task and load in the checks you require
|
23
|
+
|
24
|
+
require 'cane/rake_task'
|
25
|
+
require 'morecane'
|
26
|
+
|
27
|
+
desc "Run cane to check quality metrics"
|
28
|
+
Cane::RakeTask.new(:quality) do |cane|
|
29
|
+
cane.use Morecane::EncodingCheck, encoding_glob: "{app,lib,spec}/**/*.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
=== Checks
|
33
|
+
|
34
|
+
Here is a list of the checks available in this gem and the options they take.
|
35
|
+
|
36
|
+
==== Morecane::EncodingCheck
|
37
|
+
|
38
|
+
Ensure files have a ruby encoding marker in the first two lines.
|
39
|
+
|
40
|
+
* encoding_glob - a string to specify the files to check. You probably want
|
41
|
+
something list "{app,lib,spec}/**/*.rb"
|
42
|
+
|
43
|
+
==== Morecane::MustMatchCheck
|
44
|
+
|
45
|
+
Ensure files match a given regular expression.
|
46
|
+
|
47
|
+
* must_match_glob - a string to specify the files to check. You probably want
|
48
|
+
something list "{app,lib}/**/*.rb"
|
49
|
+
* must_match_regexp - a regular expression to check each file against
|
50
|
+
|
51
|
+
==== Morecane::MustNotMatchCheck
|
52
|
+
|
53
|
+
Ensure files do not match a given regular expression.
|
54
|
+
|
55
|
+
* must_not_match_glob - a string to specify the files to check. You probably want
|
56
|
+
something list "{app,lib}/**/*.rb"
|
57
|
+
* must_not_match_regexp - a regular expression to check each file against
|
58
|
+
|
59
|
+
== Who?
|
60
|
+
|
61
|
+
This gem is written and maintained by James Healy <james@yob.id.au>
|
62
|
+
|
63
|
+
== More?
|
64
|
+
|
65
|
+
For more information on cane, check out it's comprehensive README
|
66
|
+
|
67
|
+
https://github.com/square/cane
|
data/lib/morecane.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Morecane
|
4
|
+
# Creates violations for ruby files that have no encoding marker in the
|
5
|
+
# first two lines
|
6
|
+
class EncodingCheck < Struct.new(:opts)
|
7
|
+
def self.options
|
8
|
+
{
|
9
|
+
encoding_glob: ['Glob to run encoding checks over',
|
10
|
+
default: '{app,lib,spec}/**/*.rb',
|
11
|
+
variable: 'GLOB',
|
12
|
+
clobber: :no_encoding]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def violations
|
17
|
+
file_names.map { |file_name|
|
18
|
+
find_violations(file_name)
|
19
|
+
}.flatten.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def find_violations(file_name)
|
25
|
+
data = ::File.open(file_name, 'r:utf-8')
|
26
|
+
line_one, line_two = *data.lines
|
27
|
+
|
28
|
+
if !line_one.to_s.match(/coding:/) && !line_two.to_s.match(/coding:/)
|
29
|
+
{
|
30
|
+
description: "Source file missing an encoding marker",
|
31
|
+
file: file_name
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_names
|
37
|
+
Dir[opts.fetch(:encoding_glob)]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Morecane
|
4
|
+
# Creates violations for ruby files that don't match a given regexp
|
5
|
+
#
|
6
|
+
class MustMatchCheck < Struct.new(:opts)
|
7
|
+
def self.options
|
8
|
+
{
|
9
|
+
must_match_glob: ['Glob to run match checks over',
|
10
|
+
default: '{app,lib,spec}/**/*.rb',
|
11
|
+
variable: 'GLOB',
|
12
|
+
clobber: :no_must_match],
|
13
|
+
must_match_regexp: ['Regexp to check files against',
|
14
|
+
variable: 'REGEXP',
|
15
|
+
clobber: :no_must_match],
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def violations
|
20
|
+
file_names.map { |file_name|
|
21
|
+
find_violations(file_name)
|
22
|
+
}.flatten.compact
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def find_violations(file_name)
|
28
|
+
data = ::File.open(file_name, 'r:utf-8').read
|
29
|
+
|
30
|
+
if !data.match(opts.fetch(:must_match_regexp))
|
31
|
+
{
|
32
|
+
description: "Source file doesn't match regexp",
|
33
|
+
file: file_name
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_names
|
39
|
+
Dir[opts.fetch(:must_match_glob)]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Morecane
|
4
|
+
# Creates violations for ruby files that match a given regexp
|
5
|
+
#
|
6
|
+
class MustNotMatchCheck < Struct.new(:opts)
|
7
|
+
def self.options
|
8
|
+
{
|
9
|
+
must_not_match_glob: ['Glob to run no-match checks over',
|
10
|
+
default: '{app,lib,spec}/**/*.rb',
|
11
|
+
variable: 'GLOB',
|
12
|
+
clobber: :no_must_not_nomatch],
|
13
|
+
must_not_match_regexp: ['Regexp to check files against',
|
14
|
+
variable: 'REGEXP',
|
15
|
+
clobber: :no_must_not_match],
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def violations
|
20
|
+
file_names.map { |file_name|
|
21
|
+
find_violations(file_name)
|
22
|
+
}.flatten.compact
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def find_violations(file_name)
|
28
|
+
data = ::File.open(file_name, 'r:utf-8').read
|
29
|
+
|
30
|
+
if data.match(opts.fetch(:must_not_match_regexp))
|
31
|
+
{
|
32
|
+
description: "Source file matches regexp",
|
33
|
+
file: file_name
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_names
|
39
|
+
Dir[opts.fetch(:must_not_match_glob)]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: morecane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Healy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cane
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.3'
|
62
|
+
description: A set of common checks that I use with cane across my projects
|
63
|
+
email:
|
64
|
+
- james@yob.id.au
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/morecane.rb
|
70
|
+
- lib/morecane/must_match_check.rb
|
71
|
+
- lib/morecane/must_not_match_check.rb
|
72
|
+
- lib/morecane/encoding_check.rb
|
73
|
+
- README.rdoc
|
74
|
+
- CHANGELOG
|
75
|
+
homepage: http://github.com/yob/morecane
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --title
|
80
|
+
- Morecane
|
81
|
+
- --line-numbers
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.7
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.2
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.23
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Extra checks for the cane gem
|
102
|
+
test_files: []
|