lint_trap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5da96ecc29117fe9f261fbc71fb1930d7cc45869
4
+ data.tar.gz: 854345788d30ce5c60677a78dc8359990203d4a3
5
+ SHA512:
6
+ metadata.gz: 1f9c5c8f19a2cb08fb97ef0df44c26ffc32c72a5cb792e1d8f5db7bb729a1620f7bbbb85173c0703bc7185ec376872d9cdf599d52644ce75b51f120b059c78e1
7
+ data.tar.gz: 504e8acee1251edd2d957ea5066186f3885d9ce605cd256c3b0ffd186c9a3f2d17b2188f899fb584a2945e2b2ff444406851c92c5cde4ab884c30303857f362a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lint_trap.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Allen Madsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # LintTrap
2
+
3
+ Parses the output of various linters. Designed for usage with [permpress](https://github.com/lintci/permpress) on [LintCI](http://www.lintci.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lint_trap'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lint_trap
20
+
21
+ ## Usage
22
+
23
+ ``` ruby
24
+ require 'lint_trap'
25
+ require 'stringio'
26
+
27
+ # This would typically be a stdout for another process
28
+ io = StringIO.new("bad.rb:2:7:4:Style/MethodName:convention:Use snake_case for methods.\n")
29
+
30
+ LintTrap.parse('rubocop', io) do |violation|
31
+ puts violation.inspect
32
+ end
33
+
34
+ # Output
35
+ # {:file=>"bad.rb", :line=>"2", :column=>"7", :length=>"4", :rule=>"Style/MethodName", :severity=>"convention", :message=>"Use snake_case for methods."}
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/[my-github-username]/lint_trap/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,32 @@
1
+ require_relative 'parsers/null_parser'
2
+ require_relative 'parsers/standard_parser'
3
+ require_relative 'parsers/vim_quickfix_parser'
4
+ require_relative 'parsers/csslint_parser'
5
+
6
+ module LintTrap
7
+ # Determines the appropriate parser for the given linter
8
+ module ParserFactory
9
+ class << self
10
+ def register(linter, parser)
11
+ @parsers ||= Hash.new{|h, k| h[k] = Parsers::NullParser}
12
+ @parsers[linter] = parser
13
+ end
14
+
15
+ def parser_for(linter)
16
+ @parsers[linter]
17
+ end
18
+ end
19
+
20
+ register 'standard', Parsers::StandardParser
21
+ register 'vim_quickfix', Parsers::VimQuickfixParser
22
+
23
+ register 'checkstyle', Parsers::StandardParser
24
+ register 'coffeelint', Parsers::StandardParser
25
+ register 'csslint', Parsers::CSSLintParser
26
+ register 'golint', Parsers::VimQuickfixParser
27
+ register 'jshint', Parsers::StandardParser
28
+ register 'jsonlint', Parsers::StandardParser
29
+ register 'rubocop', Parsers::StandardParser
30
+ register 'scsslint', Parsers::StandardParser
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module LintTrap
2
+ module Parsers
3
+ class BaseParser
4
+ class << self
5
+ def parse(io)
6
+ new(io).parse(&Proc.new)
7
+ end
8
+ end
9
+
10
+ def initialize(io)
11
+ @io = io
12
+ end
13
+
14
+ def parse
15
+ raise NotImplementedError, "Subclass #{self.class.name} must implement parse."
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'line_parser'
2
+
3
+ module LintTrap
4
+ module Parsers
5
+ # Handles parsing LintCI standard format
6
+ class CSSLintParser < LineParser
7
+
8
+ private
9
+
10
+ def violation_regex
11
+ /
12
+ (?<file>[^:]+):
13
+ \sline\s(?<line>\d+),
14
+ \scol\s(?<column>\d+),
15
+ \s(?<severity>\w+)\s-\s
16
+ (?<message>.+)
17
+ /x
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'base_parser'
2
+
3
+ module LintTrap
4
+ module Parsers
5
+ # Handles parsing line by line with regex
6
+ class LineParser < BaseParser
7
+ def parse
8
+ @io.each_line do |line|
9
+ next unless (violation = parse_line(line))
10
+
11
+ yield violation
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def parse_line(line)
18
+ return unless (match = line.match(violation_regex))
19
+
20
+ violation_fields.each_with_object({}) do |field, violation|
21
+ violation[field.to_sym] = if match.names.include?(field) && !match[field].empty?
22
+ match[field]
23
+ else
24
+ nil
25
+ end
26
+ end
27
+ end
28
+
29
+ def violation_fields
30
+ %w(file line column length rule severity message)
31
+ end
32
+
33
+ def violation_regex
34
+ raise NotImplementedError, "Subclass #{self.class.name} must implement violation_regex."
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'base_parser'
2
+
3
+ module LintTrap
4
+ module Parsers
5
+ # Handles parsing for unknown linters
6
+ class NullParser < BaseParser
7
+ def parse
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'line_parser'
2
+
3
+ module LintTrap
4
+ module Parsers
5
+ # Handles parsing LintCI standard format
6
+ class StandardParser < LineParser
7
+
8
+ private
9
+
10
+ def violation_regex
11
+ /
12
+ (?<file>[^:]+):
13
+ (?<line>[^:]*):
14
+ (?<column>[^:]*):
15
+ (?<length>[^:]*):
16
+ (?<rule>[^:]*):
17
+ (?<severity>[^:]*):
18
+ (?<message>.+)
19
+ /x
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'line_parser'
2
+
3
+ module LintTrap
4
+ module Parsers
5
+ # Handles parsing LintCI standard format
6
+ class VimQuickfixParser < LineParser
7
+
8
+ private
9
+
10
+ def violation_regex
11
+ /
12
+ (?<file>[^:]+):
13
+ (?<line>[^:]*):
14
+ (?<column>[^:]*):\s*
15
+ (?<message>.+)
16
+ /x
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module LintTrap
2
+ VERSION = "0.0.1"
3
+ end
data/lib/lint_trap.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'lint_trap/version'
2
+ require 'lint_trap/parser_factory'
3
+
4
+ # Parses linter output from IO
5
+ module LintTrap
6
+ class << self
7
+ def parse(linter, io, parser_name = nil)
8
+ parser = ParserFactory.parser_for(parser_name)
9
+ parser = ParserFactory.parser_for(linter) if parser_name.nil?
10
+
11
+ parser.parse(io, &Proc.new)
12
+ end
13
+ end
14
+ end
data/lint_trap.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lint_trap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lint_trap"
8
+ spec.version = LintTrap::VERSION
9
+ spec.authors = ["Allen Madsen"]
10
+ spec.email = ["blatyo@gmail.com"]
11
+ spec.summary = %q{Parses the output of various linters.}
12
+ spec.description = %q{Parses the output of various linters.}
13
+ spec.homepage = "https://github.com/lintci/lint_trap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry-byebug"
25
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap do
4
+ it 'has a version number' do
5
+ expect(LintTrap::VERSION).not_to be nil
6
+ end
7
+
8
+ describe '.parse' do
9
+ let(:io){StringIO.new("bad.rb:2:7:4:Style/MethodName:convention:Use snake_case for methods.\n")}
10
+
11
+ it 'yields the expected violations' do
12
+ expect{|b| LintTrap.parse('rubocop', io, &b)}.to yield_successive_args({
13
+ file: 'bad.rb',
14
+ line: '2',
15
+ column: '7',
16
+ length: '4',
17
+ rule: 'Style/MethodName',
18
+ severity: 'convention',
19
+ message: 'Use snake_case for methods.'
20
+ })
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::ParserFactory do
4
+ describe '.linter_for' do
5
+ it 'returns a NullParser when no valid linter is given' do
6
+ expect(described_class.parser_for('blah')).to eq(LintTrap::Parsers::NullParser)
7
+ end
8
+
9
+ it 'returns the StandardParser when a valid linter is given' do
10
+ expect(described_class.parser_for('rubocop')).to eq(LintTrap::Parsers::StandardParser)
11
+ end
12
+
13
+ it 'returns the VimQuickfixParser when the parser itself is specified' do
14
+ expect(described_class.parser_for('vim_quickfix')).to eq(LintTrap::Parsers::VimQuickfixParser)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Parsers::CSSLintParser do
4
+ let(:parser_output) do
5
+ "bad.css: line 2, col 5, Error - Using width with border can sometimes"\
6
+ " make elements larger than you expect.\n\n"
7
+ end
8
+ let(:io){StringIO.new(parser_output)}
9
+ subject(:parser){described_class}
10
+
11
+ describe '.parse' do
12
+ it 'parses violations from io' do
13
+ expect{|b| parser.parse(io, &b)}.to yield_successive_args(
14
+ {
15
+ file: 'bad.css',
16
+ line: '2',
17
+ column: '5',
18
+ length: nil,
19
+ rule: nil,
20
+ severity: 'Error',
21
+ message: 'Using width with border can sometimes make elements larger than you expect.'
22
+ }
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Parsers::StandardParser do
4
+ let(:parser_output) do
5
+ "bad.java:1:0::com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck:error:"\
6
+ "Missing a Javadoc comment.\n"\
7
+ "bad.coffee:1:::camel_case_classes:error:Class names should be camel cased\n"\
8
+ "bad.js:2:13::W030:warning:Expected an assignment or function call and instead saw an expression.\n"\
9
+ "bad.json:2:2:::error:Json strings must use double quotes\n"\
10
+ "bad.rb:2:7:4:Style/MethodName:convention:Use snake_case for methods.\n"\
11
+ "bad.scss:2:3:12:BorderZero:warning:`border: 0;` is preferred over `border: none;`\n"
12
+ end
13
+ let(:io){StringIO.new(parser_output)}
14
+ subject(:parser){described_class}
15
+
16
+ describe '.parse' do
17
+ it 'parses violations from io' do
18
+ expect{|b| parser.parse(io, &b)}.to yield_successive_args(
19
+ {
20
+ file: 'bad.java',
21
+ line: '1',
22
+ column: '0',
23
+ length: nil,
24
+ rule: 'com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck',
25
+ severity: 'error',
26
+ message: 'Missing a Javadoc comment.'
27
+ },
28
+ {
29
+ file: 'bad.coffee',
30
+ line: '1',
31
+ column: nil,
32
+ length: nil,
33
+ rule: 'camel_case_classes',
34
+ severity: 'error',
35
+ message: 'Class names should be camel cased'
36
+ },
37
+ {
38
+ file: 'bad.js',
39
+ line: '2',
40
+ column: '13',
41
+ length: nil,
42
+ rule: 'W030',
43
+ severity: 'warning',
44
+ message: 'Expected an assignment or function call and instead saw an expression.'
45
+ },
46
+ {
47
+ file: 'bad.json',
48
+ line: '2',
49
+ column: '2',
50
+ length: nil,
51
+ rule: nil,
52
+ severity: 'error',
53
+ message: 'Json strings must use double quotes'
54
+ },
55
+ {
56
+ file: 'bad.rb',
57
+ line: '2',
58
+ column: '7',
59
+ length: '4',
60
+ rule: 'Style/MethodName',
61
+ severity: 'convention',
62
+ message: 'Use snake_case for methods.'
63
+ },
64
+ {
65
+ file: 'bad.scss',
66
+ line: '2',
67
+ column: '3',
68
+ length: '12',
69
+ rule: 'BorderZero',
70
+ severity: 'warning',
71
+ message: '`border: 0;` is preferred over `border: none;`'
72
+ }
73
+ )
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Parsers::VimQuickfixParser do
4
+ let(:parser_output) do
5
+ "bad.go:5:1: exported function Main should have comment or be unexported\n"
6
+ end
7
+ let(:io){StringIO.new(parser_output)}
8
+ subject(:parser){described_class}
9
+
10
+ describe '.parse' do
11
+ it 'parses violations from io' do
12
+ expect{|b| parser.parse(io, &b)}.to yield_successive_args(
13
+ {
14
+ file: 'bad.go',
15
+ line: '5',
16
+ column: '1',
17
+ length: nil,
18
+ rule: nil,
19
+ severity: nil,
20
+ message: 'exported function Main should have comment or be unexported'
21
+ }
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'lint_trap'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lint_trap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Allen Madsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Parses the output of various linters.
70
+ email:
71
+ - blatyo@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/lint_trap.rb
83
+ - lib/lint_trap/parser_factory.rb
84
+ - lib/lint_trap/parsers/base_parser.rb
85
+ - lib/lint_trap/parsers/csslint_parser.rb
86
+ - lib/lint_trap/parsers/line_parser.rb
87
+ - lib/lint_trap/parsers/null_parser.rb
88
+ - lib/lint_trap/parsers/standard_parser.rb
89
+ - lib/lint_trap/parsers/vim_quickfix_parser.rb
90
+ - lib/lint_trap/version.rb
91
+ - lint_trap.gemspec
92
+ - spec/lint_trap_spec.rb
93
+ - spec/parser_factory_spec.rb
94
+ - spec/parsers/csslint_parser_spec.rb
95
+ - spec/parsers/standard_parser_spec.rb
96
+ - spec/parsers/vim_quickfix_parser_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/lintci/lint_trap
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Parses the output of various linters.
122
+ test_files:
123
+ - spec/lint_trap_spec.rb
124
+ - spec/parser_factory_spec.rb
125
+ - spec/parsers/csslint_parser_spec.rb
126
+ - spec/parsers/standard_parser_spec.rb
127
+ - spec/parsers/vim_quickfix_parser_spec.rb
128
+ - spec/spec_helper.rb