pronto-erb_lint 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 284783cdb09262ff5d61aab65e9f6b3d200a3b07
4
- data.tar.gz: 01e6db6ade1913c811183c9c68e0f7395ee157cf
2
+ SHA256:
3
+ metadata.gz: f8bac9a38b27263c90eb1b6078c4f14f5420e2813b3c8e7f14d9baddb9d32ca1
4
+ data.tar.gz: 49d6d01d422490a735eeabb9f19cbf0196fae8b77cc241fa5d2a8058831bdccf
5
5
  SHA512:
6
- metadata.gz: ef6b6fc9fbe892266ab385c81e90b956516905ddd434a9e2ec75e979c50b193fad88cdde94d9146145658697f0144335e89c78bf0598fbd8f9ed52b7979e0c63
7
- data.tar.gz: 76a4ed32530c6ecf8831c39240e4cac75355945fcb2a72cf747d6c5164cc0305df0ae173f53907bf4fe13761cbbb99f12faed45d4571d8abb3aee0e303aa1cb6
6
+ metadata.gz: 7751d95260a335f241e520e02739fb434523bbd124b501cb3f12ce47763699c21844d20ee4c4b93ef46a9157548bf5219dff439ac60686e340e54ed4880ae184
7
+ data.tar.gz: 7e636800acd5b80cfef98bb56a713d956f3202e3be4d28bcd801e0671016cd98c8710a898ca09fdafef11f14cfcb02769d8d552f8a01164ac2faaf85525eea02
@@ -0,0 +1,116 @@
1
+ require 'pronto'
2
+ require 'erb_lint'
3
+ require 'erb_lint/cli'
4
+ require 'erb_lint/file_loader'
5
+
6
+ module Pronto
7
+ class ERBLint < Runner
8
+ DEFAULT_CONFIG_FILENAME = '.erb-lint.yml'
9
+
10
+ def initialize(_, _ = nil)
11
+ super
12
+ @options = {}
13
+ load_config
14
+ @inspector = ::ERBLint::Runner.new(file_loader, @config)
15
+ end
16
+
17
+ def run
18
+ return [] unless @patches
19
+
20
+ @patches.select { |patch| valid_patch?(patch) }
21
+ .map { |patch| inspect(patch) }
22
+ .flatten.compact
23
+ end
24
+
25
+ def load_config
26
+ if File.exist?(config_filename)
27
+ config = ::ERBLint::RunnerConfig.new(file_loader.yaml(config_filename))
28
+ @config = ::ERBLint::RunnerConfig.default.merge(config)
29
+ else
30
+ warn "#{config_filename} not found: using default config".yellow
31
+ @config = RunnerConfig.default
32
+ end
33
+ @config.merge!(runner_config_override)
34
+ rescue Psych::SyntaxError => e
35
+ failure!("error parsing config: #{e.message}")
36
+ end
37
+
38
+ def config_filename
39
+ @config_filename ||= @options[:config] || ::ERBLint::CLI::DEFAULT_CONFIG_FILENAME
40
+ end
41
+
42
+ def file_loader
43
+ @file_loader ||= ::ERBLint::FileLoader.new(Dir.pwd)
44
+ end
45
+
46
+ def runner_config_override
47
+ ::ERBLint::RunnerConfig.new(
48
+ linters: {}.tap do |linters|
49
+ ::ERBLint::LinterRegistry.linters.map do |klass|
50
+ linters[klass.simple_name] = { 'enabled' => enabled_linter_classes.include?(klass) }
51
+ end
52
+ end
53
+ )
54
+ end
55
+
56
+ def enabled_linter_names
57
+ @enabled_linter_names ||=
58
+ @options[:enabled_linters] ||
59
+ known_linter_names
60
+ .select { |name| @config.for_linter(name.camelize).enabled? }
61
+ end
62
+
63
+ def enabled_linter_classes
64
+ @enabled_linter_classes ||= ::ERBLint::LinterRegistry.linters
65
+ .select { |klass| linter_can_run?(klass) && enabled_linter_names.include?(klass.simple_name.underscore) }
66
+ end
67
+
68
+ def known_linter_names
69
+ @known_linter_names ||= ::ERBLint::LinterRegistry.linters
70
+ .map(&:simple_name)
71
+ .map(&:underscore)
72
+ end
73
+
74
+ def linter_can_run?(klass)
75
+ !autocorrect? || klass.support_autocorrect?
76
+ end
77
+
78
+ def autocorrect?
79
+ @options[:autocorrect]
80
+ end
81
+
82
+ def valid_patch?(patch)
83
+ return false if patch.additions < 1
84
+ path = patch.new_file_full_path
85
+ erb_file?(path)
86
+ end
87
+
88
+ def inspect(patch)
89
+ processed_source = processed_source_for(patch)
90
+ @inspector.run(processed_source)
91
+ offences = @inspector.offenses
92
+ offences.map do |offence|
93
+ patch.added_lines
94
+ .select { |line| offence.line_range.include? line.new_lineno }# line.new_lineno == offence.line
95
+ .map { |line| new_message(offence, line) }
96
+ end
97
+ end
98
+
99
+ def new_message(offence, line)
100
+ path = line.patch.delta.new_file[:path]
101
+ level = :error
102
+
103
+ Message.new(path, line, level, offence.message, nil, self.class)
104
+ end
105
+
106
+ def erb_file?(path)
107
+ File.extname(path) == '.erb'
108
+ end
109
+
110
+ def processed_source_for(patch)
111
+ path = patch.new_file_full_path.to_s
112
+ file_content = File.read(path, encoding: "ISO8859-1:utf-8")
113
+ ::ERBLint::ProcessedSource.new(path, file_content)
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module ERBLintVersion
3
+ VERSION = '0.1.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'pronto/erb_lint/version'
5
+ require 'English'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'pronto-erb_lint'
9
+ s.version = Pronto::ERBLintVersion::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.author = 'tleish'
12
+ s.email = 'tleish@hotmail.com'
13
+ s.homepage = 'https://github.com/tleish/pronto-erb_lint'
14
+ s.summary = 'Pronto runner for ERB Lint, erb code analyzer'
15
+
16
+ s.licenses = ['MIT']
17
+ s.required_ruby_version = '>= 2.0.0'
18
+ s.rubygems_version = '1.8.23'
19
+
20
+ s.files = `git ls-files`.split($RS).reject do |file|
21
+ file =~ %r{^(?:
22
+ spec/.*
23
+ |Gemfile
24
+ |Rakefile
25
+ |\.rspec
26
+ |\.gitignore
27
+ |\.rubocop.yml
28
+ |\.travis.yml
29
+ )$}x
30
+ end
31
+ s.test_files = []
32
+ s.extra_rdoc_files = ['LICENSE', 'README.md']
33
+ s.require_paths = ['lib']
34
+
35
+ s.add_runtime_dependency('erb_lint', '~> 0.0.24')
36
+ s.add_runtime_dependency('pronto', '~> 0.9.0')
37
+ s.add_development_dependency('rake', '~> 12.0')
38
+ s.add_development_dependency('rspec', '~> 3.4')
39
+ s.add_development_dependency('rspec-its', '~> 1.2')
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-erb_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tleish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-01 00:00:00.000000000 Z
11
+ date: 2018-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb_lint
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.6.0
33
+ version: 0.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.6.0
40
+ version: 0.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +90,9 @@ extra_rdoc_files:
90
90
  files:
91
91
  - LICENSE
92
92
  - README.md
93
+ - lib/pronto/erb_lint.rb
94
+ - lib/pronto/erb_lint/version.rb
95
+ - pronto-erb_lint.gemspec
93
96
  homepage: https://github.com/tleish/pronto-erb_lint
94
97
  licenses:
95
98
  - MIT
@@ -110,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
113
  version: '0'
111
114
  requirements: []
112
115
  rubyforge_project:
113
- rubygems_version: 2.6.12
116
+ rubygems_version: 2.7.3
114
117
  signing_key:
115
118
  specification_version: 4
116
119
  summary: Pronto runner for ERB Lint, erb code analyzer