slim_lint 0.20.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/default.yml +7 -0
- data/lib/slim_lint/linter.rb +29 -0
- data/lib/slim_lint/linter/embedded_engines.rb +22 -0
- data/lib/slim_lint/options.rb +5 -0
- data/lib/slim_lint/reporter/emacs_reporter.rb +44 -0
- data/lib/slim_lint/reporter/json_reporter.rb +1 -0
- data/lib/slim_lint/runner.rb +13 -9
- data/lib/slim_lint/version.rb +1 -1
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7405eb29d09bb96a9c1f50007d6734f69a2abfea213bddbd9cadd15e7ac99651
|
4
|
+
data.tar.gz: 1e55ce9b3466a9232a52a8a70ff7d4c8b31584f7bf06805d18c6965887935210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a163d473bb03269ecd4a648c992219e2e26b2bd06948d8bf7b660b54d6eceb9d2c4b675c807676c1aa1122d40a4929d125bdc587b956660dcde0b8b1cc9f3f95
|
7
|
+
data.tar.gz: 04405a47e956df8d2be5ea0520e411ddfc3da5f0c2bf498649d0d8268d1fe97cadf96384875975836e72454bc8c0157c5b1da52e631194d5c15fd69bacc89484
|
data/config/default.yml
CHANGED
@@ -18,6 +18,10 @@ linters:
|
|
18
18
|
ControlStatementSpacing:
|
19
19
|
enabled: true
|
20
20
|
|
21
|
+
EmbeddedEngines:
|
22
|
+
enabled: false
|
23
|
+
forbidden_engines: []
|
24
|
+
|
21
25
|
EmptyControlStatement:
|
22
26
|
enabled: true
|
23
27
|
|
@@ -47,12 +51,14 @@ linters:
|
|
47
51
|
- Layout/BlockAlignment
|
48
52
|
- Layout/EmptyLineAfterGuardClause
|
49
53
|
- Layout/EndAlignment
|
54
|
+
- Layout/FirstArgumentIndentation
|
50
55
|
- Layout/FirstArrayElementIndentation
|
51
56
|
- Layout/FirstParameterIndentation
|
52
57
|
- Layout/HashAlignment
|
53
58
|
- Layout/IndentationConsistency
|
54
59
|
- Layout/IndentationWidth
|
55
60
|
- Layout/InitialIndentation
|
61
|
+
- Layout/LineEndStringConcatenationIndentation
|
56
62
|
- Layout/LineLength
|
57
63
|
- Layout/MultilineArrayBraceLayout
|
58
64
|
- Layout/MultilineAssignmentLayout
|
@@ -72,6 +78,7 @@ linters:
|
|
72
78
|
- Style/IdenticalConditionalBranches
|
73
79
|
- Style/IfUnlessModifier
|
74
80
|
- Style/Next
|
81
|
+
- Style/WhileUntilDo
|
75
82
|
- Style/WhileUntilModifier
|
76
83
|
|
77
84
|
Tab:
|
data/lib/slim_lint/linter.rb
CHANGED
@@ -49,6 +49,8 @@ module SlimLint
|
|
49
49
|
# @param node [#line] node to extract the line number from
|
50
50
|
# @param message [String] error/warning to display to the user
|
51
51
|
def report_lint(node, message)
|
52
|
+
return if disabled_for_line?(node.line)
|
53
|
+
|
52
54
|
@lints << SlimLint::Lint.new(self, @document.file, node.line, message)
|
53
55
|
end
|
54
56
|
|
@@ -60,5 +62,32 @@ module SlimLint
|
|
60
62
|
@ruby_parser ||= SlimLint::RubyParser.new
|
61
63
|
@ruby_parser.parse(source)
|
62
64
|
end
|
65
|
+
|
66
|
+
def disabled_for_line?(line)
|
67
|
+
disabled_lines.include?(line)
|
68
|
+
end
|
69
|
+
|
70
|
+
def disabled_lines
|
71
|
+
@disabled_lines ||= begin
|
72
|
+
currently_disabled = false
|
73
|
+
@document.source_lines.each_with_index.reduce([]) do |lines, pair|
|
74
|
+
line = pair[0]
|
75
|
+
line_number = pair[1] + 1
|
76
|
+
|
77
|
+
if line =~ %r{/ slim-lint:disable #{linter_name}}
|
78
|
+
currently_disabled = true
|
79
|
+
elsif line =~ %r{/ slim-lint:enable #{linter_name}}
|
80
|
+
currently_disabled = false
|
81
|
+
elsif currently_disabled
|
82
|
+
lines << line_number
|
83
|
+
end
|
84
|
+
lines
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def linter_name
|
90
|
+
@linter_name ||= self.class.name.split('::').last
|
91
|
+
end
|
63
92
|
end
|
64
93
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlimLint
|
4
|
+
# Checks for forbidden embedded engines.
|
5
|
+
class Linter::EmbeddedEngines < Linter
|
6
|
+
include LinterRegistry
|
7
|
+
|
8
|
+
MESSAGE = 'Forbidden embedded engine `%s` found'
|
9
|
+
|
10
|
+
on_start do |_sexp|
|
11
|
+
forbidden_engines = config['forbidden_engines']
|
12
|
+
dummy_node = Struct.new(:line)
|
13
|
+
document.source_lines.each_with_index do |line, index|
|
14
|
+
forbidden_engines.each do |forbidden_engine|
|
15
|
+
next unless line =~ /^#{forbidden_engine}.*:\s*$/
|
16
|
+
|
17
|
+
report_lint(dummy_node.new(index + 1), MESSAGE % forbidden_engine)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/slim_lint/options.rb
CHANGED
@@ -73,6 +73,11 @@ module SlimLint
|
|
73
73
|
'List of file names to exclude') do |files|
|
74
74
|
@options[:excluded_files] = files
|
75
75
|
end
|
76
|
+
|
77
|
+
parser.on('--stdin-file-path file', String,
|
78
|
+
'Pipe source from STDIN, using file in offense reports.') do |file|
|
79
|
+
@options[:stdin_file_path] = file
|
80
|
+
end
|
76
81
|
end
|
77
82
|
|
78
83
|
# Register informational flags.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlimLint
|
4
|
+
# Outputs lints in format: {filename}:{line}:{column}: {kind}: {message}.
|
5
|
+
class Reporter::EmacsReporter < Reporter
|
6
|
+
def display_report(report)
|
7
|
+
sorted_lints = report.lints.sort_by { |l| [l.filename, l.line] }
|
8
|
+
|
9
|
+
sorted_lints.each do |lint|
|
10
|
+
print_location(lint)
|
11
|
+
print_type(lint)
|
12
|
+
print_message(lint)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def print_location(lint)
|
19
|
+
log.info lint.filename, false
|
20
|
+
log.log ':', false
|
21
|
+
log.bold lint.line, false
|
22
|
+
log.log ':', false
|
23
|
+
# TODO: change 1 to column number when linter will have this info.
|
24
|
+
log.bold 1, false
|
25
|
+
log.log ':', false
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_type(lint)
|
29
|
+
if lint.error?
|
30
|
+
log.error ' E: ', false
|
31
|
+
else
|
32
|
+
log.warning ' W: ', false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_message(lint)
|
37
|
+
if lint.linter
|
38
|
+
log.success("#{lint.linter.name}: ", false)
|
39
|
+
end
|
40
|
+
|
41
|
+
log.log lint.message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/slim_lint/runner.rb
CHANGED
@@ -15,13 +15,17 @@ module SlimLint
|
|
15
15
|
# @return [SlimLint::Report] a summary of all lints found
|
16
16
|
def run(options = {})
|
17
17
|
config = load_applicable_config(options)
|
18
|
-
files = extract_applicable_files(config, options)
|
19
|
-
|
20
18
|
linter_selector = SlimLint::LinterSelector.new(config, options)
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
if options[:stdin_file_path].nil?
|
21
|
+
files = extract_applicable_files(config, options)
|
22
|
+
lints = files.map do |file|
|
23
|
+
collect_lints(File.read(file), file, linter_selector, config)
|
24
|
+
end.flatten
|
25
|
+
else
|
26
|
+
files = [options[:stdin_file_path]]
|
27
|
+
lints = collect_lints($stdin.read, options[:stdin_file_path], linter_selector, config)
|
28
|
+
end
|
25
29
|
|
26
30
|
SlimLint::Report.new(lints, files)
|
27
31
|
end
|
@@ -49,14 +53,14 @@ module SlimLint
|
|
49
53
|
# @param file [String] path to file to lint
|
50
54
|
# @param linter_selector [SlimLint::LinterSelector]
|
51
55
|
# @param config [SlimLint::Configuration]
|
52
|
-
def collect_lints(
|
56
|
+
def collect_lints(file_content, file_name, linter_selector, config)
|
53
57
|
begin
|
54
|
-
document = SlimLint::Document.new(
|
58
|
+
document = SlimLint::Document.new(file_content, file: file_name, config: config)
|
55
59
|
rescue SlimLint::Exceptions::ParseError => e
|
56
|
-
return [SlimLint::Lint.new(nil,
|
60
|
+
return [SlimLint::Lint.new(nil, file_name, e.lineno, e.error, :error)]
|
57
61
|
end
|
58
62
|
|
59
|
-
linter_selector.linters_for_file(
|
63
|
+
linter_selector.linters_for_file(file_name).map do |linter|
|
60
64
|
linter.run(document)
|
61
65
|
end.flatten
|
62
66
|
end
|
data/lib/slim_lint/version.rb
CHANGED
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.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.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'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rspec
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,6 +118,7 @@ files:
|
|
104
118
|
- lib/slim_lint/linter/comment_control_statement.rb
|
105
119
|
- lib/slim_lint/linter/consecutive_control_statements.rb
|
106
120
|
- lib/slim_lint/linter/control_statement_spacing.rb
|
121
|
+
- lib/slim_lint/linter/embedded_engines.rb
|
107
122
|
- lib/slim_lint/linter/empty_control_statement.rb
|
108
123
|
- lib/slim_lint/linter/empty_lines.rb
|
109
124
|
- lib/slim_lint/linter/file_length.rb
|
@@ -127,6 +142,7 @@ files:
|
|
127
142
|
- lib/slim_lint/reporter.rb
|
128
143
|
- lib/slim_lint/reporter/checkstyle_reporter.rb
|
129
144
|
- lib/slim_lint/reporter/default_reporter.rb
|
145
|
+
- lib/slim_lint/reporter/emacs_reporter.rb
|
130
146
|
- lib/slim_lint/reporter/json_reporter.rb
|
131
147
|
- lib/slim_lint/ruby_extract_engine.rb
|
132
148
|
- lib/slim_lint/ruby_extractor.rb
|
@@ -140,7 +156,7 @@ homepage: https://github.com/sds/slim-lint
|
|
140
156
|
licenses:
|
141
157
|
- MIT
|
142
158
|
metadata: {}
|
143
|
-
post_install_message:
|
159
|
+
post_install_message:
|
144
160
|
rdoc_options: []
|
145
161
|
require_paths:
|
146
162
|
- lib
|
@@ -155,8 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
171
|
- !ruby/object:Gem::Version
|
156
172
|
version: '0'
|
157
173
|
requirements: []
|
158
|
-
rubygems_version: 3.1.
|
159
|
-
signing_key:
|
174
|
+
rubygems_version: 3.1.4
|
175
|
+
signing_key:
|
160
176
|
specification_version: 4
|
161
177
|
summary: Slim template linting tool
|
162
178
|
test_files: []
|