slim_lint 0.1.0 → 0.2.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
  SHA1:
3
- metadata.gz: ea825ed5f8f37b9f5c0f65af4cce47ee9289227c
4
- data.tar.gz: 31f794679bd7928f0e7990e3802319e2aeaa1764
3
+ metadata.gz: 90417095e752ffc02b70c6cf2c7c578642a7aced
4
+ data.tar.gz: db37d397d726e455c2d98e565c1f0a4ba876c28f
5
5
  SHA512:
6
- metadata.gz: 60c07b39dab5f98178fa7a01318e42c97e64676810309a03932b836fe1800bb9265203da373a601aa9882d53afc5b23d15c487efcab2d0a74871d7fcbe6f15b3
7
- data.tar.gz: 8a65468ddb8de4b2834178f5e89ce90203281678d3d1cb2c0eeb42a22ffc6d6f10ef115ad65e7ab3d237043d2730f9ed4d5969add7f465becbd0ae99b485606a
6
+ metadata.gz: d08877671cd10ae219e055f65f16c9dc26800b4aac6fe0be74dcd669da2da0bcdf45ec7885b24c87333c7731fe1178a7c0c45259146ff7c285da6371b7da53da
7
+ data.tar.gz: 1afec4e606480b536283d722121dc662fc0d6b2da4cd5bfeb3c93e4853b113404459a6e012546cd0fb179f99888983fa7ce0880f5f02bfcb5944acb163817c19
data/config/default.yml CHANGED
@@ -8,6 +8,16 @@
8
8
  skip_frontmatter: false
9
9
 
10
10
  linters:
11
+ CommentControlStatement:
12
+ enabled: true
13
+
14
+ ConsecutiveControlStatements:
15
+ enabled: true
16
+ max_consecutive: 2
17
+
18
+ EmptyControlStatment:
19
+ enabled: true
20
+
11
21
  ExplicitDiv:
12
22
  enabled: true
13
23
 
@@ -28,11 +38,15 @@ linters:
28
38
  - Style/BlockNesting
29
39
  - Style/FileName
30
40
  - Style/IfUnlessModifier
41
+ - Style/IndentationConsistency
31
42
  - Style/IndentationWidth
32
43
  - Style/Next
33
44
  - Style/TrailingBlankLines
34
45
  - Style/TrailingWhitespace
35
46
  - Style/WhileUntilModifier
36
47
 
48
+ TagCase:
49
+ enabled: true
50
+
37
51
  TrailingWhitespace:
38
52
  enabled: true
@@ -1,4 +1,4 @@
1
- # Collection of exceptions that can be raised by the HAML Lint application.
1
+ # Collection of exceptions that can be raised by the application.
2
2
  module SlimLint::Exceptions
3
3
  # Raised when a {Configuration} could not be loaded from a file.
4
4
  class ConfigurationError < StandardError; end
@@ -1,5 +1,5 @@
1
1
  module SlimLint
2
- # Contains information about a problem or issue with a HAML document.
2
+ # Contains information about a problem or issue with a Slim document.
3
3
  class Lint
4
4
  attr_reader :filename, :line, :linter, :message, :severity
5
5
 
@@ -0,0 +1,17 @@
1
+ module SlimLint
2
+ # Searches for control statements with only comments.
3
+ class Linter::CommentControlStatement < Linter
4
+ include LinterRegistry
5
+
6
+ on [:slim, :control] do |sexp|
7
+ _, _, code = sexp
8
+ next unless code =~ /\A\s*#/
9
+
10
+ comment = code[/\A\s*#(.*\z)/, 1]
11
+
12
+ report_lint(sexp,
13
+ "Slim code comments (`/#{comment}`) are preferred over " \
14
+ "control statement comments (`-# #{comment}`)")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ module SlimLint
2
+ # Searches for more than an allowed number of consecutive control code
3
+ # statements that could be condensed into a :ruby filter.
4
+ class Linter::ConsecutiveControlStatements < Linter
5
+ include LinterRegistry
6
+
7
+ on [:multi] do |sexp|
8
+ Utils.for_consecutive_items(sexp,
9
+ method(:code_sexp?),
10
+ config['max_consecutive'] + 1) do |group|
11
+ report_lint(group.first,
12
+ "#{group.count} consecutive control statements can be " \
13
+ 'merged into a single `ruby:` filter')
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ # Returns whether the given Sexp is a :code abstraction.
20
+ #
21
+ # @param sexp [SlimLint::Sexp]
22
+ # @return [Boolean]
23
+ def code_sexp?(sexp)
24
+ # TODO: Switch this with a built-in method on the {Sexp} object itself
25
+ sexp.is_a?(Sexp) && sexp.match?([:slim, :control])
26
+ end
27
+
28
+ def newline_sexp?(sexp)
29
+ sexp.is_a?(Sexp) && sexp.first == :newline
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ module SlimLint
2
+ # Searches for control statements with no code.
3
+ class Linter::EmptyControlStatement < Linter
4
+ include LinterRegistry
5
+
6
+ on [:slim, :control] do |sexp|
7
+ _, _, code = sexp
8
+ next unless code =~ /\A\s*\Z/
9
+
10
+ report_lint(sexp, 'Empty control statement can be removed')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module SlimLint
2
+ # Searches for tags with uppercase characters.
3
+ class Linter::TagCase < Linter
4
+ include LinterRegistry
5
+
6
+ on [:html, :tag] do |sexp|
7
+ _, _, name = sexp
8
+ next unless name =~ /[A-Z]/
9
+
10
+ report_lint(sexp, "Tag `#{name}` should be written as `#{name.downcase}`")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,49 @@
1
+ module SlimLint
2
+ # Miscellaneus collection of helper functions.
3
+ module Utils
4
+ module_function
5
+
6
+ # Find all consecutive items satisfying the given block of a minimum size,
7
+ # yielding each group of consecutive items to the provided block.
8
+ #
9
+ # @param items [Array]
10
+ # @param satisfies [Proc] function that takes an item and returns true/false
11
+ # @param min_consecutive [Fixnum] minimum number of consecutive items before
12
+ # yielding the group
13
+ # @yield Passes list of consecutive items all matching the criteria defined
14
+ # by the `satisfies` {Proc} to the provided block
15
+ # @yieldparam group [Array] List of consecutive items
16
+ # @yieldreturn [Boolean] block should return whether item matches criteria
17
+ # for inclusion
18
+ def for_consecutive_items(items, satisfies, min_consecutive = 2)
19
+ current_index = -1
20
+
21
+ while (current_index += 1) < items.count
22
+ next unless satisfies[items[current_index]]
23
+
24
+ count = count_consecutive(items, current_index, &satisfies)
25
+ next unless count >= min_consecutive
26
+
27
+ # Yield the chunk of consecutive items
28
+ yield items[current_index...(current_index + count)]
29
+
30
+ current_index += count # Skip this patch of consecutive items to find more
31
+ end
32
+ end
33
+
34
+ # Count the number of consecutive items satisfying the given {Proc}.
35
+ #
36
+ # @param items [Array]
37
+ # @param offset [Fixnum] index to start searching from
38
+ # @yield [item] Passes item to the provided block.
39
+ # @yieldparam item [Object] Item to evaluate as matching criteria for
40
+ # inclusion
41
+ # @yieldreturn [Boolean] whether to include the item
42
+ # @return [Integer]
43
+ def count_consecutive(items, offset = 0, &block)
44
+ count = 1
45
+ count += 1 while (offset + count < items.count) && block.call(items[offset + count])
46
+ count
47
+ end
48
+ end
49
+ end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SlimLint
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
data/lib/slim_lint.rb CHANGED
@@ -5,6 +5,7 @@ require 'slim_lint/constants'
5
5
  require 'slim_lint/exceptions'
6
6
  require 'slim_lint/configuration'
7
7
  require 'slim_lint/configuration_loader'
8
+ require 'slim_lint/utils'
8
9
  require 'slim_lint/sexp'
9
10
  require 'slim_lint/file_finder'
10
11
  require 'slim_lint/linter_registry'
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.1.0
4
+ version: 0.2.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: 2015-04-19 00:00:00.000000000 Z
11
+ date: 2015-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim
@@ -103,9 +103,13 @@ files:
103
103
  - lib/slim_lint/filters/sexp_converter.rb
104
104
  - lib/slim_lint/lint.rb
105
105
  - lib/slim_lint/linter.rb
106
+ - lib/slim_lint/linter/comment_control_statement.rb
107
+ - lib/slim_lint/linter/consecutive_control_statements.rb
108
+ - lib/slim_lint/linter/empty_control_statement.rb
106
109
  - lib/slim_lint/linter/line_length.rb
107
110
  - lib/slim_lint/linter/redundant_div.rb
108
111
  - lib/slim_lint/linter/rubocop.rb
112
+ - lib/slim_lint/linter/tag_case.rb
109
113
  - lib/slim_lint/linter/trailing_whitespace.rb
110
114
  - lib/slim_lint/linter_registry.rb
111
115
  - lib/slim_lint/logger.rb
@@ -121,6 +125,7 @@ files:
121
125
  - lib/slim_lint/runner.rb
122
126
  - lib/slim_lint/sexp.rb
123
127
  - lib/slim_lint/sexp_visitor.rb
128
+ - lib/slim_lint/utils.rb
124
129
  - lib/slim_lint/version.rb
125
130
  homepage: https://github.com/sds/slim-lint
126
131
  licenses: