stars-checkers 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/VERSION.yml +4 -0
- data/bin/check +40 -0
- data/lib/checkers.rb +5 -0
- data/lib/checkers/parser/git.rb +21 -0
- data/lib/checkers/processor.rb +64 -0
- data/lib/checkers/processors/erb.rb +17 -0
- data/lib/checkers/processors/haml.rb +16 -0
- data/lib/checkers/processors/ruby.rb +18 -0
- data/lib/checkers/processors/sass.rb +16 -0
- data/test/checkers_test.rb +56 -0
- data/test/files/file.xyz +1 -0
- data/test/files/invalid.erb +8 -0
- data/test/files/invalid.haml +6 -0
- data/test/files/invalid.rb +1 -0
- data/test/files/invalid.rhtml +8 -0
- data/test/files/invalid.sass +2 -0
- data/test/files/valid.erb +8 -0
- data/test/files/valid.haml +5 -0
- data/test/files/valid.rb +2 -0
- data/test/files/valid.rhtml +8 -0
- data/test/files/valid.sass +2 -0
- data/test/test_helper.rb +10 -0
- metadata +82 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 27stars Limited.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
.oooooo. oooo oooo
|
2
|
+
d8P' `Y8b `888 `888
|
3
|
+
888 888 .oo. .ooooo. .ooooo. 888 oooo .ooooo. oooo d8b .oooo.o
|
4
|
+
888 888P"Y88b d88' `88b d88' `"Y8 888 .8P' d88' `88b `888""8P d88( "8
|
5
|
+
888 888 888 888ooo888 888 888888. 888ooo888 888 `"Y88b.
|
6
|
+
`88b ooo 888 888 888 .o 888 .o8 888 `88b. 888 .o 888 o. )88b
|
7
|
+
`Y8bood8P' o888o o888o `Y8bod8P' `Y8bod8P' o888o o888o `Y8bod8P' d888b 8""888P'
|
8
|
+
|
9
|
+
== Suggested Improvements
|
10
|
+
|
11
|
+
* Specify filename(s) directly as command-line argument
|
12
|
+
* bin support (parse shebang line to determine type)
|
13
|
+
* SVN support (parse svn status)
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2009 27stars Limited. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/bin/check
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
7
|
+
require 'checkers'
|
8
|
+
include Checkers
|
9
|
+
|
10
|
+
ARGV.options do |o|
|
11
|
+
o.banner = "Usage: #{File.basename(__FILE__)}"
|
12
|
+
o.define_head "Easy syntax checking of source files."
|
13
|
+
# o.on("-f", "--first=[val]", String,
|
14
|
+
# "A long and short (optional) string argument",
|
15
|
+
# "Default: #{OPTIONS[:first]}") { |OPTIONS[:first]| }
|
16
|
+
# o.on("-a", "--another=val", Integer,
|
17
|
+
# "Requires an int argument") { |OPTIONS[:another]| }
|
18
|
+
# o.on("-b", "--boolean",
|
19
|
+
# "A boolean argument") { |OPTIONS[:bool]| }
|
20
|
+
# o.on("--list=[x,y,z]", Array,
|
21
|
+
# "Example 'list' of arguments") { |OPTIONS[:list]| }
|
22
|
+
# o.separator ""
|
23
|
+
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit(1) }
|
24
|
+
o.parse!
|
25
|
+
end
|
26
|
+
|
27
|
+
# Process files
|
28
|
+
if File.exist?('.git')
|
29
|
+
@filenames = Parser::Git.parse(`git status`)
|
30
|
+
else
|
31
|
+
puts 'No file(s) specified.'
|
32
|
+
exit(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
@filenames.each do |filename|
|
36
|
+
result = Processor.check(filename)
|
37
|
+
unless result == :na
|
38
|
+
puts result.to_s.upcase.ljust(7) + (' '*2) + filename
|
39
|
+
end
|
40
|
+
end
|
data/lib/checkers.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Checkers
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
|
5
|
+
class Git
|
6
|
+
|
7
|
+
def self.parse(text)
|
8
|
+
filenames = []
|
9
|
+
text.each_line do |line|
|
10
|
+
if md = line.match(/^#(\s*)(new file|modified):(\s*)(.*)$/)
|
11
|
+
filenames << md[4]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
filenames
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Checkers
|
2
|
+
|
3
|
+
# Thanks to: http://eigenclass.org/hiki.rb?ruby+plugins
|
4
|
+
class Processor
|
5
|
+
@registered_processors = {}
|
6
|
+
class << self
|
7
|
+
attr_reader :registered_processors
|
8
|
+
private :new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.check(filename)
|
12
|
+
ext = File.extname(filename).delete('.')
|
13
|
+
if processor = self.for(ext)
|
14
|
+
if processor.check(filename)
|
15
|
+
:valid
|
16
|
+
else
|
17
|
+
:invalid
|
18
|
+
end
|
19
|
+
else
|
20
|
+
:na
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.for(extension)
|
25
|
+
# TODO: just initialise this once elsewhere
|
26
|
+
# Map file extensions to the processors that process them
|
27
|
+
filetypes = {}
|
28
|
+
self.registered_processors.each do |definition|
|
29
|
+
name, processor = *definition
|
30
|
+
processor.handles.to_a.each do |ext|
|
31
|
+
filetypes[ext] = name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# Return processor for this extension
|
35
|
+
self.registered_processors[filetypes[extension]]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.define(name, &block)
|
39
|
+
p = new
|
40
|
+
p.instance_eval(&block)
|
41
|
+
self.registered_processors[name] = p
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.def_field(*names)
|
45
|
+
class_eval do
|
46
|
+
names.each do |name|
|
47
|
+
define_method(name) do |*args|
|
48
|
+
case args.size
|
49
|
+
when 0: instance_variable_get("@#{name}")
|
50
|
+
else instance_variable_set("@#{name}", *args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def_field :handles
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# Load plugins
|
63
|
+
PROCESSOR_DIR = File.dirname(File.expand_path(__FILE__))
|
64
|
+
Dir.glob(File.join(PROCESSOR_DIR, 'processors', '*.rb')).map { |file| load file }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
Checkers::Processor.define "erb" do
|
5
|
+
handles ['erb','rhtml']
|
6
|
+
|
7
|
+
def check(filename)
|
8
|
+
Open3.popen3('ruby -c') do |stdin, stdout, stderr|
|
9
|
+
stdin.puts(ERB.new(File.read(filename), nil, '-').src)
|
10
|
+
stdin.close
|
11
|
+
ret = (error = (stderr.readline rescue false)) ? false : true
|
12
|
+
stdout.close rescue false
|
13
|
+
stderr.close rescue false
|
14
|
+
ret
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
Checkers::Processor.define "haml" do
|
4
|
+
handles 'haml'
|
5
|
+
|
6
|
+
def check(filename)
|
7
|
+
Open3.popen3('haml --stdin --check') do |stdin, stdout, stderr|
|
8
|
+
stdin.puts(File.read(filename))
|
9
|
+
stdin.close
|
10
|
+
ret = (error = (stderr.readline rescue false)) ? false : true
|
11
|
+
stdout.close rescue false
|
12
|
+
stderr.close rescue false
|
13
|
+
ret
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
Checkers::Processor.define "ruby" do
|
5
|
+
# TODO: handle 'Rakefile'
|
6
|
+
handles ['rb','rjs']
|
7
|
+
|
8
|
+
def check(filename)
|
9
|
+
Open3.popen3('ruby -c') do |stdin, stdout, stderr|
|
10
|
+
stdin.puts(File.read(filename))
|
11
|
+
stdin.close
|
12
|
+
ret = (error = (stderr.readline rescue false)) ? false : true
|
13
|
+
stdout.close rescue false
|
14
|
+
stderr.close rescue false
|
15
|
+
ret
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
Checkers::Processor.define "sass" do
|
4
|
+
handles 'sass'
|
5
|
+
|
6
|
+
def check(filename)
|
7
|
+
Open3.popen3('sass --stdin --check') do |stdin, stdout, stderr|
|
8
|
+
stdin.puts(File.read(filename))
|
9
|
+
stdin.close
|
10
|
+
ret = (error = (stderr.readline rescue false)) ? false : true
|
11
|
+
stdout.close rescue false
|
12
|
+
stderr.close rescue false
|
13
|
+
ret
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CheckersTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Valid files" do
|
6
|
+
setup do
|
7
|
+
@filenames = Dir.glob(File.join('test', 'files', 'valid*'))
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be detected as valid" do
|
11
|
+
assert(@filenames.all? do |filename|
|
12
|
+
Checkers::Processor.check(filename) == :valid
|
13
|
+
end)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "Invalid files" do
|
18
|
+
setup do
|
19
|
+
@filenames = Dir.glob(File.join('test', 'files', 'invalid*'))
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be detected as invalid" do
|
23
|
+
assert(@filenames.all? do |filename|
|
24
|
+
Checkers::Processor.check(filename) == :invalid
|
25
|
+
end)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "Git status output (with new and modified files)" do
|
30
|
+
setup do
|
31
|
+
@status =<<EOS
|
32
|
+
# On branch master
|
33
|
+
# Changes to be committed:
|
34
|
+
# (use "git reset HEAD <file>..." to unstage)
|
35
|
+
#
|
36
|
+
# new file: lib/checkers.rb
|
37
|
+
#
|
38
|
+
# Changed but not updated:
|
39
|
+
# (use "git add <file>..." to update what will be committed)
|
40
|
+
#
|
41
|
+
# modified: test/checkers_test.rb
|
42
|
+
#
|
43
|
+
# Untracked files:
|
44
|
+
# (use "git add <file>..." to include in what will be committed)
|
45
|
+
#
|
46
|
+
# lib/checkers/
|
47
|
+
EOS
|
48
|
+
end
|
49
|
+
|
50
|
+
should "be correctly parsed in to filenames" do
|
51
|
+
filenames = Checkers::Parser::Git.parse(@status)
|
52
|
+
assert_equal ['lib/checkers.rb', 'test/checkers_test.rb'], filenames
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/test/files/file.xyz
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
abcdefghijklmnopqrstuvwxyz
|
@@ -0,0 +1 @@
|
|
1
|
+
class Invalid
|
data/test/files/valid.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stars-checkers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-08 00:00:00 -08:00
|
13
|
+
default_executable: check
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: hello@27stars.co.uk
|
18
|
+
executables:
|
19
|
+
- check
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- VERSION.yml
|
28
|
+
- bin/check
|
29
|
+
- lib/checkers
|
30
|
+
- lib/checkers/parser
|
31
|
+
- lib/checkers/parser/git.rb
|
32
|
+
- lib/checkers/processor.rb
|
33
|
+
- lib/checkers/processors
|
34
|
+
- lib/checkers/processors/erb.rb
|
35
|
+
- lib/checkers/processors/haml.rb
|
36
|
+
- lib/checkers/processors/ruby.rb
|
37
|
+
- lib/checkers/processors/sass.rb
|
38
|
+
- lib/checkers.rb
|
39
|
+
- test/checkers_test.rb
|
40
|
+
- test/files
|
41
|
+
- test/files/file.xyz
|
42
|
+
- test/files/invalid.erb
|
43
|
+
- test/files/invalid.haml
|
44
|
+
- test/files/invalid.rb
|
45
|
+
- test/files/invalid.rhtml
|
46
|
+
- test/files/invalid.sass
|
47
|
+
- test/files/valid.erb
|
48
|
+
- test/files/valid.haml
|
49
|
+
- test/files/valid.rb
|
50
|
+
- test/files/valid.rhtml
|
51
|
+
- test/files/valid.sass
|
52
|
+
- test/test_helper.rb
|
53
|
+
- LICENSE
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/stars/checkers
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --inline-source
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.2.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: Easy syntax checking of source files.
|
81
|
+
test_files: []
|
82
|
+
|