lint_trap 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +97 -0
  3. data/Dockerfile +222 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +45 -0
  6. data/circle.yml +22 -0
  7. data/config/checkstyle/checkstyle_logger-all.jar +0 -0
  8. data/config/checkstyle/sun_checks.xml +177 -0
  9. data/config/coffeelint/lint_trap.coffee +12 -0
  10. data/config/jshint/formatter.js +22 -0
  11. data/config/rubocop/formatter.rb +22 -0
  12. data/config/scsslint/scsslint +34 -0
  13. data/lib/lint_trap/command.rb +39 -0
  14. data/lib/lint_trap/container/base.rb +30 -0
  15. data/lib/lint_trap/container/docker.rb +46 -0
  16. data/lib/lint_trap/container/fake.rb +28 -0
  17. data/lib/lint_trap/language/base.rb +18 -0
  18. data/lib/lint_trap/language/coffeescript.rb +13 -0
  19. data/lib/lint_trap/language/cpp.rb +17 -0
  20. data/lib/lint_trap/language/css.rb +13 -0
  21. data/lib/lint_trap/language/go.rb +13 -0
  22. data/lib/lint_trap/language/java.rb +13 -0
  23. data/lib/lint_trap/language/javascript.rb +13 -0
  24. data/lib/lint_trap/language/json.rb +13 -0
  25. data/lib/lint_trap/language/python.rb +13 -0
  26. data/lib/lint_trap/language/ruby.rb +13 -0
  27. data/lib/lint_trap/language/scss.rb +13 -0
  28. data/lib/lint_trap/language.rb +50 -0
  29. data/lib/lint_trap/linter/base.rb +58 -0
  30. data/lib/lint_trap/linter/checkstyle.rb +24 -0
  31. data/lib/lint_trap/linter/coffeelint.rb +21 -0
  32. data/lib/lint_trap/linter/cppcheck.rb +18 -0
  33. data/lib/lint_trap/linter/csslint.rb +23 -0
  34. data/lib/lint_trap/linter/golint.rb +19 -0
  35. data/lib/lint_trap/linter/jshint.rb +20 -0
  36. data/lib/lint_trap/linter/jsonlint.rb +18 -0
  37. data/lib/lint_trap/linter/pylint.rb +19 -0
  38. data/lib/lint_trap/linter/rubocop.rb +22 -0
  39. data/lib/lint_trap/linter/scsslint.rb +22 -0
  40. data/lib/lint_trap/linter.rb +42 -0
  41. data/lib/lint_trap/{parsers/base_parser.rb → parser/base.rb} +8 -9
  42. data/lib/lint_trap/{parsers/csslint_parser.rb → parser/csslint.rb} +4 -5
  43. data/lib/lint_trap/{parsers/line_parser.rb → parser/line.rb} +14 -5
  44. data/lib/lint_trap/parser/standard.rb +22 -0
  45. data/lib/lint_trap/parser/vim_quickfix.rb +19 -0
  46. data/lib/lint_trap/version.rb +1 -1
  47. data/lib/lint_trap.rb +5 -14
  48. data/lint_trap.gemspec +3 -0
  49. data/spec/command_spec.rb +38 -0
  50. data/spec/container/docker_spec.rb +34 -0
  51. data/spec/container/fake_spec.rb +29 -0
  52. data/spec/fixtures/Good.java +6 -0
  53. data/spec/fixtures/bad.coffee +1 -0
  54. data/spec/fixtures/bad.cpp +5 -0
  55. data/spec/fixtures/bad.css +4 -0
  56. data/spec/fixtures/bad.go +7 -0
  57. data/spec/fixtures/bad.java +3 -0
  58. data/spec/fixtures/bad.js +3 -0
  59. data/spec/fixtures/bad.json +4 -0
  60. data/spec/fixtures/bad.py +2 -0
  61. data/spec/fixtures/bad.rb +4 -0
  62. data/spec/fixtures/bad.scss +3 -0
  63. data/spec/fixtures/good.coffee +1 -0
  64. data/spec/fixtures/good.cpp +4 -0
  65. data/spec/fixtures/good.css +3 -0
  66. data/spec/fixtures/good.go +7 -0
  67. data/spec/fixtures/good.js +5 -0
  68. data/spec/fixtures/good.json +4 -0
  69. data/spec/fixtures/good.py +6 -0
  70. data/spec/fixtures/good.rb +5 -0
  71. data/spec/fixtures/good.scss +3 -0
  72. data/spec/fixtures/lint.txt +1 -0
  73. data/spec/integration/checkstyle_spec.rb +52 -0
  74. data/spec/integration/coffeelint_spec.rb +44 -0
  75. data/spec/integration/cppcheck_spec.rb +60 -0
  76. data/spec/integration/csslint_spec.rb +44 -0
  77. data/spec/integration/golint_spec.rb +44 -0
  78. data/spec/integration/jshint_spec.rb +70 -0
  79. data/spec/integration/jsonlint_spec.rb +60 -0
  80. data/spec/integration/pylint_spec.rb +51 -0
  81. data/spec/integration/rubocop_spec.rb +52 -0
  82. data/spec/integration/scsslint_spec.rb +44 -0
  83. data/spec/language/coffeescript_spec.rb +8 -0
  84. data/spec/language/cpp_spec.rb +8 -0
  85. data/spec/language/css_spec.rb +8 -0
  86. data/spec/language/go_spec.rb +8 -0
  87. data/spec/language/java_spec.rb +8 -0
  88. data/spec/language/javascript_spec.rb +8 -0
  89. data/spec/language/json_spec.rb +8 -0
  90. data/spec/language/python_spec.rb +8 -0
  91. data/spec/language/ruby_spec.rb +8 -0
  92. data/spec/language/scss_spec.rb +8 -0
  93. data/spec/language_spec.rb +143 -0
  94. data/spec/lint_trap_spec.rb +0 -16
  95. data/spec/linter/checkstyle_spec.rb +45 -0
  96. data/spec/linter/coffeelint_spec.rb +46 -0
  97. data/spec/linter/cppcheck_spec.rb +26 -0
  98. data/spec/linter/csslint_spec.rb +44 -0
  99. data/spec/linter/golint_spec.rb +22 -0
  100. data/spec/linter/jshint_spec.rb +44 -0
  101. data/spec/linter/jsonlint_spec.rb +22 -0
  102. data/spec/linter/pylint_spec.rb +46 -0
  103. data/spec/linter/rubocop_spec.rb +48 -0
  104. data/spec/linter/scsslint_spec.rb +44 -0
  105. data/spec/linter_spec.rb +67 -0
  106. data/spec/parser/csslint_spec.rb +25 -0
  107. data/spec/{parsers/standard_parser_spec.rb → parser/standard_spec.rb} +4 -3
  108. data/spec/{parsers/vim_quickfix_parser_spec.rb → parser/vim_quickfix_spec.rb} +5 -4
  109. data/spec/spec_helper.rb +8 -0
  110. data/spec/support/fixture_file_helper.rb +8 -0
  111. metadata +193 -18
  112. data/lib/lint_trap/parser_factory.rb +0 -32
  113. data/lib/lint_trap/parsers/null_parser.rb +0 -11
  114. data/lib/lint_trap/parsers/standard_parser.rb +0 -23
  115. data/lib/lint_trap/parsers/vim_quickfix_parser.rb +0 -20
  116. data/spec/parser_factory_spec.rb +0 -17
  117. data/spec/parsers/csslint_parser_spec.rb +0 -26
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::CSSLint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.css bad.css)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ context 'when config is provided' do
12
+ let(:config){'.csslintrc'}
13
+
14
+ it 'runs the lint command with the correct arguments' do
15
+ expect(LintTrap::Command).to receive(:new).with(
16
+ 'csslint',
17
+ [
18
+ '--format=compact',
19
+ '--config=.csslintrc'
20
+ ],
21
+ files
22
+ ).and_return(command)
23
+ expect(command).to receive(:run).with(container)
24
+
25
+ linter.lint(files)
26
+ end
27
+ end
28
+
29
+ context 'when config is not provided' do
30
+ it 'runs the lint command with the correct arguments' do
31
+ expect(LintTrap::Command).to receive(:new).with(
32
+ 'csslint',
33
+ [
34
+ '--format=compact'
35
+ ],
36
+ files
37
+ ).and_return(command)
38
+ expect(command).to receive(:run).with(container)
39
+
40
+ linter.lint(files)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::GoLint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.go bad.go)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ it 'runs the lint command with the correct arguments' do
12
+ expect(LintTrap::Command).to receive(:new).with(
13
+ 'golint',
14
+ [],
15
+ files
16
+ ).and_return(command)
17
+ expect(command).to receive(:run).with(container)
18
+
19
+ linter.lint(files)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::JSHint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.js bad.js)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ context 'when config is provided' do
12
+ let(:config){'.jshintrc'}
13
+
14
+ it 'runs the lint command with the correct arguments' do
15
+ expect(LintTrap::Command).to receive(:new).with(
16
+ 'jshint',
17
+ [
18
+ '--reporter', container.config_path(described_class::FORMATTER),
19
+ '--config', config
20
+ ],
21
+ files
22
+ ).and_return(command)
23
+ expect(command).to receive(:run).with(container)
24
+
25
+ linter.lint(files)
26
+ end
27
+ end
28
+
29
+ context 'when config is not provided' do
30
+ it 'runs the lint command with the correct arguments' do
31
+ expect(LintTrap::Command).to receive(:new).with(
32
+ 'jshint',
33
+ [
34
+ '--reporter', container.config_path(described_class::FORMATTER)
35
+ ],
36
+ files
37
+ ).and_return(command)
38
+ expect(command).to receive(:run).with(container)
39
+
40
+ linter.lint(files)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::JSONLint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.go bad.go)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ it 'runs the lint command with the correct arguments' do
12
+ expect(LintTrap::Command).to receive(:new).with(
13
+ 'durable-json-lint',
14
+ ['--format', '{{file}}:{{line}}:{{column}}:::error:{{{description}}}'],
15
+ files
16
+ ).and_return(command)
17
+ expect(command).to receive(:run).with(container)
18
+
19
+ linter.lint(files)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::PyLint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.py bad.py)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ context 'when config is provided' do
12
+ let(:config){'.pylintrc'}
13
+
14
+ it 'runs the lint command with the correct arguments' do
15
+ expect(LintTrap::Command).to receive(:new).with(
16
+ 'pylint',
17
+ [
18
+ '-r', 'no',
19
+ '--msg-template', '"{abspath}:{line}:{column}::{symbol}:{category}:{msg}"',
20
+ '--rcfile', config
21
+ ],
22
+ files
23
+ ).and_return(command)
24
+ expect(command).to receive(:run).with(container)
25
+
26
+ linter.lint(files)
27
+ end
28
+ end
29
+
30
+ context 'when config is not provided' do
31
+ it 'runs the lint command with the correct arguments' do
32
+ expect(LintTrap::Command).to receive(:new).with(
33
+ 'pylint',
34
+ [
35
+ '-r', 'no',
36
+ '--msg-template', '"{abspath}:{line}:{column}::{symbol}:{category}:{msg}"'
37
+ ],
38
+ files
39
+ ).and_return(command)
40
+ expect(command).to receive(:run).with(container)
41
+
42
+ linter.lint(files)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::RuboCop do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.rb bad.rb)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ context 'when config is provided' do
12
+ let(:config){'.rubocop.yml'}
13
+
14
+ it 'runs the lint command with the correct arguments' do
15
+ expect(LintTrap::Command).to receive(:new).with(
16
+ 'rubocop',
17
+ [
18
+ '--require', container.config_path(described_class::FORMATTER),
19
+ '--format', 'LintTrap::Rubocop::Formatter',
20
+ '--no-color',
21
+ '--config', config
22
+ ],
23
+ files
24
+ ).and_return(command)
25
+ expect(command).to receive(:run).with(container)
26
+
27
+ linter.lint(files)
28
+ end
29
+ end
30
+
31
+ context 'when config is not provided' do
32
+ it 'runs the lint command with the correct arguments' do
33
+ expect(LintTrap::Command).to receive(:new).with(
34
+ 'rubocop',
35
+ [
36
+ '--require', container.config_path(described_class::FORMATTER),
37
+ '--format', 'LintTrap::Rubocop::Formatter',
38
+ '--no-color'
39
+ ],
40
+ files
41
+ ).and_return(command)
42
+ expect(command).to receive(:run).with(container)
43
+
44
+ linter.lint(files)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter::SCSSLint do
4
+ let(:container){LintTrap::Container::Fake.new}
5
+ let(:config){nil}
6
+ let(:files){%w(good.scss bad.scss)}
7
+ subject(:linter){described_class.new(container: container, config: config)}
8
+ let(:command){instance_double(LintTrap::Command)}
9
+
10
+ describe '#lint' do
11
+ context 'when config is provided' do
12
+ let(:config){'.scss-lint.yml'}
13
+
14
+ it 'runs the lint command with the correct arguments' do
15
+ expect(LintTrap::Command).to receive(:new).with(
16
+ container.config_path(described_class::COMMAND),
17
+ [
18
+ '--format=LintTrap',
19
+ '--config', '.scss-lint.yml'
20
+ ],
21
+ files
22
+ ).and_return(command)
23
+ expect(command).to receive(:run).with(container)
24
+
25
+ linter.lint(files)
26
+ end
27
+ end
28
+
29
+ context 'when config is not provided' do
30
+ it 'runs the lint command with the correct arguments' do
31
+ expect(LintTrap::Command).to receive(:new).with(
32
+ container.config_path(described_class::COMMAND),
33
+ [
34
+ '--format=LintTrap'
35
+ ],
36
+ files
37
+ ).and_return(command)
38
+ expect(command).to receive(:run).with(container)
39
+
40
+ linter.lint(files)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Linter do
4
+ describe '.find' do
5
+ subject(:language){described_class.find(linter_name)}
6
+
7
+ context 'when given CheckStyle' do
8
+ let(:linter_name){'CheckStyle'}
9
+
10
+ it{is_expected.to eq(described_class::CheckStyle)}
11
+ end
12
+
13
+ context 'when given CoffeeLint' do
14
+ let(:linter_name){'CoffeeLint'}
15
+
16
+ it{is_expected.to eq(described_class::CoffeeLint)}
17
+ end
18
+
19
+ context 'when given CPPCheck' do
20
+ let(:linter_name){'CPPCheck'}
21
+
22
+ it{is_expected.to eq(described_class::CPPCheck)}
23
+ end
24
+
25
+ context 'when given CSSLint' do
26
+ let(:linter_name){'CSSLint'}
27
+
28
+ it{is_expected.to eq(described_class::CSSLint)}
29
+ end
30
+
31
+ context 'when given GoLint' do
32
+ let(:linter_name){'GoLint'}
33
+
34
+ it{is_expected.to eq(described_class::GoLint)}
35
+ end
36
+
37
+ context 'when given JSHint' do
38
+ let(:linter_name){'JSHint'}
39
+
40
+ it{is_expected.to eq(described_class::JSHint)}
41
+ end
42
+
43
+ context 'when given JSONLint' do
44
+ let(:linter_name){'JSONLint'}
45
+
46
+ it{is_expected.to eq(described_class::JSONLint)}
47
+ end
48
+
49
+ context 'when given PyLint' do
50
+ let(:linter_name){'PyLint'}
51
+
52
+ it{is_expected.to eq(described_class::PyLint)}
53
+ end
54
+
55
+ context 'when given RuboCop' do
56
+ let(:linter_name){'RuboCop'}
57
+
58
+ it{is_expected.to eq(described_class::RuboCop)}
59
+ end
60
+
61
+ context 'when given SCSSLint' do
62
+ let(:linter_name){'SCSSLint'}
63
+
64
+ it{is_expected.to eq(described_class::SCSSLint)}
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe LintTrap::Parser::CSSLint 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
+ let(:container){LintTrap::Container::Fake.new}
10
+ subject(:parser){described_class.new(io, container)}
11
+
12
+ describe '.parse' do
13
+ it 'parses violations from io' do
14
+ expect{|b| parser.parse(&b)}.to yield_successive_args(
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
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LintTrap::Parsers::StandardParser do
3
+ describe LintTrap::Parser::Standard do
4
4
  let(:parser_output) do
5
5
  "bad.java:1:0::com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck:error:"\
6
6
  "Missing a Javadoc comment.\n"\
@@ -11,11 +11,12 @@ describe LintTrap::Parsers::StandardParser do
11
11
  "bad.scss:2:3:12:BorderZero:warning:`border: 0;` is preferred over `border: none;`\n"
12
12
  end
13
13
  let(:io){StringIO.new(parser_output)}
14
- subject(:parser){described_class}
14
+ let(:container){LintTrap::Container::Fake.new}
15
+ subject(:parser){described_class.new(io, container)}
15
16
 
16
17
  describe '.parse' do
17
18
  it 'parses violations from io' do
18
- expect{|b| parser.parse(io, &b)}.to yield_successive_args(
19
+ expect{|b| parser.parse(&b)}.to yield_successive_args(
19
20
  {
20
21
  file: 'bad.java',
21
22
  line: '1',
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LintTrap::Parsers::VimQuickfixParser do
3
+ describe LintTrap::Parser::VimQuickfix do
4
4
  let(:parser_output) do
5
5
  "bad.go:5:1: exported function Main should have comment or be unexported\n"
6
6
  end
7
7
  let(:io){StringIO.new(parser_output)}
8
- subject(:parser){described_class}
8
+ let(:container){LintTrap::Container::Fake.new}
9
+ subject(:parser){described_class.new(io, container)}
9
10
 
10
- describe '.parse' do
11
+ describe '#parse' do
11
12
  it 'parses violations from io' do
12
- expect{|b| parser.parse(io, &b)}.to yield_successive_args(
13
+ expect{|b| parser.parse(&b)}.to yield_successive_args(
13
14
  {
14
15
  file: 'bad.go',
15
16
  line: '5',
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,10 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rspec/its'
2
3
  require 'lint_trap'
4
+ require_relative 'support/fixture_file_helper'
5
+
6
+ ENV['DEBUG_LINTING'] = ENV['CI']
7
+
8
+ RSpec.configure do |config|
9
+ config.include FixtureFileHelper
10
+ end
@@ -0,0 +1,8 @@
1
+ # Simplifies referencing fixture files
2
+ module FixtureFileHelper
3
+ FIXTURE_PATH = File.expand_path('../../fixtures', __FILE__)
4
+
5
+ def fixture_path(path = '')
6
+ File.join(FIXTURE_PATH, path)
7
+ end
8
+ end