Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

We have the line number

  • Loading branch information...
commit fddb94c34f7be01119b04b575fe23f290386b726 1 parent 824e39b
Bruno Michel nono authored
4 lib/readminator.rb
View
@@ -2,9 +2,9 @@ module Readminator
def validate(readme)
errors = []
blocks = Parsinator.blocks(readme)
- blocks.each do |(language, code)|
+ blocks.each do |(line, language, code)|
validator = Validator.for(language)
- errors << validator.check(code)
+ errors << validator.check(code, line)
end
errors.compact
end
7 lib/readminator/parsinator.rb
View
@@ -5,7 +5,12 @@
module Readminator
class Parsinator
def self.blocks(readme)
- readme.scan(/^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$/m)
+ blocks = readme.scan(/^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$/m)
+ lines = readme.split("\n")
+ blocks.map do |(language, code)|
+ line = code.split("\n", 1).first
+ [lines.index(line), language, code]
+ end
end
end
end
4 lib/readminator/validator.rb
View
@@ -7,12 +7,12 @@ def self.for(language)
end
class Ruby
- def check(code)
+ def check(code, line)
Open3.popen3("ruby -c") do |stdin, stdout, stderr, wait|
stdin << code
stdin.close
exit_status = wait.value
- return { line: 1, error: stderr.read.chomp, language: "ruby" } if exit_status != 0
+ return { line: line, error: stderr.read.chomp, language: "ruby" } if exit_status != 0
end
nil
end
2  test/fixtures/04-ruby.rb
View
@@ -1 +1 @@
-[ { line: "5", error: "", language: "ruby"}]
+[ { line: 5, error: "-:1: unterminated string meets end of file", language: "ruby"}]
2  test/fixtures/06-ruby.rb
View
@@ -1 +1 @@
-[ { line: "3", error: "", language: "ruby"}]
+[ { line: 3, error: "", language: "ruby"}]
Please sign in to comment.
Something went wrong with that request. Please try again.