slim_lint 0.20.2 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +4 -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 +12 -8
- data/lib/slim_lint/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb7c8e4610ab75806023562750e2ef68bfd0b9457403297a22773af85951935
|
4
|
+
data.tar.gz: ad04da9dd32582ab42c290c85628f391e88a4f8a1eae83ef4d6ad3695d88f1bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecda5be7f9b2adf7fd5e06d78449df876037953b34a07c658bf999b13af8d4d322afbc4779ac62654e9887c8d9b6621ce224b215871c842cb9fe25c92eb2e769
|
7
|
+
data.tar.gz: bfd2cfa1794ff5406ac546f66013985cc809ec4c5136d04d6a99e12994e7c4e0ea2876f69067239b6e9aa3f6c2ea96031d1ce4e882bd099b2efdb6531b2786ba
|
data/config/default.yml
CHANGED
@@ -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
60
|
return [SlimLint::Lint.new(nil, file, 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.21.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-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/slim_lint/linter/comment_control_statement.rb
|
105
105
|
- lib/slim_lint/linter/consecutive_control_statements.rb
|
106
106
|
- lib/slim_lint/linter/control_statement_spacing.rb
|
107
|
+
- lib/slim_lint/linter/embedded_engines.rb
|
107
108
|
- lib/slim_lint/linter/empty_control_statement.rb
|
108
109
|
- lib/slim_lint/linter/empty_lines.rb
|
109
110
|
- lib/slim_lint/linter/file_length.rb
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- lib/slim_lint/reporter.rb
|
128
129
|
- lib/slim_lint/reporter/checkstyle_reporter.rb
|
129
130
|
- lib/slim_lint/reporter/default_reporter.rb
|
131
|
+
- lib/slim_lint/reporter/emacs_reporter.rb
|
130
132
|
- lib/slim_lint/reporter/json_reporter.rb
|
131
133
|
- lib/slim_lint/ruby_extract_engine.rb
|
132
134
|
- lib/slim_lint/ruby_extractor.rb
|
@@ -140,7 +142,7 @@ homepage: https://github.com/sds/slim-lint
|
|
140
142
|
licenses:
|
141
143
|
- MIT
|
142
144
|
metadata: {}
|
143
|
-
post_install_message:
|
145
|
+
post_install_message:
|
144
146
|
rdoc_options: []
|
145
147
|
require_paths:
|
146
148
|
- lib
|
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
158
|
version: '0'
|
157
159
|
requirements: []
|
158
160
|
rubygems_version: 3.1.4
|
159
|
-
signing_key:
|
161
|
+
signing_key:
|
160
162
|
specification_version: 4
|
161
163
|
summary: Slim template linting tool
|
162
164
|
test_files: []
|