slim_lint 0.18.0 → 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: 986eec7f82b19dc099ffdc1b39569f7dfde2eb01243dbcebe7ad13d36366a566
4
- data.tar.gz: 1543d58c24572178d4bd0cfe025a350619fb9fd1a3a0407efa79b1b9ed830d1f
3
+ metadata.gz: ecb7c8e4610ab75806023562750e2ef68bfd0b9457403297a22773af85951935
4
+ data.tar.gz: ad04da9dd32582ab42c290c85628f391e88a4f8a1eae83ef4d6ad3695d88f1bb
5
5
  SHA512:
6
- metadata.gz: 82d91f68c230e4e5af4a6b6c3d439dc06816fdce4e258e890bfedbcb2682b8987ee7eed1c41b6b2c0fda63370f25675152d0d4ac0a55287d2706b3b24af55b77
7
- data.tar.gz: c4c07a3f6623fba5162b1e9f9bcbf358b6dbc37e500916980289c3022f0627a41da8268406b90d4fb2d768324729d0129c1afd1a8d40990572d2fe87a799422b
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
 
@@ -42,16 +46,18 @@ linters:
42
46
  # WARNING: If you define this list in your own .slim-lint.yml file, you'll
43
47
  # be overriding the list defined here.
44
48
  ignored_cops:
45
- - Layout/AlignArguments
46
- - Layout/AlignArray
47
- - Layout/AlignHash
48
- - Layout/AlignParameters
49
+ - Layout/ArgumentAlignment
50
+ - Layout/ArrayAlignment
51
+ - Layout/BlockAlignment
49
52
  - Layout/EmptyLineAfterGuardClause
53
+ - Layout/EndAlignment
54
+ - Layout/FirstArrayElementIndentation
50
55
  - Layout/FirstParameterIndentation
51
- - Layout/IndentArray
56
+ - Layout/HashAlignment
52
57
  - Layout/IndentationConsistency
53
58
  - Layout/IndentationWidth
54
59
  - Layout/InitialIndentation
60
+ - Layout/LineLength
55
61
  - Layout/MultilineArrayBraceLayout
56
62
  - Layout/MultilineAssignmentLayout
57
63
  - Layout/MultilineHashBraceLayout
@@ -59,18 +65,18 @@ linters:
59
65
  - Layout/MultilineMethodCallIndentation
60
66
  - Layout/MultilineMethodDefinitionBraceLayout
61
67
  - Layout/MultilineOperationIndentation
62
- - Layout/TrailingBlankLines
68
+ - Layout/ParameterAlignment
69
+ - Layout/TrailingEmptyLines
63
70
  - Layout/TrailingWhitespace
64
- - Lint/BlockAlignment
65
- - Lint/EndAlignment
66
71
  - Lint/Void
67
72
  - Metrics/BlockLength
68
73
  - Metrics/BlockNesting
69
- - Metrics/LineLength
70
74
  - Naming/FileName
71
75
  - Style/FrozenStringLiteralComment
76
+ - Style/IdenticalConditionalBranches
72
77
  - Style/IfUnlessModifier
73
78
  - Style/Next
79
+ - Style/WhileUntilDo
74
80
  - Style/WhileUntilModifier
75
81
 
76
82
  Tab:
data/lib/slim_lint.rb CHANGED
@@ -19,7 +19,7 @@ require 'slim_lint/logger'
19
19
  require 'slim_lint/version'
20
20
 
21
21
  # Load all filters (required by SlimLint::Engine)
22
- Dir[File.expand_path('slim_lint/filters/*.rb', File.dirname(__FILE__))].each do |file|
22
+ Dir[File.expand_path('slim_lint/filters/*.rb', File.dirname(__FILE__))].sort.each do |file|
23
23
  require file
24
24
  end
25
25
 
@@ -37,16 +37,16 @@ require 'slim_lint/runner'
37
37
 
38
38
  # Load all matchers
39
39
  require 'slim_lint/matcher/base'
40
- Dir[File.expand_path('slim_lint/matcher/*.rb', File.dirname(__FILE__))].each do |file|
40
+ Dir[File.expand_path('slim_lint/matcher/*.rb', File.dirname(__FILE__))].sort.each do |file|
41
41
  require file
42
42
  end
43
43
 
44
44
  # Load all linters
45
- Dir[File.expand_path('slim_lint/linter/*.rb', File.dirname(__FILE__))].each do |file|
45
+ Dir[File.expand_path('slim_lint/linter/*.rb', File.dirname(__FILE__))].sort.each do |file|
46
46
  require file
47
47
  end
48
48
 
49
49
  # Load all reporters
50
- Dir[File.expand_path('slim_lint/reporter/*.rb', File.dirname(__FILE__))].each do |file|
50
+ Dir[File.expand_path('slim_lint/reporter/*.rb', File.dirname(__FILE__))].sort.each do |file|
51
51
  require file
52
52
  end
data/lib/slim_lint/cli.rb CHANGED
@@ -3,11 +3,18 @@
3
3
  require 'slim_lint'
4
4
  require 'slim_lint/options'
5
5
 
6
- require 'sysexits'
7
-
8
6
  module SlimLint
9
7
  # Command line application interface.
10
8
  class CLI # rubocop:disable Metrics/ClassLength
9
+ # Exit codes
10
+ # @see https://man.openbsd.org/sysexits.3
11
+ EX_OK = 0
12
+ EX_USAGE = 64
13
+ EX_DATAERR = 65
14
+ EX_NOINPUT = 67
15
+ EX_SOFTWARE = 70
16
+ EX_CONFIG = 78
17
+
11
18
  # Create a CLI that outputs to the specified logger.
12
19
  #
13
20
  # @param logger [SlimLint::Logger]
@@ -39,16 +46,16 @@ module SlimLint
39
46
 
40
47
  if options[:help]
41
48
  print_help(options)
42
- Sysexits::EX_OK
49
+ EX_OK
43
50
  elsif options[:version] || options[:verbose_version]
44
51
  print_version(options)
45
- Sysexits::EX_OK
52
+ EX_OK
46
53
  elsif options[:show_linters]
47
54
  print_available_linters
48
- Sysexits::EX_OK
55
+ EX_OK
49
56
  elsif options[:show_reporters]
50
57
  print_available_reporters
51
- Sysexits::EX_OK
58
+ EX_OK
52
59
  else
53
60
  scan_for_lints(options)
54
61
  end
@@ -60,20 +67,20 @@ module SlimLint
60
67
  case exception
61
68
  when SlimLint::Exceptions::ConfigurationError
62
69
  log.error exception.message
63
- Sysexits::EX_CONFIG
70
+ EX_CONFIG
64
71
  when SlimLint::Exceptions::InvalidCLIOption
65
72
  log.error exception.message
66
73
  log.log "Run `#{APP_NAME}` --help for usage documentation"
67
- Sysexits::EX_USAGE
74
+ EX_USAGE
68
75
  when SlimLint::Exceptions::InvalidFilePath
69
76
  log.error exception.message
70
- Sysexits::EX_NOINPUT
77
+ EX_NOINPUT
71
78
  when SlimLint::Exceptions::NoLintersError
72
79
  log.error exception.message
73
- Sysexits::EX_NOINPUT
80
+ EX_NOINPUT
74
81
  else
75
82
  print_unexpected_exception(exception)
76
- Sysexits::EX_SOFTWARE
83
+ EX_SOFTWARE
77
84
  end
78
85
  end
79
86
 
@@ -83,7 +90,7 @@ module SlimLint
83
90
  def scan_for_lints(options)
84
91
  report = Runner.new.run(options)
85
92
  print_report(report, options)
86
- report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK
93
+ report.failed? ? EX_DATAERR : EX_OK
87
94
  end
88
95
 
89
96
  # Outputs a report of the linter run using the specified reporter.
@@ -38,7 +38,7 @@ module SlimLint
38
38
  #
39
39
  # @param patterns [Array<String>]
40
40
  # @return [Array<String>]
41
- def extract_files_from(patterns) # rubocop:disable MethodLength
41
+ def extract_files_from(patterns) # rubocop:disable Metrics/MethodLength
42
42
  files = []
43
43
 
44
44
  patterns.each do |pattern|
@@ -9,7 +9,6 @@ module SlimLint
9
9
 
10
10
  on [:html, :tag, anything, [],
11
11
  [:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
12
-
13
12
  # Fetch original Slim code that contains an element with a control statement.
14
13
  line = document.source_lines[sexp.line() - 1]
15
14
 
@@ -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.18.0'
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.18.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: 2019-10-10 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.50.0
19
+ version: 0.78.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.50.0
26
+ version: 0.78.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: slim
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,20 +44,6 @@ dependencies:
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.0'
47
- - !ruby/object:Gem::Dependency
48
- name: sysexits
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '1.1'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '1.1'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rspec
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +104,7 @@ files:
118
104
  - lib/slim_lint/linter/comment_control_statement.rb
119
105
  - lib/slim_lint/linter/consecutive_control_statements.rb
120
106
  - lib/slim_lint/linter/control_statement_spacing.rb
107
+ - lib/slim_lint/linter/embedded_engines.rb
121
108
  - lib/slim_lint/linter/empty_control_statement.rb
122
109
  - lib/slim_lint/linter/empty_lines.rb
123
110
  - lib/slim_lint/linter/file_length.rb
@@ -141,6 +128,7 @@ files:
141
128
  - lib/slim_lint/reporter.rb
142
129
  - lib/slim_lint/reporter/checkstyle_reporter.rb
143
130
  - lib/slim_lint/reporter/default_reporter.rb
131
+ - lib/slim_lint/reporter/emacs_reporter.rb
144
132
  - lib/slim_lint/reporter/json_reporter.rb
145
133
  - lib/slim_lint/ruby_extract_engine.rb
146
134
  - lib/slim_lint/ruby_extractor.rb
@@ -154,7 +142,7 @@ homepage: https://github.com/sds/slim-lint
154
142
  licenses:
155
143
  - MIT
156
144
  metadata: {}
157
- post_install_message:
145
+ post_install_message:
158
146
  rdoc_options: []
159
147
  require_paths:
160
148
  - lib
@@ -169,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
157
  - !ruby/object:Gem::Version
170
158
  version: '0'
171
159
  requirements: []
172
- rubygems_version: 3.0.3
173
- signing_key:
160
+ rubygems_version: 3.1.4
161
+ signing_key:
174
162
  specification_version: 4
175
163
  summary: Slim template linting tool
176
164
  test_files: []