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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12e6f287dec219087741642a7082ebb184b9ae49c658a69786eceb773f084ea5
4
- data.tar.gz: 3b078c22d76cea859645319017edcaa0e7ddaf160566057d3fb2656130ba2605
3
+ metadata.gz: ecb7c8e4610ab75806023562750e2ef68bfd0b9457403297a22773af85951935
4
+ data.tar.gz: ad04da9dd32582ab42c290c85628f391e88a4f8a1eae83ef4d6ad3695d88f1bb
5
5
  SHA512:
6
- metadata.gz: e952c0d0b0ceecad1762c3c3dd5d0d86a3954fdcb38978bf6b38c216a2b153cf2491d5823b84441bf56a23b983410b91b6ae6dfaecc147b90c874e02179a3363
7
- data.tar.gz: b80f20753aed88a9b0a8a7dfc8caa5e003a7915018fba1a0b0d12a2edb565c2bc0be559306ba427d6376bbd5aa1a342ce407ffe199fb3380d39f11249c0c9e14
6
+ metadata.gz: ecda5be7f9b2adf7fd5e06d78449df876037953b34a07c658bf999b13af8d4d322afbc4779ac62654e9887c8d9b6621ce224b215871c842cb9fe25c92eb2e769
7
+ data.tar.gz: bfd2cfa1794ff5406ac546f66013985cc809ec4c5136d04d6a99e12994e7c4e0ea2876f69067239b6e9aa3f6c2ea96031d1ce4e882bd099b2efdb6531b2786ba
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
 
@@ -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
@@ -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
@@ -45,6 +45,7 @@ module SlimLint
45
45
  location: {
46
46
  line: offense.line,
47
47
  },
48
+ linter: offense.linter&.name,
48
49
  }
49
50
  end
50
51
  end
@@ -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
- lints = files.map do |file|
23
- collect_lints(file, linter_selector, config)
24
- end.flatten
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(file, linter_selector, config)
56
+ def collect_lints(file_content, file_name, linter_selector, config)
53
57
  begin
54
- document = SlimLint::Document.new(File.read(file), file: file, config: config)
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(file).map do |linter|
63
+ linter_selector.linters_for_file(file_name).map do |linter|
60
64
  linter.run(document)
61
65
  end.flatten
62
66
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.20.2'
5
+ VERSION = '0.21.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.20.2
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: 2020-10-13 00:00:00.000000000 Z
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: []