erb_lint 0.0.7 → 0.0.8

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: 19ae73f0612719d45eb240bb5c318022bbda31d6
4
- data.tar.gz: b303b89d8fb7b4bc8eaaccd64e54f987b4cec953
3
+ metadata.gz: 4c63d51b88111aebeec5f4bc85009a499d61d750
4
+ data.tar.gz: b389e7f7f6aca2251369ae7491b9a58847a8db0e
5
5
  SHA512:
6
- metadata.gz: cf30f6318bfbbdc123f3c8bf87981288bcdd8c125ca57466ed88e1e28438d83ec22f4900680cfe4ed789cdf656bcb31745a44e27561eb70d25a63fccad0db52c
7
- data.tar.gz: 4ba1c926ea2cbb72b02dc8903cc2d753e2f680d6b46c1021b3278b9b3fbe0579a09f464922f6176a726adc534dab50dfe55d1539c8338b761c4239fb0f8dc707
6
+ metadata.gz: 5951a1d7466088a8298801fb6e41a00069417cd33a977cb5b2a8403fe1611f349162b710887b073410f23fa66f03f67ccf683a678f3068e61cd7bb22b79cfa5f
7
+ data.tar.gz: 1c505e1eb402fe827c8d0f542d8c8eba8efeeed9a5f973f21bb12a83ae698ea4f9eb77f6ed193d8a58c6e006eded532cd06544c610a9ea01846bd010e8e03260
data/lib/erb_lint.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'erb_lint/linter_registry'
4
4
  require 'erb_lint/linter'
5
5
  require 'erb_lint/runner'
6
+ require 'erb_lint/file_loader'
6
7
 
7
8
  # Load linters
8
9
  Dir[File.expand_path('erb_lint/linters/**/*.rb', File.dirname(__FILE__))].each do |file|
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ERBLint
4
+ # Loads file from disk
5
+ class FileLoader
6
+ attr_reader :base_path
7
+
8
+ def initialize(base_path)
9
+ @base_path = base_path
10
+ end
11
+
12
+ def yaml(filename)
13
+ YAML.safe_load(read_content(filename), [Regexp], [], false, filename) || {}
14
+ rescue Psych::SyntaxError
15
+ {}
16
+ end
17
+
18
+ private
19
+
20
+ def join(filename)
21
+ File.join(base_path, filename)
22
+ end
23
+
24
+ def read_content(filename)
25
+ File.read(join(filename))
26
+ end
27
+ end
28
+ end
@@ -20,8 +20,8 @@ module ERBLint
20
20
  end
21
21
 
22
22
  # Must be implemented by the concrete inheriting class.
23
- def initialize(_config)
24
- raise NotImplementedError, "must implement ##{__method__}"
23
+ def initialize(file_loader, _config)
24
+ @file_loader = file_loader
25
25
  end
26
26
 
27
27
  def lint_file(file_content)
@@ -8,7 +8,9 @@ module ERBLint
8
8
  class DeprecatedClasses < Linter
9
9
  include LinterRegistry
10
10
 
11
- def initialize(config)
11
+ def initialize(file_loader, config)
12
+ super
13
+
12
14
  @deprecated_ruleset = []
13
15
  config.fetch('rule_set', []).each do |rule|
14
16
  suggestion = rule.fetch('suggestion', '')
@@ -10,12 +10,14 @@ module ERBLint
10
10
  include LinterRegistry
11
11
  include BetterHtml::TestHelper::SafeErbTester
12
12
 
13
- def initialize(config)
13
+ def initialize(file_loader, config)
14
+ super
15
+ @config_filename = config['better-html-config']
14
16
  end
15
17
 
16
18
  def lint_file(file_content)
17
19
  errors = []
18
- tester = Tester.new(file_content)
20
+ tester = Tester.new(file_content, config: better_html_config)
19
21
  tester.errors.each do |error|
20
22
  errors << format_error(error)
21
23
  end
@@ -24,6 +26,18 @@ module ERBLint
24
26
 
25
27
  private
26
28
 
29
+ def better_html_config
30
+ @better_html_config ||= begin
31
+ config_hash =
32
+ if @config_filename.nil?
33
+ {}
34
+ else
35
+ @file_loader.yaml(@config_filename)
36
+ end
37
+ BetterHtml::Config.new(**config_hash)
38
+ end
39
+ end
40
+
27
41
  def format_error(error)
28
42
  {
29
43
  line: error.location.line,
@@ -6,7 +6,8 @@ module ERBLint
6
6
  class FinalNewline < Linter
7
7
  include LinterRegistry
8
8
 
9
- def initialize(config)
9
+ def initialize(file_loader, config)
10
+ super
10
11
  @new_lines_should_be_present = config['present'].nil? ? true : config['present']
11
12
  end
12
13
 
@@ -13,7 +13,8 @@ module ERBLint
13
13
  # copied from Rails: action_view/template/handlers/erb/erubi.rb
14
14
  BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
15
15
 
16
- def initialize(config_hash)
16
+ def initialize(file_loader, config_hash)
17
+ super
17
18
  @enabled_cops = config_hash.delete('only')
18
19
  tempfile_from('.erblint-rubocop', config_hash.except('enabled').to_yaml) do |tempfile|
19
20
  custom_config = RuboCop::ConfigLoader.load_file(tempfile.path)
@@ -3,14 +3,15 @@
3
3
  module ERBLint
4
4
  # Runs all enabled linters against an html.erb file.
5
5
  class Runner
6
- def initialize(config = {})
6
+ def initialize(file_loader, config = {})
7
+ @file_loader = file_loader
7
8
  @config = default_config.merge(config || {})
8
9
 
9
10
  LinterRegistry.load_custom_linters
10
11
  @linters = LinterRegistry.linters.select { |linter_class| linter_enabled?(linter_class) }
11
12
  @linters.map! do |linter_class|
12
13
  linter_config = @config.dig('linters', linter_class.simple_name)
13
- linter_class.new(linter_config)
14
+ linter_class.new(@file_loader, linter_config)
14
15
  end
15
16
  end
16
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Chan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.5
19
+ version: 0.0.10
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.0.5
26
+ version: 0.0.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: html_tokenizer
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,6 +88,7 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - lib/erb_lint.rb
91
+ - lib/erb_lint/file_loader.rb
91
92
  - lib/erb_lint/linter.rb
92
93
  - lib/erb_lint/linter_registry.rb
93
94
  - lib/erb_lint/linters/deprecated_classes.rb