slim_lint 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/slim_lint/cli.rb +20 -5
- data/lib/slim_lint/document.rb +10 -1
- data/lib/slim_lint/engine.rb +11 -1
- data/lib/slim_lint/exceptions.rb +3 -0
- data/lib/slim_lint/logger.rb +5 -7
- data/lib/slim_lint/options.rb +4 -0
- data/lib/slim_lint/rake_task.rb +1 -0
- data/lib/slim_lint/ruby_extractor.rb +1 -0
- data/lib/slim_lint/runner.rb +2 -2
- data/lib/slim_lint/utils.rb +2 -0
- data/lib/slim_lint/version.rb +1 -1
- data/lib/slim_lint.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c2a57fa0d9dc24917ca85379e01546e917ec092
|
4
|
+
data.tar.gz: 13144b73104ca05aa05e0d23bef2ed71b9130529
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe1ff6f1c59b1b97cff345874117a89851ccda90bd71fbace6d4f6663d4a71b316780d34a59e3ef5fb564e59d249edb4ebaad26c14808c9a15ffcfb31a9ac55f
|
7
|
+
data.tar.gz: 1827561fb1b2107d2006ec8105f969d740e5486a7cfdc1366182fb02595d98329d5fb54046636e0cb5eb25d16308a155f7d24593166e1cab37c9c446fc9eb273
|
data/lib/slim_lint/cli.rb
CHANGED
@@ -5,7 +5,7 @@ require 'sysexits'
|
|
5
5
|
|
6
6
|
module SlimLint
|
7
7
|
# Command line application interface.
|
8
|
-
class CLI
|
8
|
+
class CLI # rubocop:disable Metrics/ClassLength
|
9
9
|
# Create a CLI that outputs to the specified logger.
|
10
10
|
#
|
11
11
|
# @param logger [SlimLint::Logger]
|
@@ -38,8 +38,8 @@ module SlimLint
|
|
38
38
|
if options[:help]
|
39
39
|
print_help(options)
|
40
40
|
Sysexits::EX_OK
|
41
|
-
elsif options[:version]
|
42
|
-
print_version
|
41
|
+
elsif options[:version] || options[:verbose_version]
|
42
|
+
print_version(options)
|
43
43
|
Sysexits::EX_OK
|
44
44
|
elsif options[:show_linters]
|
45
45
|
print_available_linters
|
@@ -123,17 +123,32 @@ module SlimLint
|
|
123
123
|
end
|
124
124
|
|
125
125
|
# Outputs the application name and version.
|
126
|
-
def print_version
|
126
|
+
def print_version(options)
|
127
127
|
log.log "#{SlimLint::APP_NAME} #{SlimLint::VERSION}"
|
128
|
+
|
129
|
+
if options[:verbose_version]
|
130
|
+
log.log "slim #{Gem.loaded_specs['slim'].version}"
|
131
|
+
log.log "rubocop #{Gem.loaded_specs['rubocop'].version}"
|
132
|
+
log.log RUBY_DESCRIPTION
|
133
|
+
end
|
128
134
|
end
|
129
135
|
|
130
136
|
# Outputs the backtrace of an exception with instructions on how to report
|
131
137
|
# the issue.
|
132
|
-
def print_unexpected_exception(ex)
|
138
|
+
def print_unexpected_exception(ex) # rubocop:disable Metrics/AbcSize
|
133
139
|
log.bold_error ex.message
|
134
140
|
log.error ex.backtrace.join("\n")
|
135
141
|
log.warning 'Report this bug at ', false
|
136
142
|
log.info SlimLint::BUG_REPORT_URL
|
143
|
+
log.newline
|
144
|
+
log.success 'To help fix this issue, please include:'
|
145
|
+
log.log '- The above stack trace'
|
146
|
+
log.log '- Slim-Lint version: ', false
|
147
|
+
log.info SlimLint::VERSION
|
148
|
+
log.log '- RuboCop version: ', false
|
149
|
+
log.info Gem.loaded_specs['rubocop'].version
|
150
|
+
log.log '- Ruby version: ', false
|
151
|
+
log.info RUBY_VERSION
|
137
152
|
end
|
138
153
|
end
|
139
154
|
end
|
data/lib/slim_lint/document.rb
CHANGED
@@ -35,8 +35,9 @@ module SlimLint
|
|
35
35
|
private
|
36
36
|
|
37
37
|
# @param source [String] Slim code to parse
|
38
|
-
# @raise [
|
38
|
+
# @raise [SlimLint::Exceptions::ParseError] if there was a problem parsing the document
|
39
39
|
def process_source(source)
|
40
|
+
@source = process_encoding(source)
|
40
41
|
@source = strip_frontmatter(source)
|
41
42
|
@source_lines = @source.split("\n")
|
42
43
|
|
@@ -44,6 +45,14 @@ module SlimLint
|
|
44
45
|
@sexp = engine.parse(source)
|
45
46
|
end
|
46
47
|
|
48
|
+
# Ensure the string's encoding is valid.
|
49
|
+
#
|
50
|
+
# @param source [String]
|
51
|
+
# @return [String] source encoded in a valid encoding
|
52
|
+
def process_encoding(source)
|
53
|
+
::Temple::Filters::Encoding.new.call(source)
|
54
|
+
end
|
55
|
+
|
47
56
|
# Removes YAML frontmatter
|
48
57
|
def strip_frontmatter(source)
|
49
58
|
if config['skip_frontmatter'] &&
|
data/lib/slim_lint/engine.rb
CHANGED
@@ -28,6 +28,16 @@ module SlimLint
|
|
28
28
|
#
|
29
29
|
# @param source [String] source code to parse
|
30
30
|
# @return [SlimLint::Sexp] parsed Sexp
|
31
|
-
|
31
|
+
def parse(source)
|
32
|
+
call(source)
|
33
|
+
rescue ::Slim::Parser::SyntaxError => ex
|
34
|
+
# Convert to our own exception type to isolate from upstream changes
|
35
|
+
error = SlimLint::Exceptions::ParseError.new(ex.error,
|
36
|
+
ex.file,
|
37
|
+
ex.line,
|
38
|
+
ex.lineno,
|
39
|
+
ex.column)
|
40
|
+
raise error
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
data/lib/slim_lint/exceptions.rb
CHANGED
@@ -9,6 +9,9 @@ module SlimLint::Exceptions
|
|
9
9
|
# Raised when an invalid file path is specified
|
10
10
|
class InvalidFilePath < StandardError; end
|
11
11
|
|
12
|
+
# Raised when the Slim parser is unable to parse a template.
|
13
|
+
class ParseError < ::Slim::Parser::SyntaxError; end
|
14
|
+
|
12
15
|
# Raised when attempting to execute `Runner` with options that would result in
|
13
16
|
# no linters being enabled.
|
14
17
|
class NoLintersError < StandardError; end
|
data/lib/slim_lint/logger.rb
CHANGED
@@ -22,7 +22,6 @@ module SlimLint
|
|
22
22
|
#
|
23
23
|
# @param output [String] the output to send
|
24
24
|
# @param newline [true,false] whether to append a newline
|
25
|
-
# @return [nil]
|
26
25
|
def log(output, newline = true)
|
27
26
|
@out.print(output)
|
28
27
|
@out.print("\n") if newline
|
@@ -32,7 +31,6 @@ module SlimLint
|
|
32
31
|
# If output destination is not a TTY, behaves the same as {#log}.
|
33
32
|
#
|
34
33
|
# @param args [Array<String>]
|
35
|
-
# @return [nil]
|
36
34
|
def bold(*args)
|
37
35
|
color('1', *args)
|
38
36
|
end
|
@@ -41,7 +39,6 @@ module SlimLint
|
|
41
39
|
# If output destination is not a TTY, behaves the same as {#log}.
|
42
40
|
#
|
43
41
|
# @param args [Array<String>]
|
44
|
-
# @return [nil]
|
45
42
|
def error(*args)
|
46
43
|
color(31, *args)
|
47
44
|
end
|
@@ -50,7 +47,6 @@ module SlimLint
|
|
50
47
|
# If output destination is not a TTY, behaves the same as {#log}.
|
51
48
|
#
|
52
49
|
# @param args [Array<String>]
|
53
|
-
# @return [nil]
|
54
50
|
def bold_error(*args)
|
55
51
|
color('1;31', *args)
|
56
52
|
end
|
@@ -59,7 +55,6 @@ module SlimLint
|
|
59
55
|
# If output destination is not a TTY, behaves the same as {#log}.
|
60
56
|
#
|
61
57
|
# @param args [Array<String>]
|
62
|
-
# @return [nil]
|
63
58
|
def success(*args)
|
64
59
|
color(32, *args)
|
65
60
|
end
|
@@ -68,7 +63,6 @@ module SlimLint
|
|
68
63
|
# If output destination is not a TTY, behaves the same as {#log}.
|
69
64
|
#
|
70
65
|
# @param args [Array<String>]
|
71
|
-
# @return [nil]
|
72
66
|
def warning(*args)
|
73
67
|
color(33, *args)
|
74
68
|
end
|
@@ -77,11 +71,15 @@ module SlimLint
|
|
77
71
|
# If output destination is not a TTY, behaves the same as {#log}.
|
78
72
|
#
|
79
73
|
# @param args [Array<String>]
|
80
|
-
# @return [nil]
|
81
74
|
def info(*args)
|
82
75
|
color(36, *args)
|
83
76
|
end
|
84
77
|
|
78
|
+
# Print a blank line.
|
79
|
+
def newline
|
80
|
+
log('')
|
81
|
+
end
|
82
|
+
|
85
83
|
# Whether this logger is outputting to a TTY.
|
86
84
|
#
|
87
85
|
# @return [true,false]
|
data/lib/slim_lint/options.rb
CHANGED
@@ -94,6 +94,10 @@ module SlimLint
|
|
94
94
|
parser.on_tail('-v', '--version', 'Display version') do
|
95
95
|
@options[:version] = true
|
96
96
|
end
|
97
|
+
|
98
|
+
parser.on_tail('-V', '--verbose-version', 'Display verbose version information') do
|
99
|
+
@options[:verbose_version] = true
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
data/lib/slim_lint/rake_task.rb
CHANGED
@@ -41,6 +41,7 @@ module SlimLint
|
|
41
41
|
# Extracts Ruby code from Sexp representing a Slim document.
|
42
42
|
#
|
43
43
|
# @param sexp [SlimLint::Sexp]
|
44
|
+
# @return [SlimLint::RubyExtractor::RubySource]
|
44
45
|
def extract(sexp)
|
45
46
|
trigger_pattern_callbacks(sexp)
|
46
47
|
RubySource.new(@source_lines.join("\n"), @source_map)
|
data/lib/slim_lint/runner.rb
CHANGED
@@ -50,8 +50,8 @@ module SlimLint
|
|
50
50
|
def collect_lints(file, linter_selector, config)
|
51
51
|
begin
|
52
52
|
document = SlimLint::Document.new(File.read(file), file: file, config: config)
|
53
|
-
rescue
|
54
|
-
return [SlimLint::Lint.new(nil, file, ex.
|
53
|
+
rescue SlimLint::Exceptions::ParseError => ex
|
54
|
+
return [SlimLint::Lint.new(nil, file, ex.lineno, ex.error, :error)]
|
55
55
|
end
|
56
56
|
|
57
57
|
linter_selector.linters_for_file(file).map do |linter|
|
data/lib/slim_lint/utils.rb
CHANGED
@@ -65,6 +65,8 @@ module SlimLint
|
|
65
65
|
|
66
66
|
# Calls a block of code with a modified set of environment variables,
|
67
67
|
# restoring them once the code has executed.
|
68
|
+
#
|
69
|
+
# @param env [Hash] environment variables to set
|
68
70
|
def with_environment(env)
|
69
71
|
old_env = {}
|
70
72
|
env.each do |var, value|
|
data/lib/slim_lint/version.rb
CHANGED
data/lib/slim_lint.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Load all slim-lint modules necessary to parse and lint a file.
|
2
2
|
# Ordering here can be important depending on class references in each module.
|
3
3
|
|
4
|
+
# Need to load slim before we can reference some classes or define filters
|
5
|
+
require 'slim'
|
6
|
+
|
4
7
|
require 'slim_lint/constants'
|
5
8
|
require 'slim_lint/exceptions'
|
6
9
|
require 'slim_lint/configuration'
|
@@ -13,9 +16,6 @@ require 'slim_lint/linter_registry'
|
|
13
16
|
require 'slim_lint/logger'
|
14
17
|
require 'slim_lint/version'
|
15
18
|
|
16
|
-
# Need to load slim before we can define filters
|
17
|
-
require 'slim'
|
18
|
-
|
19
19
|
# Load all filters (required by SlimLint::Engine)
|
20
20
|
Dir[File.expand_path('slim_lint/filters/*.rb', File.dirname(__FILE__))].each do |file|
|
21
21
|
require file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slim_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slim
|
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 2.0.0
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.4.
|
160
|
+
rubygems_version: 2.4.8
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: Slim template linting tool
|