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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6369991d47446420b433e59002ca420cb12ffec
4
- data.tar.gz: a6c4a34cffad4c9e8c3296e28c08b47ae558acdf
3
+ metadata.gz: 8c2a57fa0d9dc24917ca85379e01546e917ec092
4
+ data.tar.gz: 13144b73104ca05aa05e0d23bef2ed71b9130529
5
5
  SHA512:
6
- metadata.gz: 87d930b8e8514e0233e94ba2ace9c2d8fb338429f6d3846f566b95a54daceadb0a6840d5af893dd6e885d0af254bf17ace8033704e9adb609612d862effeb12e
7
- data.tar.gz: c29bebcc2db97f8908130338ad4922af655646a7eed40c36b9019b56e427a7b6a324daf468ff6a2acb3b9777294e157700e48b620538898a88303ee11eb9f5fc
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
@@ -35,8 +35,9 @@ module SlimLint
35
35
  private
36
36
 
37
37
  # @param source [String] Slim code to parse
38
- # @raise [Slim::Parser::Error] if there was a problem parsing the document
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'] &&
@@ -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
- alias_method :parse, :call
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
@@ -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
@@ -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]
@@ -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
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
+ require 'slim_lint/constants'
3
4
 
4
5
  module SlimLint
5
6
  # Rake task interface for slim-lint command line interface.
@@ -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)
@@ -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 Slim::Parser::SyntaxError => ex
54
- return [SlimLint::Lint.new(nil, file, ex.line, ex.error, :error)]
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|
@@ -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|
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SlimLint
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
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.5.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-05-31 00:00:00.000000000 Z
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: 1.9.3
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.5
160
+ rubygems_version: 2.4.8
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Slim template linting tool