haml_lint 0.27.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/haml_lint/cli.rb +12 -12
- data/lib/haml_lint/configuration.rb +16 -1
- data/lib/haml_lint/configuration_loader.rb +2 -2
- data/lib/haml_lint/linter/class_attribute_with_static_value.rb +8 -2
- data/lib/haml_lint/tree/tag_node.rb +3 -6
- data/lib/haml_lint/utils.rb +27 -4
- data/lib/haml_lint/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de1778be09762f2f6e9205045f63a6bfbc1966f1bc848e57c5bc22a52a8c0488
|
4
|
+
data.tar.gz: ecb4cc40e34424ba773dec9b252ef7618f60b9a14e63d7afba68164f41d49681
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cdf82866d301aa55ba5891d364030f6657dcd492118be4bc06933a3158c88bb45d088fcdc6a0e60e72a983271781f5c1ab515aef5e9eff2b2a82ea23ef16cc1
|
7
|
+
data.tar.gz: 68ae9a3bd3c9d7c2d3514577aae4513b755479b4c63c7fc08bfd5f45a8cbb1dd5495e4d2dd7f071988e3d8b84bb44959577786860b2f4c2eb5118f2e6257bd8b
|
data/lib/haml_lint/cli.rb
CHANGED
@@ -21,8 +21,8 @@ module HamlLint
|
|
21
21
|
def run(args)
|
22
22
|
options = HamlLint::Options.new.parse(args)
|
23
23
|
act_on_options(options)
|
24
|
-
rescue StandardError =>
|
25
|
-
handle_exception(
|
24
|
+
rescue StandardError => exception
|
25
|
+
handle_exception(exception)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -62,23 +62,23 @@ module HamlLint
|
|
62
62
|
|
63
63
|
# Outputs a message and returns an appropriate error code for the specified
|
64
64
|
# exception.
|
65
|
-
def handle_exception(
|
66
|
-
case
|
65
|
+
def handle_exception(exception)
|
66
|
+
case exception
|
67
67
|
when HamlLint::Exceptions::ConfigurationError
|
68
|
-
log.error
|
68
|
+
log.error exception.message
|
69
69
|
Sysexits::EX_CONFIG
|
70
70
|
when HamlLint::Exceptions::InvalidCLIOption
|
71
|
-
log.error
|
71
|
+
log.error exception.message
|
72
72
|
log.log "Run `#{APP_NAME}` --help for usage documentation"
|
73
73
|
Sysexits::EX_USAGE
|
74
74
|
when HamlLint::Exceptions::InvalidFilePath
|
75
|
-
log.error
|
75
|
+
log.error exception.message
|
76
76
|
Sysexits::EX_NOINPUT
|
77
77
|
when HamlLint::Exceptions::NoLintersError
|
78
|
-
log.error
|
78
|
+
log.error exception.message
|
79
79
|
Sysexits::EX_NOINPUT
|
80
80
|
else
|
81
|
-
print_unexpected_exception(
|
81
|
+
print_unexpected_exception(exception)
|
82
82
|
Sysexits::EX_SOFTWARE
|
83
83
|
end
|
84
84
|
end
|
@@ -148,9 +148,9 @@ module HamlLint
|
|
148
148
|
|
149
149
|
# Outputs the backtrace of an exception with instructions on how to report
|
150
150
|
# the issue.
|
151
|
-
def print_unexpected_exception(
|
152
|
-
log.bold_error
|
153
|
-
log.error
|
151
|
+
def print_unexpected_exception(exception) # rubocop:disable Metrics/AbcSize
|
152
|
+
log.bold_error exception.message
|
153
|
+
log.error exception.backtrace.join("\n")
|
154
154
|
log.warning 'Report this bug at ', false
|
155
155
|
log.info HamlLint::BUG_REPORT_URL
|
156
156
|
log.newline
|
@@ -12,8 +12,10 @@ module HamlLint
|
|
12
12
|
# Creates a configuration from the given options hash.
|
13
13
|
#
|
14
14
|
# @param options [Hash]
|
15
|
-
def initialize(options)
|
15
|
+
def initialize(options, file = nil)
|
16
16
|
@hash = options
|
17
|
+
@config_dir = file ? File.dirname(file) : nil
|
18
|
+
resolve_requires
|
17
19
|
validate
|
18
20
|
end
|
19
21
|
|
@@ -75,6 +77,19 @@ module HamlLint
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
80
|
+
# Requires any extra linters / files specified in the configuration.
|
81
|
+
# String starting with a . are treated as relative paths
|
82
|
+
def resolve_requires
|
83
|
+
relative_require_dir = @config_dir || Dir.pwd
|
84
|
+
Array(@hash['require']).each do |r|
|
85
|
+
if r.start_with?('.')
|
86
|
+
require File.join(relative_require_dir, r)
|
87
|
+
else
|
88
|
+
require r
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
78
93
|
# Validates the configuration for any invalid options, normalizing it where
|
79
94
|
# possible.
|
80
95
|
def validate
|
@@ -26,7 +26,7 @@ module HamlLint
|
|
26
26
|
|
27
27
|
# Loads the built-in default configuration.
|
28
28
|
def default_configuration
|
29
|
-
@
|
29
|
+
@default_configuration ||= load_from_file(DEFAULT_CONFIG_PATH)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Loads a configuration, ensuring it extends the default configuration.
|
@@ -76,7 +76,7 @@ module HamlLint
|
|
76
76
|
hash['inherits_from'].concat(Array(hash.delete('inherit_from')))
|
77
77
|
end
|
78
78
|
|
79
|
-
HamlLint::Configuration.new(hash)
|
79
|
+
HamlLint::Configuration.new(hash, file)
|
80
80
|
end
|
81
81
|
|
82
82
|
# Returns a list of possible configuration files given the context of the
|
@@ -29,9 +29,13 @@ module HamlLint
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
+
def surrounded_by_braces?(code)
|
33
|
+
code.start_with?('{') && code.end_with?('}')
|
34
|
+
end
|
35
|
+
|
32
36
|
def contains_class_attribute?(attributes_sources)
|
33
37
|
attributes_sources.each do |code|
|
34
|
-
ast_root = parse_ruby(
|
38
|
+
ast_root = parse_ruby(surrounded_by_braces?(code) ? code : "{#{code}}")
|
35
39
|
next unless ast_root # RuboCop linter will report syntax errors
|
36
40
|
|
37
41
|
ast_root.children.each do |pair|
|
@@ -43,7 +47,9 @@ module HamlLint
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def static_class_attribute_value?(pair)
|
46
|
-
|
50
|
+
return false if (children = pair.children).empty?
|
51
|
+
|
52
|
+
key, value = children
|
47
53
|
|
48
54
|
STATIC_TYPES.include?(key.type) &&
|
49
55
|
key.children.first.to_sym == :class &&
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module HamlLint::Tree
|
2
2
|
# Represents a tag node in a HAML document.
|
3
|
-
# rubocop:disable ClassLength
|
4
|
-
class TagNode < Node
|
3
|
+
class TagNode < Node # rubocop:disable ClassLength
|
5
4
|
# Computed set of attribute hashes code.
|
6
5
|
#
|
7
6
|
# This is a combination of all dynamically calculated attributes from the
|
@@ -97,7 +96,7 @@ module HamlLint::Tree
|
|
97
96
|
#
|
98
97
|
# @return [Hash]
|
99
98
|
def attributes_source
|
100
|
-
@
|
99
|
+
@attributes_source ||=
|
101
100
|
begin
|
102
101
|
_explicit_tag, static_attrs, rest =
|
103
102
|
source_code.scan(/\A\s*(%[-:\w]+)?([-:\w\.\#]*)(.*)/m)[0]
|
@@ -217,11 +216,9 @@ module HamlLint::Tree
|
|
217
216
|
# Whether this node had a `>` after it signifying that outer whitespace
|
218
217
|
# should be removed.
|
219
218
|
#
|
220
|
-
# rubocop:disable Style/DoubleNegation
|
221
|
-
#
|
222
219
|
# @return [true,false]
|
223
220
|
def remove_outer_whitespace?
|
224
|
-
!!@value[:nuke_outer_whitespace]
|
221
|
+
!!@value[:nuke_outer_whitespace] # rubocop:disable Style/DoubleNegation
|
225
222
|
end
|
226
223
|
|
227
224
|
# Returns the script source that will be evaluated to produce this tag's
|
data/lib/haml_lint/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
module HamlLint
|
2
4
|
# A miscellaneous set of utility functions.
|
3
5
|
module Utils
|
@@ -13,10 +15,31 @@ module HamlLint
|
|
13
15
|
# @param file [String]
|
14
16
|
# @return [Boolean]
|
15
17
|
def any_glob_matches?(globs_or_glob, file)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
get_abs_and_rel_path(file).any? do |path|
|
19
|
+
Array(globs_or_glob).any? do |glob|
|
20
|
+
::File.fnmatch?(glob, path,
|
21
|
+
::File::FNM_PATHNAME | # Wildcards don't match path separators
|
22
|
+
::File::FNM_DOTMATCH) # `*` wildcard matches dotfiles
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns an array of two items, the first being the absolute path, the second
|
28
|
+
# the relative path.
|
29
|
+
#
|
30
|
+
# The relative path is relative to the current working dir. The path passed can
|
31
|
+
# be either relative or absolute.
|
32
|
+
#
|
33
|
+
# @param path [String] Path to get absolute and relative path of
|
34
|
+
# @return [Array<String>] Absolute and relative path
|
35
|
+
def get_abs_and_rel_path(path)
|
36
|
+
original_path = Pathname.new(path)
|
37
|
+
root_dir_path = Pathname.new(File.expand_path(Dir.pwd))
|
38
|
+
|
39
|
+
if original_path.absolute?
|
40
|
+
[path, original_path.relative_path_from(root_dir_path)]
|
41
|
+
else
|
42
|
+
[root_dir_path + original_path, path]
|
20
43
|
end
|
21
44
|
end
|
22
45
|
|
data/lib/haml_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.28.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brigade Engineering
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: haml
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
description: Configurable tool for writing clean and consistent HAML
|
97
97
|
email:
|
98
98
|
- eng@brigade.com
|
99
|
-
- shane
|
99
|
+
- shane@dasilva.io
|
100
100
|
executables:
|
101
101
|
- haml-lint
|
102
102
|
extensions: []
|
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
197
|
requirements:
|
198
198
|
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
|
-
version: 2.
|
200
|
+
version: 2.2.0
|
201
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
202
|
requirements:
|
203
203
|
- - ">="
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.6
|
208
|
+
rubygems_version: 2.7.6
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: HAML lint tool
|