learn_linter 1.6.9 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8dd5cb1e1a21941f889c8f0d26fdade640d150e0
4
- data.tar.gz: 8a31c1280f1d6cf72ca68ecdccd6c95efe884e73
3
+ metadata.gz: 2591ce2673e8253953b70b5cd03c115b0dec2e46
4
+ data.tar.gz: 9400f8228d373ef061e55b786093fee3dbd9ef68
5
5
  SHA512:
6
- metadata.gz: 5e0cc594e0ae450f060029e69f1d48578f3ee930435287765a00eadcf4b59a43fe5201f3522fdb058bf3118f71d20c26ed7ca2cadcc980897bbf1f0c4c4fe757
7
- data.tar.gz: 41706f9d007cfa4664f45dda42de257568eecd63af0e76c7b80435433f6cd77c7df7dcf91487a5b1e6811b193b6b762c5672a9ce3b2d8b34ca368e31bc75ee45
6
+ metadata.gz: 8c4c8b2d1becb8a718a96fe9ae38e1de50220590a13d0c7c6d402ab79e5f2663ab8f62f52970a50ff31f5dc896f1d22f25526c258447655ea6b24ad30a154f90
7
+ data.tar.gz: 4200cdfb63629d2eac2ea8fef9c1c10fe87b3f7a052f9bd8688afe973791ce65c86dfadc63b3154e260898277d2d902be35b0a98d5625bb77677f5ca1bdea6be
@@ -20,7 +20,7 @@ class LearnError < StandardError
20
20
 
21
21
  @valid_yaml = {message: "invalid yaml", color: :red}
22
22
  @valid_license = {message: "invalid or missing license content", color: :yellow}
23
- @valid_readme = {message: "invalid code snippet. Must have three backticks + optional language designator to open and close all code blocks. In-line code snippets must use one backtic", color: :red}
23
+ @valid_readme = {message: "", color: :red}
24
24
  @valid_contributing = {message: "invalid or missing contributing content", color: :yellow}
25
25
 
26
26
  @present_learn = {message: "missing .learn file", color: :red}
@@ -1,11 +1,13 @@
1
+ require 'english'
2
+
1
3
  class ReadmeLinter
2
4
 
3
5
  def self.parse_file(file, learn_error)
4
- file_string = File.open(file).read
5
- if has_code_snippets?(file_string)
6
- validate_snippets(file_string, learn_error)
6
+ if has_code_snippets?(file)
7
+ lines = collect_lines(file)
8
+ validate_snippets(lines, learn_error)
7
9
  else
8
- green_light(learn_error)
10
+ green_light(learn_error)
9
11
  end
10
12
  end
11
13
 
@@ -15,19 +17,35 @@ class ReadmeLinter
15
17
  end
16
18
 
17
19
  def self.has_code_snippets?(file)
18
- file.match(/``/)
20
+ file_content = File.open(file).read
21
+ file_content.match(/``/)
19
22
  end
20
23
 
21
- def self.validate_snippets(file, learn_error)
22
- file.split(" ").each do |chars|
23
- if chars.match(/``/)
24
- if !(chars.match(/^```(ruby|bash|swift|html|erb|js|javascript|objc|java|sql)?$/))
25
- break
26
- else
27
- green_light(learn_error)
24
+ def self.collect_lines(file)
25
+ lines = {}
26
+ File.foreach(file) do |line_content|
27
+ lines["#{$INPUT_LINE_NUMBER}"] = line_content
28
+ end
29
+ lines
30
+ end
31
+
32
+ def self.validate_snippets(lines, learn_error)
33
+ lines.each do |line_num, line_content|
34
+ if line_content.match(/``/)
35
+ if !(line_content.match(/^```(ruby|bash|swift|html|erb|js|javascript|objc|java|sql)?$/))
36
+ learn_error.valid_readme[:message] << "INVALID CODE SNIPPET - line #{line_num}: #{line_content}\n"
28
37
  end
29
38
  end
30
39
  end
40
+ total_errors?(learn_error)
41
+ end
42
+
43
+ def self.total_errors?(learn_error)
44
+ if !learn_error.valid_readme[:message].include?("INVALID CODE SNIPPET")
45
+ green_light(learn_error)
46
+ end
31
47
  end
32
48
  end
49
+
50
+
33
51
 
@@ -1,3 +1,3 @@
1
1
  class LearnLinter
2
- VERSION = "1.6.9"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: learn_linter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.9
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sophie DeBenedetto