codeqa 0.3.0

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.codeqa.rb +22 -0
  3. data/.gitignore +20 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +93 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +10 -0
  8. data/.vimrc +1 -0
  9. data/CHANGELOG +8 -0
  10. data/Gemfile +18 -0
  11. data/Guardfile +21 -0
  12. data/LICENSE +22 -0
  13. data/README.md +97 -0
  14. data/Rakefile +19 -0
  15. data/bin/codeqa +75 -0
  16. data/codeqa.gemspec +21 -0
  17. data/config/default.rb +42 -0
  18. data/lib/codeqa/check_errors.rb +21 -0
  19. data/lib/codeqa/checker.rb +47 -0
  20. data/lib/codeqa/checkers/check_conflict.rb +28 -0
  21. data/lib/codeqa/checkers/check_erb.rb +48 -0
  22. data/lib/codeqa/checkers/check_erb_html.rb +42 -0
  23. data/lib/codeqa/checkers/check_linkto.rb +28 -0
  24. data/lib/codeqa/checkers/check_pry.rb +28 -0
  25. data/lib/codeqa/checkers/check_rspec_focus.rb +28 -0
  26. data/lib/codeqa/checkers/check_ruby_syntax.rb +25 -0
  27. data/lib/codeqa/checkers/check_strange_chars.rb +29 -0
  28. data/lib/codeqa/checkers/check_utf8_encoding.rb +22 -0
  29. data/lib/codeqa/checkers/check_yard.rb +55 -0
  30. data/lib/codeqa/checkers/pattern_checker.rb +26 -0
  31. data/lib/codeqa/checkers/rubocop_formatter.rb +29 -0
  32. data/lib/codeqa/checkers/rubocop_full.rb +53 -0
  33. data/lib/codeqa/checkers/rubocop_lint.rb +21 -0
  34. data/lib/codeqa/configuration.rb +94 -0
  35. data/lib/codeqa/fake_erb.rb +80 -0
  36. data/lib/codeqa/runner.rb +61 -0
  37. data/lib/codeqa/runner_decorator.rb +84 -0
  38. data/lib/codeqa/sourcefile.rb +50 -0
  39. data/lib/codeqa/version.rb +3 -0
  40. data/lib/codeqa.rb +78 -0
  41. data/lib/templates/pre-commit +50 -0
  42. data/spec/fixtures/html_error.html.erb +10 -0
  43. data/spec/fixtures/html_error.text.html +3 -0
  44. data/spec/fixtures/isolation/home/project/dir/.gitkeep +0 -0
  45. data/spec/fixtures/isolation/home/project/file.rb +1 -0
  46. data/spec/fixtures/isolation/home/project/ignored/some_file.txt +1 -0
  47. data/spec/fixtures/ruby.rb +3 -0
  48. data/spec/fixtures/ruby_error.rb +3 -0
  49. data/spec/lib/codeqa/checkers/check_conflict_spec.rb +30 -0
  50. data/spec/lib/codeqa/checkers/check_erb_html_spec.rb +72 -0
  51. data/spec/lib/codeqa/checkers/check_erb_spec.rb +31 -0
  52. data/spec/lib/codeqa/checkers/check_linkto_spec.rb +26 -0
  53. data/spec/lib/codeqa/checkers/check_pry_spec.rb +25 -0
  54. data/spec/lib/codeqa/checkers/check_rspec_focus_spec.rb +25 -0
  55. data/spec/lib/codeqa/checkers/check_ruby_syntax_spec.rb +26 -0
  56. data/spec/lib/codeqa/checkers/check_strange_chars_spec.rb +27 -0
  57. data/spec/lib/codeqa/checkers/check_utf8_encoding_spec.rb +26 -0
  58. data/spec/lib/codeqa/checkers/check_yard_spec.rb +21 -0
  59. data/spec/lib/codeqa/checkers/rubocop_formatter_spec.rb +5 -0
  60. data/spec/lib/codeqa/checkers/rubocop_full_spec.rb +5 -0
  61. data/spec/lib/codeqa/checkers/rubocop_lint_spec.rb +26 -0
  62. data/spec/lib/codeqa/configuration_spec.rb +52 -0
  63. data/spec/lib/codeqa/runner_decorator_spec.rb +19 -0
  64. data/spec/lib/codeqa/runner_spec.rb +5 -0
  65. data/spec/lib/codeqa/sourcefile_spec.rb +33 -0
  66. data/spec/lib/codeqa_spec.rb +52 -0
  67. data/spec/spec_helper.rb +56 -0
  68. data/spec/support/checker.rb +20 -0
  69. metadata +183 -0
@@ -0,0 +1,84 @@
1
+ module Codeqa
2
+ class RunnerDecorator
3
+ def initialize(runner, options={})
4
+ @options = { :colors => true }.merge(options)
5
+ @runner = runner
6
+ @msg = ''
7
+ end
8
+
9
+ def sourcefile_to_s
10
+ info("Codeqa on :'#{@runner.sourcefile.filename}'\n")
11
+ end
12
+
13
+ def success_to_s
14
+ if @runner.success?
15
+ success("Passed tests: #{@runner.results.map(&:name).join(', ')}\n")
16
+ else
17
+ error("Failed tests: #{@runner.failures.map(&:name).join(', ')}\n")
18
+ end
19
+ end
20
+
21
+ def details_to_s
22
+ error_details
23
+ end
24
+
25
+ def to_s
26
+ @msg << sourcefile_to_s
27
+ @msg << success_to_s
28
+ @msg << details_to_s unless @runner.success?
29
+
30
+ @msg
31
+ end
32
+
33
+ private
34
+
35
+ def error_details
36
+ msg = ''
37
+ @runner.failures.each do |checker|
38
+ msg << error("------- #{checker.name} -------\n")
39
+ msg << error("#{checker.hint}\n")
40
+ checker.errors.details.each do |detail|
41
+ msg << info("#{detail[1]}\n")
42
+ end
43
+ end
44
+ msg
45
+ end
46
+
47
+ # http://stackoverflow.com/questions/1489183/colorized-ruby-output
48
+ def info(txt)
49
+ txt
50
+ end
51
+
52
+ def error(txt)
53
+ red(txt)
54
+ end
55
+
56
+ def success(txt)
57
+ green(txt)
58
+ end
59
+
60
+ def colorize(color_code, txt)
61
+ if @options[:colors]
62
+ "\e[#{color_code}m#{txt}\e[0m"
63
+ else
64
+ txt
65
+ end
66
+ end
67
+
68
+ def red(txt)
69
+ colorize(31, txt)
70
+ end
71
+
72
+ def green(txt)
73
+ colorize(32, txt)
74
+ end
75
+
76
+ # def yellow(txt)
77
+ # colorize(33, txt)
78
+ # end
79
+
80
+ # def pink(txt)
81
+ # colorize(35, txt)
82
+ # end
83
+ end
84
+ end
@@ -0,0 +1,50 @@
1
+ module Codeqa
2
+ class Sourcefile
3
+ BINARY_PATTERN = /\.(swf|jpg|png|gif|pdf|xls|zip|eot|woff|ttf|mo|so|gem)$/
4
+ ERB_PATTERN = /\.(erb|rhtml|text\.html|text\.plain)$/
5
+ HTML_PATTERN = /\.(rhtml|html|text\.html)/
6
+ RUBY_PATTERN = /\.(rb|gemspec)$/
7
+ RUBY_NAMES = %w(Guardfile Gemfile Rakefile config.ru)
8
+ SPEC_PATTERN = /_spec\.rb$/
9
+
10
+ def initialize(filename, content=nil)
11
+ @filename = filename
12
+ @content = content
13
+ # ensure_file
14
+ end
15
+
16
+ attr_reader :filename
17
+
18
+ def content
19
+ @content ||= File.read(filename)
20
+ end
21
+
22
+ def exist?
23
+ File.exist?(filename)
24
+ end
25
+
26
+ def text?
27
+ !binary?
28
+ end
29
+
30
+ def binary?
31
+ @binary ||= !!(filename =~ BINARY_PATTERN)
32
+ end
33
+
34
+ def ruby?
35
+ @ruby ||= (RUBY_NAMES.include?(filename) || !!(filename =~ RUBY_PATTERN))
36
+ end
37
+
38
+ def erb?
39
+ @erb ||= !!(filename =~ ERB_PATTERN)
40
+ end
41
+
42
+ def html?
43
+ @html ||= !!(filename =~ HTML_PATTERN) && !ruby?
44
+ end
45
+
46
+ def spec?
47
+ @spec ||= !!(filename =~ SPEC_PATTERN)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Codeqa
2
+ VERSION = '0.3.0'
3
+ end
data/lib/codeqa.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'pathname'
2
+ module Codeqa
3
+ CODEQA_HOME = Pathname.new(File.join(File.dirname(__FILE__), '..')).realpath
4
+
5
+ class << self
6
+ def root
7
+ CODEQA_HOME
8
+ end
9
+
10
+ def install(root='.')
11
+ require 'fileutils'
12
+ git_root = Pathname.new "#{root}/.git"
13
+ if File.exist?(git_root)
14
+ pre_commit_path = git_root.join 'hooks', 'pre-commit'
15
+ if File.exist?(pre_commit_path)
16
+ # $stdout.puts 'moving away the old pre-commit hook -> pre-commit.bkp'
17
+ FileUtils.mv(pre_commit_path,
18
+ git_root.join('hooks', 'pre-commit.bkp'),
19
+ :force => true)
20
+ end
21
+ pre_commit_template_path = Codeqa.root.join('lib', 'templates', 'pre-commit')
22
+ # $stdout.puts 'placing new pre-commit hook'
23
+ FileUtils.cp(pre_commit_template_path, pre_commit_path)
24
+ FileUtils.chmod('+x', pre_commit_path)
25
+ true
26
+ else
27
+ # $stderr.puts "#{root} is not in a git root"
28
+ false
29
+ end
30
+ end
31
+
32
+ def check(filename, options={})
33
+ options = { :silent_success => false, :silent => false }.merge(options)
34
+ runner = runner(filename)
35
+ if runner.success?
36
+ $stdout.puts(runner.display_result) unless options[:silent_success] || options[:silent]
37
+ true
38
+ else
39
+ $stderr.puts runner.display_result unless options[:silent]
40
+ false
41
+ end
42
+ end
43
+
44
+ def runner(filename)
45
+ sourcefile = Codeqa::Sourcefile.new(filename)
46
+ Codeqa::Runner.run(sourcefile)
47
+ end
48
+
49
+ def register_checkers
50
+ Codeqa::Runner.reset_checkers
51
+ configuration.enabled_checker.each do |checker|
52
+ begin
53
+ checker_klass = Codeqa::Checkers.const_get(checker)
54
+ next unless checker_klass.available?
55
+ Codeqa::Runner.register_checker checker_klass
56
+ rescue
57
+ "checker <#{checker}> not known"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ require 'codeqa/version'
65
+ require 'codeqa/sourcefile'
66
+ require 'codeqa/checker'
67
+ require 'codeqa/check_errors'
68
+ require 'codeqa/runner'
69
+ require 'codeqa/runner_decorator'
70
+
71
+ require 'codeqa/configuration'
72
+
73
+ # load all files in checkers subfolder
74
+ Dir.glob(Codeqa.root.join('lib/codeqa/checkers/*.rb')) do |file|
75
+ require "codeqa/checkers/#{file[%r{/([^/]+)\.rb}, 1]}"
76
+ end
77
+
78
+ Codeqa.register_checkers
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def staged_files
4
+ @staged_files ||= begin
5
+ files = `git diff --cached --name-only --diff-filter=ACM`.split
6
+ files.reject do |f|
7
+ if File.ftype(f) != 'file'
8
+ true
9
+ else
10
+ size = File.size(f)
11
+ size > 1_000_000 || (size > 20 && binary?(f))
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ # from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90
18
+ def binary?(file)
19
+ return true if File.ftype(file) != 'file'
20
+ s = (File.read(file, File.stat(file).blksize) || '').split(//)
21
+ ((s.size - s.grep(' '..'~').size) / s.size.to_f) > 0.30
22
+ end
23
+
24
+ begin
25
+ require 'bundler/setup'
26
+ require 'codeqa'
27
+ rescue LoadError
28
+ puts "can't find codeqa in current bundle"
29
+ exit 1
30
+ end
31
+
32
+ files_to_check = staged_files.
33
+ map{ |e| Pathname.new(e).realpath.to_s }.
34
+ reject{ |e| File.directory?(e) || Codeqa.configuration.excluded?(e) }.
35
+ uniq
36
+
37
+ print "Codeqa checking #{files_to_check.count} files"
38
+ # fail fast
39
+ success = files_to_check.all? do |file|
40
+ print '.'
41
+ Codeqa.check(file, :silent => true)
42
+ end
43
+
44
+ if success
45
+ puts 'success'
46
+ exit 0
47
+ else
48
+ puts 'error'
49
+ exit 1
50
+ end
@@ -0,0 +1,10 @@
1
+ <div>
2
+ some close tag error </li>
3
+ </div>
4
+
5
+ <div open_attribute="error another="ok">
6
+ </div>
7
+
8
+ <div open_till_end="error>
9
+ </div>
10
+
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <% def erb_error %>
3
+ </div>
File without changes
@@ -0,0 +1 @@
1
+ p 'this is a ruby file'
@@ -0,0 +1,3 @@
1
+ class Foo
2
+ attr_reader :bar
3
+ end
@@ -0,0 +1,3 @@
1
+ class Ok Ok
2
+ def foo
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckConflict do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check text files' do
7
+ source = source_with
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect ======== and <<<<<<< and >>>>>>>' do
14
+ source = source_with("first line\n<<<<<<<\n=======\nthirdline\n>>>>>>>")
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details).to eq([
18
+ ['2,1', 'conflict leftovers in line 2, please merge properly'],
19
+ ['3,1', 'conflict leftovers in line 3, please merge properly'],
20
+ ['5,1', 'conflict leftovers in line 5, please merge properly']
21
+ ])
22
+ end
23
+
24
+ it 'should find not find if not there ' do
25
+ source = source_with("first line\n<<<<<<\n======\nthirdline\n>>>>>>")
26
+ checker = check_with(described_class, source)
27
+ expect(checker).to be_success
28
+ end
29
+
30
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ # there is no tidy on travis-ci so we can't test this checker there
3
+ unless ENV['TRAVIS']
4
+ describe Codeqa::Checkers::CheckErbHtml do
5
+ it_behaves_like 'a checker'
6
+
7
+ it 'should check erb files' do
8
+ source = source_with('', 'file.html.erb')
9
+ expect(described_class.check?(source)).to be_truthy
10
+ source = source_with('', 'test.rhtml')
11
+ expect(described_class.check?(source)).to be_truthy
12
+ source = source_with('', 'test.text.html')
13
+ expect(described_class.check?(source)).to be_truthy
14
+
15
+ source = source_with('', 'zipped.zip')
16
+ expect(described_class.check?(source)).to be_falsey
17
+ end
18
+
19
+ it 'should detect html tag errors' do
20
+ source = source_with('<div><ul></div>')
21
+ checker = check_with(described_class, source)
22
+ expect(checker).to be_error
23
+ expect(checker.errors.details).to eq([
24
+ [nil, '<div><ul></div>'],
25
+ [nil, "line 1 column 10 - Error: unexpected </div> in <ul>\n"]])
26
+ end
27
+
28
+ it 'should detect attribute till end of file errors' do
29
+ source = source_with("<div class='halfopen></div>")
30
+ checker = check_with(described_class, source)
31
+ expect(checker).to be_error
32
+ expect(checker.errors.details).to eq([
33
+ [nil, "<div class='halfopen></div>"],
34
+ [nil, "line 1 column 28 - Warning: <div> end of file while parsing attributes\n"]])
35
+
36
+ end
37
+ it 'should detect attribute with missing trailing qute mark' do
38
+ source = source_with('<div class="halfopen next="ok"></div>')
39
+ checker = check_with(described_class, source)
40
+ expect(checker).to be_error
41
+ expect(checker.errors.details).to eq([
42
+ [nil, "<div class=\"halfopen next=\"ok\"></div>"],
43
+ [nil, "line 1 column 1 - Warning: <div> attribute with missing trailing quote mark\n"]])
44
+
45
+ end
46
+
47
+ it 'should find not find errors if html is ok ' do
48
+ source = source_with('<div><ul></ul></div>')
49
+ checker = check_with(described_class, source)
50
+ expect(checker).to be_success
51
+ end
52
+
53
+ it 'should ignore javascript' do
54
+ source = source_with('<div><script></ul></script></div>')
55
+ checker = check_with(described_class, source)
56
+ expect(checker).to be_success
57
+ end
58
+ it 'should ignore javascript' do
59
+ source = source_with('<div><script type="text/javascript" charset="utf-8"></ul></script></div>')
60
+ checker = check_with(described_class, source)
61
+ expect(checker).to be_success
62
+ source = source_with("<div><script>multiline\n</ul></script></div>")
63
+ checker = check_with(described_class, source)
64
+ expect(checker).to be_success
65
+ end
66
+ it 'should ignore javascript' do
67
+ source = source_with('<div><style></ul></style></div>')
68
+ checker = check_with(described_class, source)
69
+ expect(checker).to be_success
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckErb do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check erb files' do
7
+ source = source_with('', 'file.html.erb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'test.rhtml')
10
+ expect(described_class.check?(source)).to be_truthy
11
+ source = source_with('', 'test.text.html')
12
+ expect(described_class.check?(source)).to be_truthy
13
+ source = source_with('', 'zipped.zip')
14
+ expect(described_class.check?(source)).to be_falsey
15
+ end
16
+
17
+ it 'should detect syntax errors in the erb' do
18
+ source = source_with('blub<%= def syntax %> ok')
19
+ checker = check_with(described_class, source)
20
+ expect(checker.errors?).to be true
21
+ str = checker.errors.details[0][1]
22
+
23
+ expect(str).to match(Regexp.new(Regexp.escape('(erb):1: syntax error, unexpected end-of-input, expect')))
24
+ end
25
+ it 'should be successfull for valid erb' do
26
+ source = source_with('blub<%= var %> ok')
27
+ checker = check_with(described_class, source)
28
+ expect(checker.success?).to be true
29
+ end
30
+
31
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckLinkto do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check erb files' do
7
+ source = source_with('', 'file.html.erb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect <% link_to ... do ... %>' do
14
+ source = source_with("<% link_to '/page',do_some_paths do%>", 'file.html.erb')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details).to eq([['1,1', 'old style block link_to in line 1']])
18
+ end
19
+
20
+ it 'should find not find if not there ' do
21
+ source = source_with("<%= link_to '/page',do_some_paths do%>", 'file.html.erb')
22
+ checker = check_with(described_class, source)
23
+ expect(checker).to be_success
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckPry do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check ruby files' do
7
+ source = source_with('', 'file.rb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect binding pry' do
14
+ source = source_with("first line\nbinding.pry\nthirdline", 'file.rb')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ end
18
+
19
+ it 'should be success is all is finde ' do
20
+ source = source_with("first line\nthirdline\n", 'file.rb')
21
+ checker = check_with(described_class, source)
22
+ expect(checker).to be_success
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckRspecFocus do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check spec files' do
7
+ source = source_with('', 'file_spec.rb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'file.rb')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect :focus' do
14
+ source = source_with("first line\:focus\nthirdline", 'file_spec.rb')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ end
18
+
19
+ it 'should be success is all is finde ' do
20
+ source = source_with("first line\nthirdline\n", 'file_spec.rb')
21
+ checker = check_with(described_class, source)
22
+ expect(checker).to be_success
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckRubySyntax do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check text files' do
7
+ source = source_with
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect syntax errors' do
14
+ source = source_with('class MyClass')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details).to eq([[nil, 'Ruby syntax error']])
18
+ end
19
+
20
+ it 'should find not find if not there ' do
21
+ source = source_with('class MyClass; end')
22
+ checker = check_with(described_class, source)
23
+ expect(checker).to be_success
24
+ end
25
+
26
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckStrangeChars do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check text files' do
7
+ source = source_with('', 'file.html.erb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect tabs' do
14
+ source = source_with("one\x09two")
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details).to eq([['1,4', 'TAB x09 at line 1 column 4']])
18
+ end
19
+
20
+ it 'should detect form feeds' do
21
+ source = source_with("one\n\x0ctwo")
22
+ checker = check_with(described_class, source)
23
+ expect(checker).to be_error
24
+ expect(checker.errors.details).to eq([['2,1', 'FORM FEED x0C at line 2 column 1']])
25
+ end
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckUtf8Encoding do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check text files' do
7
+ source = source_with
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect non utf8 chars ' do
14
+ source = source_with("\xE4\xF6\xFC")
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details).to eq([[nil, 'encoding error, not utf8']])
18
+ end
19
+
20
+ it 'should find not find if not there ' do
21
+ source = source_with('first line')
22
+ checker = check_with(described_class, source)
23
+ expect(checker).to be_success
24
+ end
25
+
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::CheckYard do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check rb files' do
7
+ source = source_with('', 'file.rb')
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'test.rhtml')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect yard errors' do
14
+ source = source_with("# @paramsssss\nclass MyClass\nend", 'file.rb')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ detail = checker.errors.details[0][1]
18
+ expect(detail).to match(/Unknown tag @paramsssss in file/)
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::RubocopFormatter do
4
+ it_behaves_like 'a checker'
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::Rubocop do
4
+ it_behaves_like 'a checker'
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Checkers::RubocopLint do
4
+ it_behaves_like 'a checker'
5
+
6
+ it 'should check text files' do
7
+ source = source_with
8
+ expect(described_class.check?(source)).to be_truthy
9
+ source = source_with('', 'zipped.zip')
10
+ expect(described_class.check?(source)).to be_falsey
11
+ end
12
+
13
+ it 'should detect syntax errors' do
14
+ source = source_with('class MyClass')
15
+ checker = check_with(described_class, source)
16
+ expect(checker).to be_error
17
+ expect(checker.errors.details.first[1]).to match(/unexpected token/)
18
+ end
19
+
20
+ it 'should find not find if not there ' do
21
+ source = source_with('class MyClass; end')
22
+ checker = check_with(described_class, source)
23
+ expect(checker).to be_success
24
+ end
25
+
26
+ end