slim_lint 0.15.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/slim-lint +1 -0
- data/config/default.yml +8 -0
- data/lib/slim_lint/atom.rb +2 -0
- data/lib/slim_lint/capture_map.rb +2 -0
- data/lib/slim_lint/cli.rb +12 -10
- data/lib/slim_lint/configuration.rb +2 -0
- data/lib/slim_lint/configuration_loader.rb +2 -2
- data/lib/slim_lint/constants.rb +3 -3
- data/lib/slim_lint/engine.rb +2 -0
- data/lib/slim_lint/exceptions.rb +2 -0
- data/lib/slim_lint/file_finder.rb +3 -1
- data/lib/slim_lint/filters/attribute_processor.rb +2 -0
- data/lib/slim_lint/filters/control_processor.rb +2 -0
- data/lib/slim_lint/filters/inject_line_numbers.rb +2 -0
- data/lib/slim_lint/filters/sexp_converter.rb +2 -0
- data/lib/slim_lint/filters/splat_processor.rb +2 -0
- data/lib/slim_lint/lint.rb +2 -0
- data/lib/slim_lint/linter/comment_control_statement.rb +2 -0
- data/lib/slim_lint/linter/consecutive_control_statements.rb +2 -0
- data/lib/slim_lint/linter/control_statement_spacing.rb +24 -0
- data/lib/slim_lint/linter/empty_control_statement.rb +2 -0
- data/lib/slim_lint/linter/empty_lines.rb +2 -0
- data/lib/slim_lint/linter/file_length.rb +20 -0
- data/lib/slim_lint/linter/line_length.rb +1 -1
- data/lib/slim_lint/linter/redundant_div.rb +1 -1
- data/lib/slim_lint/linter/rubocop.rb +2 -0
- data/lib/slim_lint/linter/tab.rb +3 -1
- data/lib/slim_lint/linter/tag_case.rb +2 -0
- data/lib/slim_lint/linter/trailing_blank_lines.rb +2 -0
- data/lib/slim_lint/linter/trailing_whitespace.rb +2 -0
- data/lib/slim_lint/linter.rb +2 -0
- data/lib/slim_lint/linter_registry.rb +2 -0
- data/lib/slim_lint/linter_selector.rb +2 -0
- data/lib/slim_lint/logger.rb +2 -0
- data/lib/slim_lint/matcher/anything.rb +2 -0
- data/lib/slim_lint/matcher/base.rb +2 -0
- data/lib/slim_lint/matcher/capture.rb +2 -0
- data/lib/slim_lint/matcher/nothing.rb +2 -0
- data/lib/slim_lint/options.rb +2 -0
- data/lib/slim_lint/rake_task.rb +2 -0
- data/lib/slim_lint/report.rb +2 -0
- data/lib/slim_lint/reporter/checkstyle_reporter.rb +2 -0
- data/lib/slim_lint/reporter/default_reporter.rb +2 -0
- data/lib/slim_lint/reporter/json_reporter.rb +2 -0
- data/lib/slim_lint/reporter.rb +2 -0
- data/lib/slim_lint/ruby_extract_engine.rb +2 -0
- data/lib/slim_lint/ruby_extractor.rb +2 -0
- data/lib/slim_lint/ruby_parser.rb +2 -0
- data/lib/slim_lint/runner.rb +2 -0
- data/lib/slim_lint/sexp.rb +3 -1
- data/lib/slim_lint/sexp_visitor.rb +2 -0
- data/lib/slim_lint/utils.rb +4 -1
- data/lib/slim_lint/version.rb +1 -1
- data/lib/slim_lint.rb +2 -0
- metadata +14 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a0a85688d4fd272c34d5a3f6a6f8e76fc92baa6612ecc6beabe5459b02a0ff1
|
4
|
+
data.tar.gz: ba9b1c8a6adc808311d0ae0cdfe67a260f1692ec7c6e0ac2476d19035b18e270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72945205219ecb6bdf4ef8947bb84b7def1c4b549ac6e52d8ad3afc338f0061bfa90fe15d3b013dcde25990b0da270df449ef53fc1f6e61cfb76b871367388d3
|
7
|
+
data.tar.gz: 74513c279efc7056bdea21519d43ac9074f5599cdd72f6a9132ec71efd88ed64ac2b23684724ea598f8c0db493230ffa44529ccf39e579109701cebb4f8388b2
|
data/bin/slim-lint
CHANGED
data/config/default.yml
CHANGED
@@ -11,6 +11,9 @@ linters:
|
|
11
11
|
CommentControlStatement:
|
12
12
|
enabled: true
|
13
13
|
|
14
|
+
ControlStatementSpacing:
|
15
|
+
enabled: true
|
16
|
+
|
14
17
|
ConsecutiveControlStatements:
|
15
18
|
enabled: true
|
16
19
|
max_consecutive: 2
|
@@ -28,6 +31,10 @@ linters:
|
|
28
31
|
enabled: true
|
29
32
|
max: 80
|
30
33
|
|
34
|
+
FileLength:
|
35
|
+
enabled: false
|
36
|
+
max: 300
|
37
|
+
|
31
38
|
RuboCop:
|
32
39
|
enabled: true
|
33
40
|
# These cops are incredibly noisy since the Ruby we extract from Slim
|
@@ -58,6 +65,7 @@ linters:
|
|
58
65
|
- Metrics/BlockNesting
|
59
66
|
- Metrics/LineLength
|
60
67
|
- Naming/FileName
|
68
|
+
- Style/EmptyLineAfterGuardClause
|
61
69
|
- Style/FrozenStringLiteralComment
|
62
70
|
- Style/IfUnlessModifier
|
63
71
|
- Style/Next
|
data/lib/slim_lint/atom.rb
CHANGED
data/lib/slim_lint/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'slim_lint'
|
2
4
|
require 'slim_lint/options'
|
3
5
|
|
@@ -54,23 +56,23 @@ module SlimLint
|
|
54
56
|
|
55
57
|
# Outputs a message and returns an appropriate error code for the specified
|
56
58
|
# exception.
|
57
|
-
def handle_exception(
|
58
|
-
case
|
59
|
+
def handle_exception(exception)
|
60
|
+
case exception
|
59
61
|
when SlimLint::Exceptions::ConfigurationError
|
60
|
-
log.error
|
62
|
+
log.error exception.message
|
61
63
|
Sysexits::EX_CONFIG
|
62
64
|
when SlimLint::Exceptions::InvalidCLIOption
|
63
|
-
log.error
|
65
|
+
log.error exception.message
|
64
66
|
log.log "Run `#{APP_NAME}` --help for usage documentation"
|
65
67
|
Sysexits::EX_USAGE
|
66
68
|
when SlimLint::Exceptions::InvalidFilePath
|
67
|
-
log.error
|
69
|
+
log.error exception.message
|
68
70
|
Sysexits::EX_NOINPUT
|
69
71
|
when SlimLint::Exceptions::NoLintersError
|
70
|
-
log.error
|
72
|
+
log.error exception.message
|
71
73
|
Sysexits::EX_NOINPUT
|
72
74
|
else
|
73
|
-
print_unexpected_exception(
|
75
|
+
print_unexpected_exception(exception)
|
74
76
|
Sysexits::EX_SOFTWARE
|
75
77
|
end
|
76
78
|
end
|
@@ -135,9 +137,9 @@ module SlimLint
|
|
135
137
|
|
136
138
|
# Outputs the backtrace of an exception with instructions on how to report
|
137
139
|
# the issue.
|
138
|
-
def print_unexpected_exception(
|
139
|
-
log.bold_error
|
140
|
-
log.error
|
140
|
+
def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize
|
141
|
+
log.bold_error exception.message
|
142
|
+
log.error exception.backtrace.join("\n")
|
141
143
|
log.warning 'Report this bug at ', false
|
142
144
|
log.info SlimLint::BUG_REPORT_URL
|
143
145
|
log.newline
|
@@ -7,7 +7,7 @@ module SlimLint
|
|
7
7
|
# Manages configuration file loading.
|
8
8
|
class ConfigurationLoader
|
9
9
|
DEFAULT_CONFIG_PATH = File.join(SlimLint::HOME, 'config', 'default.yml').freeze
|
10
|
-
CONFIG_FILE_NAME = '.slim-lint.yml'
|
10
|
+
CONFIG_FILE_NAME = '.slim-lint.yml'
|
11
11
|
|
12
12
|
class << self
|
13
13
|
# Load configuration file given the current working directory the
|
@@ -25,7 +25,7 @@ module SlimLint
|
|
25
25
|
|
26
26
|
# Loads the built-in default configuration.
|
27
27
|
def default_configuration
|
28
|
-
@
|
28
|
+
@default_configuration ||= load_from_file(DEFAULT_CONFIG_PATH)
|
29
29
|
end
|
30
30
|
|
31
31
|
# Loads a configuration, ensuring it extends the default configuration.
|
data/lib/slim_lint/constants.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Global application constants.
|
4
4
|
module SlimLint
|
5
5
|
HOME = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
|
6
|
-
APP_NAME = 'slim-lint'
|
6
|
+
APP_NAME = 'slim-lint'
|
7
7
|
|
8
|
-
REPO_URL = 'https://github.com/sds/slim-lint'
|
9
|
-
BUG_REPORT_URL = "#{REPO_URL}/issues"
|
8
|
+
REPO_URL = 'https://github.com/sds/slim-lint'
|
9
|
+
BUG_REPORT_URL = "#{REPO_URL}/issues"
|
10
10
|
end
|
data/lib/slim_lint/engine.rb
CHANGED
data/lib/slim_lint/exceptions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'find'
|
2
4
|
|
3
5
|
module SlimLint
|
@@ -70,7 +72,7 @@ module SlimLint
|
|
70
72
|
# @param path [String]
|
71
73
|
# @return [String]
|
72
74
|
def normalize_path(path)
|
73
|
-
|
75
|
+
path.start_with?(".#{File::SEPARATOR}") ? path[2..-1] : path
|
74
76
|
end
|
75
77
|
|
76
78
|
# Whether the given file should be treated as a Slim file.
|
data/lib/slim_lint/lint.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlimLint
|
4
|
+
# Checks for missing or superfluous spacing before and after control statements.
|
5
|
+
class Linter::ControlStatementSpacing < Linter
|
6
|
+
include LinterRegistry
|
7
|
+
|
8
|
+
MESSAGE = 'Please add a space before and after the `=`'
|
9
|
+
|
10
|
+
on [:html, :tag, anything, [],
|
11
|
+
[:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
|
12
|
+
|
13
|
+
# Fetch original Slim code that contains an element with a control statement.
|
14
|
+
line = document.source_lines[sexp.line() - 1]
|
15
|
+
|
16
|
+
# Remove any Ruby code, because our regexp below must not match inside Ruby.
|
17
|
+
ruby = captures[:ruby]
|
18
|
+
line = line.sub(ruby, 'x')
|
19
|
+
|
20
|
+
next if line =~ /[^ ] ==? [^ ]/
|
21
|
+
report_lint(sexp, MESSAGE)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlimLint
|
4
|
+
# Checks for file longer than a maximum number of lines.
|
5
|
+
class Linter::FileLength < Linter
|
6
|
+
include LinterRegistry
|
7
|
+
|
8
|
+
MSG = 'File is too long. [%d/%d]'
|
9
|
+
|
10
|
+
on_start do |_sexp|
|
11
|
+
max_length = config['max']
|
12
|
+
dummy_node = Struct.new(:line)
|
13
|
+
|
14
|
+
count = document.source_lines.size
|
15
|
+
if count > max_length
|
16
|
+
report_lint(dummy_node.new(1), format(MSG, count, max_length))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -6,7 +6,7 @@ module SlimLint
|
|
6
6
|
class Linter::RedundantDiv < Linter
|
7
7
|
include LinterRegistry
|
8
8
|
|
9
|
-
MESSAGE = '`div` is redundant when %s attribute shortcut is present'
|
9
|
+
MESSAGE = '`div` is redundant when %s attribute shortcut is present'
|
10
10
|
|
11
11
|
on [:html, :tag, 'div',
|
12
12
|
[:html, :attrs,
|
data/lib/slim_lint/linter/tab.rb
CHANGED
data/lib/slim_lint/linter.rb
CHANGED
data/lib/slim_lint/logger.rb
CHANGED
data/lib/slim_lint/options.rb
CHANGED
data/lib/slim_lint/rake_task.rb
CHANGED
data/lib/slim_lint/report.rb
CHANGED
data/lib/slim_lint/reporter.rb
CHANGED
data/lib/slim_lint/runner.rb
CHANGED
data/lib/slim_lint/sexp.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlimLint
|
2
4
|
# Symbolic expression which represents tree-structured data.
|
3
5
|
#
|
@@ -78,7 +80,7 @@ module SlimLint
|
|
78
80
|
# @return [String]
|
79
81
|
def display(depth = 1) # rubocop:disable Metrics/AbcSize
|
80
82
|
indentation = ' ' * 2 * depth
|
81
|
-
output = '['
|
83
|
+
output = '['.dup
|
82
84
|
|
83
85
|
each_with_index do |nested_sexp, index|
|
84
86
|
output << "\n"
|
data/lib/slim_lint/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlimLint
|
2
4
|
# Miscellaneus collection of helper functions.
|
3
5
|
module Utils
|
@@ -13,8 +15,9 @@ module SlimLint
|
|
13
15
|
# @param file [String]
|
14
16
|
# @return [Boolean]
|
15
17
|
def any_glob_matches?(globs_or_glob, file)
|
18
|
+
path = File.expand_path(file)
|
16
19
|
Array(globs_or_glob).any? do |glob|
|
17
|
-
::File.fnmatch?(glob,
|
20
|
+
::File.fnmatch?(File.expand_path(glob), path,
|
18
21
|
::File::FNM_PATHNAME | # Wildcards don't match path separators
|
19
22
|
::File::FNM_DOTMATCH) # `*` wildcard matches dotfiles
|
20
23
|
end
|
data/lib/slim_lint/version.rb
CHANGED
data/lib/slim_lint.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.16.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:
|
11
|
+
date: 2018-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -48,16 +48,22 @@ dependencies:
|
|
48
48
|
name: slim
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '3.0'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '5.0'
|
54
57
|
type: :runtime
|
55
58
|
prerelease: false
|
56
59
|
version_requirements: !ruby/object:Gem::Requirement
|
57
60
|
requirements:
|
58
|
-
- - "
|
61
|
+
- - ">="
|
59
62
|
- !ruby/object:Gem::Version
|
60
63
|
version: '3.0'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '5.0'
|
61
67
|
- !ruby/object:Gem::Dependency
|
62
68
|
name: sysexits
|
63
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,8 +137,10 @@ files:
|
|
131
137
|
- lib/slim_lint/linter.rb
|
132
138
|
- lib/slim_lint/linter/comment_control_statement.rb
|
133
139
|
- lib/slim_lint/linter/consecutive_control_statements.rb
|
140
|
+
- lib/slim_lint/linter/control_statement_spacing.rb
|
134
141
|
- lib/slim_lint/linter/empty_control_statement.rb
|
135
142
|
- lib/slim_lint/linter/empty_lines.rb
|
143
|
+
- lib/slim_lint/linter/file_length.rb
|
136
144
|
- lib/slim_lint/linter/line_length.rb
|
137
145
|
- lib/slim_lint/linter/redundant_div.rb
|
138
146
|
- lib/slim_lint/linter/rubocop.rb
|
@@ -174,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
182
|
requirements:
|
175
183
|
- - ">="
|
176
184
|
- !ruby/object:Gem::Version
|
177
|
-
version: 2.
|
185
|
+
version: 2.2.0
|
178
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
187
|
requirements:
|
180
188
|
- - ">="
|
@@ -182,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
190
|
version: '0'
|
183
191
|
requirements: []
|
184
192
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.6
|
193
|
+
rubygems_version: 2.7.6
|
186
194
|
signing_key:
|
187
195
|
specification_version: 4
|
188
196
|
summary: Slim template linting tool
|