slim_lint 0.23.0 → 0.25.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
  SHA256:
3
- metadata.gz: 4d873940ddc504e1c78dc4ec1c1c7140a51ebc308294cd8083d3bde7bf7ee814
4
- data.tar.gz: d284de951c7ebf98448cdc49fab0ca54fa5c9b9cc6f6e0c731359b73a0ba64fa
3
+ metadata.gz: 58c99ab50012a0f3475e6518e69bade743b55e6ed5eb4f5dd25a98ea1b7a617e
4
+ data.tar.gz: 4593348af814f4bce1bd240d4982eec2acd9d4c7bbda5f5ccc231a3a51b8c148
5
5
  SHA512:
6
- metadata.gz: 5147b5647239c39231529cc18cb397ac33fe1d6a07db58b33ddcda9924022e71cc24f3a4b7f91bf4795b668d031b8d65deb85dc5ee8869bca1237e18eb5af5a3
7
- data.tar.gz: 4afba73fe9d49dc124554b63bb230c1135c18288d377fb0ad9af098b418dec31d1524410c09dba6fb284fb1ab8e0742a06b04c97fdd850d04500e500d9ef57ac
6
+ metadata.gz: 53ea008e7e03d7261af22c33e098be489096299117b9ec103406382568af8b8b3c10e0a77a3e97e9848c88a57d04d2f5a6b7998b48555d7ea205ceb136f95cdb
7
+ data.tar.gz: 1e5e98f7d7e6eacc805a85451b8428f2f746b91b5b3433ce5262779d6bd9285b6db00e463c3d1b79912e9b93b677b5f12f0bf0e50613f284b8b482732fc7e552
data/bin/slim-lint CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  require 'slim_lint/cli'
5
5
 
6
- logger = SlimLint::Logger.new(STDOUT)
6
+ logger = SlimLint::Logger.new($stdout)
7
7
  exit SlimLint::CLI.new(logger).run(ARGV)
data/config/default.yml CHANGED
@@ -94,3 +94,6 @@ linters:
94
94
 
95
95
  TrailingWhitespace:
96
96
  enabled: true
97
+
98
+ Zwsp:
99
+ enabled: false
@@ -67,7 +67,7 @@ module SlimLint
67
67
  # Second capture match --- or ... followed by optional whitespace
68
68
  # and newline. This matches the closing --- for the frontmatter.
69
69
  (---|\.\.\.)\s*$\n?/mx
70
- source = $POSTMATCH
70
+ source = ::Regexp.last_match.post_match
71
71
  end
72
72
 
73
73
  source
@@ -72,7 +72,7 @@ module SlimLint
72
72
  # @param path [String]
73
73
  # @return [String]
74
74
  def normalize_path(path)
75
- path.start_with?(".#{File::SEPARATOR}") ? path[2..-1] : path
75
+ path.start_with?(".#{File::SEPARATOR}") ? path[2..] : path
76
76
  end
77
77
 
78
78
  # Whether the given file should be treated as a Slim file.
@@ -5,7 +5,7 @@ module SlimLint::Filters
5
5
  # variables and other cruft (which in the context of extracting Ruby code,
6
6
  # results in a lot of weird cops reported by RuboCop).
7
7
  class ControlProcessor < Slim::Filter
8
- BLOCK_RE = /\A(if|unless)\b|\bdo\s*(\|[^\|]*\|)?\s*$/
8
+ BLOCK_RE = /\A(if|unless)\b|\bdo\s*(\|[^|]*\|)?\s*$/
9
9
 
10
10
  # Handle control expression `[:slim, :control, code, content]`
11
11
  #
@@ -9,8 +9,14 @@ module SlimLint
9
9
 
10
10
  on [:html, :tag, anything, [],
11
11
  [:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
12
- # Fetch original Slim code that contains an element with a control statement.
13
- line = document.source_lines[sexp.line() - 1]
12
+ # Process original slim code so that multi-line attributes become single line.
13
+ # And store the correction line count
14
+ source = merge_multiline_attributes(document.source_lines)
15
+
16
+ # Fetch processed Slim code that contains an element with a control statement.
17
+ line = source[sexp.line - 1][:line]
18
+ # Apply correction to the line count.
19
+ sexp.line += source[sexp.line - 1][:line_count]
14
20
 
15
21
  # Remove any Ruby code, because our regexp below must not match inside Ruby.
16
22
  ruby = captures[:ruby]
@@ -20,5 +26,29 @@ module SlimLint
20
26
 
21
27
  report_lint(sexp, MESSAGE)
22
28
  end
29
+
30
+ private
31
+
32
+ def merge_multiline_attributes(source_lines)
33
+ result = []
34
+ memo = ''
35
+ correction_line_count = 0
36
+
37
+ source_lines.each do |line|
38
+ memo += line.chomp('\\')
39
+
40
+ # Lines ending in a backslash are concatenated with the next line
41
+ # And count the number of lines to correct the sexp line count.
42
+ if line.match?(/\\$/)
43
+ correction_line_count += 1
44
+ next
45
+ end
46
+
47
+ # Add merged rows and correction line count to the result and reset the memo
48
+ result << { line: memo, line_count: correction_line_count }
49
+ memo = ''
50
+ end
51
+ result
52
+ end
23
53
  end
24
54
  end
@@ -4,7 +4,7 @@ module SlimLint
4
4
  class Linter::Zwsp < Linter
5
5
  include LinterRegistry
6
6
 
7
- MSG = 'Remove Zwsp'
7
+ MSG = 'Remove zero-width space'
8
8
 
9
9
  on_start do |_sexp|
10
10
  dummy_node = Struct.new(:line)
@@ -71,7 +71,7 @@ module SlimLint
71
71
  def disabled_lines
72
72
  @disabled_lines ||= begin
73
73
  currently_disabled = false
74
- @document.source_lines.each_with_index.reduce([]) do |lines, pair|
74
+ @document.source_lines.each_with_index.each_with_object([]) do |pair, lines|
75
75
  line = pair[0]
76
76
  line_number = pair[1] + 1
77
77
 
@@ -82,7 +82,6 @@ module SlimLint
82
82
  elsif currently_disabled
83
83
  lines << line_number
84
84
  end
85
- lines
86
85
  end
87
86
  end
88
87
  end
@@ -27,11 +27,9 @@ module SlimLint
27
27
  # @return [Array<Class>]
28
28
  def extract_linters_from(linter_names)
29
29
  linter_names.map do |linter_name|
30
- begin
31
- SlimLint::Linter.const_get(linter_name)
32
- rescue NameError
33
- raise NoSuchLinter, "Linter #{linter_name} does not exist"
34
- end
30
+ SlimLint::Linter.const_get(linter_name)
31
+ rescue NameError
32
+ raise NoSuchLinter, "Linter #{linter_name} does not exist"
35
33
  end
36
34
  end
37
35
  end
@@ -87,7 +87,7 @@ module SlimLint
87
87
  def run_cli(task_args)
88
88
  cli_args = ['--config', config] if config
89
89
 
90
- logger = quiet ? SlimLint::Logger.silent : SlimLint::Logger.new(STDOUT)
90
+ logger = quiet ? SlimLint::Logger.silent : SlimLint::Logger.new($stdout)
91
91
  result = SlimLint::CLI.new(logger).run(Array(cli_args) + files_to_lint(task_args))
92
92
 
93
93
  fail "#{SlimLint::APP_NAME} failed with exit code #{result}" unless result == 0
@@ -98,7 +98,7 @@ module SlimLint
98
98
  #
99
99
  # @param task_args [Rake::TaskArguments]
100
100
  def files_to_lint(task_args)
101
- # Note: we're abusing Rake's argument handling a bit here. We call the
101
+ # NOTE: we're abusing Rake's argument handling a bit here. We call the
102
102
  # first argument `files` but it's actually only the first file--we pull
103
103
  # the rest out of the `extras` from the task arguments. This is so we
104
104
  # can specify an arbitrary list of files separated by commas on the
@@ -2,7 +2,14 @@
2
2
 
3
3
  require 'rubocop'
4
4
  require 'rubocop/ast/builder'
5
- require 'parser/current'
5
+
6
+ def require_parser(path)
7
+ prev = $VERBOSE
8
+ $VERBOSE = nil
9
+ require "parser/#{path}"
10
+ ensure
11
+ $VERBOSE = prev
12
+ end
6
13
 
7
14
  module SlimLint
8
15
  # Parser for the Ruby language.
@@ -13,6 +20,7 @@ module SlimLint
13
20
  class RubyParser
14
21
  # Creates a reusable parser.
15
22
  def initialize
23
+ require_parser('current')
16
24
  @builder = ::RuboCop::AST::Builder.new
17
25
  @parser = ::Parser::CurrentRuby.new(@builder)
18
26
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.23.0'
5
+ VERSION = '0.25.0'
6
6
  end
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.23.0
4
+ version: 0.25.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: 2023-01-27 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.78.0
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.78.0
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: slim
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,20 +50,6 @@ dependencies:
44
50
  - - "<"
45
51
  - !ruby/object:Gem::Version
46
52
  version: '6.0'
47
- - !ruby/object:Gem::Dependency
48
- name: pry
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.13'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '0.13'
61
53
  - !ruby/object:Gem::Dependency
62
54
  name: rspec
63
55
  requirement: !ruby/object:Gem::Requirement
@@ -165,14 +157,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
157
  requirements:
166
158
  - - ">="
167
159
  - !ruby/object:Gem::Version
168
- version: 2.4.0
160
+ version: '3.0'
169
161
  required_rubygems_version: !ruby/object:Gem::Requirement
170
162
  requirements:
171
163
  - - ">="
172
164
  - !ruby/object:Gem::Version
173
165
  version: '0'
174
166
  requirements: []
175
- rubygems_version: 3.1.6
167
+ rubygems_version: 3.0.3.1
176
168
  signing_key:
177
169
  specification_version: 4
178
170
  summary: Slim template linting tool