rails-erb-lint 1.1.6 → 1.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c755024ecaeaabf99ceb33b9c65c52c0ab3cda9
|
4
|
+
data.tar.gz: 71d266c0611a778fcc2367e699f3e9861cacdada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20df5b0a36e0b31c0b6276adccdab2e78394a976c4a78571114ef5ca5103cc0c1d42ec6bec7946c123097dbc9dcf0039df8b165b91de202df8d2debf61f4f6fe
|
7
|
+
data.tar.gz: 93d14018a063366b3d74c7941a91a40c92be52b89dbd4106c246f9c0a8f812f71b5cc93604c17e15a76a5d4f0b3f3d18e358b69e182d3bb2d90480154af16f95
|
@@ -1,13 +1,23 @@
|
|
1
1
|
require 'action_view'
|
2
2
|
|
3
3
|
module RailsErbCheck
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class Checker
|
5
|
+
attr_reader :error
|
6
|
+
|
7
|
+
def initialize(erb_path)
|
8
|
+
@erb = File.read(erb_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid_syntax?
|
12
|
+
begin
|
13
|
+
ActionView::Template::Handlers::Erubis.new(@erb).result
|
14
|
+
rescue SyntaxError => e
|
15
|
+
@error = e
|
16
|
+
return false
|
17
|
+
rescue Exception
|
18
|
+
return true
|
19
|
+
end
|
11
20
|
end
|
21
|
+
|
12
22
|
end
|
13
23
|
end
|
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
['action_view',
|
2
|
+
'find',
|
3
|
+
'gli',
|
4
|
+
'json',
|
5
|
+
'rainbow'].each do |d|
|
6
|
+
require d
|
7
|
+
end
|
5
8
|
|
6
9
|
require_relative '../helpers/rails_erb_check'
|
7
10
|
|
@@ -9,31 +12,91 @@ include GLI::App
|
|
9
12
|
|
10
13
|
program_desc 'A simple lint tool for ERB Rails views.'
|
11
14
|
|
15
|
+
def get_erb_list(path)
|
16
|
+
erb_files = []
|
17
|
+
|
18
|
+
Find.find(path.to_s) do |f|
|
19
|
+
next if FileTest.directory?(f)
|
20
|
+
if /.*\.erb/.match(File.basename(f))
|
21
|
+
erb_files << f
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
erb_files
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_files(erbs, options)
|
29
|
+
files = {}
|
30
|
+
|
31
|
+
erbs.each do |f|
|
32
|
+
checker = RailsErbCheck::Checker.new(f)
|
33
|
+
|
34
|
+
if checker.valid_syntax?
|
35
|
+
puts Rainbow("#{f} => valid").green if options[:valid]
|
36
|
+
files[f] = { invalid: false }
|
37
|
+
else
|
38
|
+
puts Rainbow("#{f} => invalid").red
|
39
|
+
puts checker.error.message if options[:error]
|
40
|
+
files[f] = {
|
41
|
+
invalid: true,
|
42
|
+
error: checker.error.message,
|
43
|
+
backtrace: checker.error.backtrace
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
files
|
49
|
+
end
|
50
|
+
|
51
|
+
def export_json(hash, path)
|
52
|
+
File.open(path, 'w') do |file|
|
53
|
+
JSON.dump(hash, file)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
12
57
|
desc 'Check for syntax errors on views'
|
13
58
|
command :check do |c|
|
14
|
-
c.switch :
|
15
|
-
|
16
|
-
valid
|
17
|
-
invalid
|
18
|
-
|
59
|
+
c.switch [:v, :valid], {
|
60
|
+
default_value: false,
|
61
|
+
arg_name: 'valid',
|
62
|
+
desc: 'print valid files along with invalid files'
|
63
|
+
}
|
64
|
+
|
65
|
+
c.switch [:e, :error], {
|
66
|
+
default_value: false,
|
67
|
+
arg_name: 'error',
|
68
|
+
desc: 'print errors associated with invalid files'
|
69
|
+
}
|
19
70
|
|
20
|
-
|
71
|
+
c.flag [:j, :json], {
|
72
|
+
default_value: nil,
|
73
|
+
arg_name: 'json-file',
|
74
|
+
type: String,
|
75
|
+
desc: 'Export a json file with results, also exports valid files when coupled with -v'
|
76
|
+
}
|
77
|
+
|
78
|
+
c.flag [:p, :path], {
|
79
|
+
default_value: Dir.getwd,
|
80
|
+
arg_name: 'path',
|
81
|
+
type: String,
|
82
|
+
desc: 'specify the path that should be used as the root of the check'
|
83
|
+
}
|
84
|
+
|
85
|
+
c.action do |global_options, options|
|
86
|
+
path = options[:path]
|
21
87
|
puts Rainbow("Checking for files in current directory: #{path}").green
|
22
88
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
89
|
+
erbs = get_erb_list(path)
|
90
|
+
files = check_files(erbs, options)
|
91
|
+
|
92
|
+
valid = files.reject { |file, info| info[:invalid] }
|
93
|
+
invalid = files.select { |file, info| info[:invalid] }
|
29
94
|
|
30
|
-
|
31
|
-
if
|
32
|
-
|
33
|
-
valid << f
|
95
|
+
if options[:json]
|
96
|
+
if options[:valid]
|
97
|
+
export_json(files, options[:json])
|
34
98
|
else
|
35
|
-
|
36
|
-
invalid << f
|
99
|
+
export_json(invalid, options[:json])
|
37
100
|
end
|
38
101
|
end
|
39
102
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-erb-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katherine Pe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '4.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: builder
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|