codeqa 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Configuration do
4
+ let(:subject){ Codeqa.configuration }
5
+
6
+ it 'should be exposed in the Codeqa module' do
7
+ expect(Codeqa).to respond_to(:configuration)
8
+ end
9
+
10
+ %w(excludes enabled_checker erb_engine rubocop_formatter_cops).each do |c|
11
+ it "should provide :#{c}" do
12
+ expect(Codeqa.configuration).to respond_to(c.to_sym)
13
+ end
14
+ end
15
+
16
+ it 'should have the excludes set' do
17
+ expect(Codeqa.configuration.excludes).to be_a(Set)
18
+ expect(Codeqa.configuration.excludes).to eq(Set.new(['vendor/**/*']))
19
+ end
20
+ it 'should have the enabled checkers set' do
21
+ expect(Codeqa.configuration.enabled_checker).to be_a(Set)
22
+ exp_set = Set.new(%w(CheckStrangeChars
23
+ CheckUtf8Encoding
24
+ CheckConflict
25
+ CheckPry
26
+ RubocopLint))
27
+ expect(Codeqa.configuration.enabled_checker).to eq(exp_set)
28
+ end
29
+
30
+ context 'exclude' do
31
+ before(:each) do
32
+ @org_dir = Dir.pwd
33
+ project_root = Codeqa.root.join 'spec/fixtures/isolation/home/project'
34
+ allow(Codeqa.configuration).to receive(:project_root).and_return(Pathname.new(project_root))
35
+ Dir.chdir(project_root)
36
+ Codeqa.configure{ |c| c.excludes = ['ignored/*', /tmp/] }
37
+ end
38
+ after(:each) do
39
+ Dir.chdir(@org_dir)
40
+ load_test_config
41
+ end
42
+ it 'should be true for filenames within a foo folder' do
43
+ expect(Codeqa.configuration.excluded?('ignored/some_file.txt')).to be true
44
+ end
45
+ it 'should be false for files unrelated to the excludes' do
46
+ expect(Codeqa.configuration.excluded?('file.rb')).to be false
47
+ end
48
+ it 'should work with regex matches' do
49
+ expect(Codeqa.configuration.excluded?('some/tmp/path')).to be true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::RunnerDecorator do
4
+ it 'should run provide the errors if the checker failed' do
5
+ source = source_with('def syntax_error', 'ruby.rb')
6
+ runner = Codeqa::Runner.run(source)
7
+ expect(runner.success?).to be false
8
+ decorator = Codeqa::RunnerDecorator.new(runner)
9
+ expect(decorator.to_s).to match(/syntax/)
10
+ end
11
+ it 'should run list the ran checkers' do
12
+ source = source_with('def foo; end', 'ruby.rb')
13
+ runner = Codeqa::Runner.run(source)
14
+ expect(runner.success?).to be true
15
+ decorator = Codeqa::RunnerDecorator.new(runner)
16
+ expect(decorator.to_s).to match(/Passed tests.+strange chars/)
17
+ end
18
+
19
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Runner do
4
+
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa::Sourcefile do
4
+ it 'should detect binary' do
5
+ source = Codeqa::Sourcefile.new('zipped.zip')
6
+ expect(source).to be_binary
7
+ expect(source).not_to be_text
8
+ end
9
+
10
+ it 'should detect ruby' do
11
+ source = Codeqa::Sourcefile.new('ruby.rb')
12
+ expect(source).to be_text
13
+ expect(source).to be_ruby
14
+ end
15
+
16
+ it 'should detect erb' do
17
+ source = Codeqa::Sourcefile.new('erb.erb')
18
+ expect(source).to be_text
19
+ expect(source).to be_erb
20
+ end
21
+
22
+ it 'should detect html' do
23
+ source = Codeqa::Sourcefile.new('erb.html.erb')
24
+ expect(source).to be_text
25
+ expect(source).to be_erb
26
+ expect(source).to be_html
27
+ source = Codeqa::Sourcefile.new('erb.rhtml')
28
+ expect(source).to be_text
29
+ expect(source).to be_erb
30
+ expect(source).to be_html
31
+ end
32
+
33
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Codeqa do
4
+ context 'register_checkers' do
5
+ it 'should first reset the checkers' do
6
+ expect(Codeqa::Runner).to receive(:reset_checkers)
7
+ Codeqa.register_checkers
8
+ end
9
+ it 'should constantize the checkers in config and add them to the registered_checkers' do
10
+ Codeqa.configuration.enabled_checker = ['CheckErb']
11
+ Codeqa.register_checkers
12
+ expect(Codeqa::Runner.registered_checkers).to include(Codeqa::Checkers::CheckErb)
13
+ load_test_config
14
+ end
15
+ end
16
+ context 'check' do
17
+ it 'should be true if the file is OK' do
18
+ file = './spec/fixtures/ruby.rb'
19
+ expect(Codeqa.check(file, :silent => true)).to be true
20
+ end
21
+ it 'should be false if the file is broken' do
22
+ file = './spec/fixtures/ruby_error.rb'
23
+ expect(Codeqa.check(file, :silent => true)).to be false
24
+ end
25
+ end
26
+
27
+ context 'install' do
28
+ let(:project_dir){ Codeqa.root.join('spec/fixtures/isolation/home/project') }
29
+ before(:each) do
30
+ FileUtils.mkdir_p(project_dir.join('.git', 'hooks'))
31
+ end
32
+ after(:each) do
33
+ FileUtils.rm_rf(project_dir.join('.git'))
34
+ end
35
+
36
+ it 'should be true if folder looks like a git root' do
37
+ expect(Codeqa.install(project_dir.to_s)).to be true
38
+ end
39
+
40
+ it 'should be false if folder does not look like a git root' do
41
+ expect(Codeqa.install(Codeqa.root.join('spec', 'fixtures'))).to be false
42
+ end
43
+
44
+ it 'should copy pre-commit hook into project git folder' do
45
+ template_location = Codeqa.root.join('lib', 'templates', 'pre-commit')
46
+ hook_location = project_dir.join('.git', 'hooks', 'pre-commit')
47
+ expect(FileUtils).to receive(:cp).with(template_location, hook_location)
48
+ allow(FileUtils).to receive(:chmod)
49
+ Codeqa.install project_dir.to_s
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,56 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start
11
+
12
+ Bundler.require(:default, :test)
13
+
14
+ require 'codeqa'
15
+ RSpec.configure do |config|
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+
25
+ # override some config settings
26
+ config.before(:all) do
27
+ load_test_config
28
+ end
29
+ end
30
+
31
+ Dir['./spec/support/**/*.rb'].sort.each{ |f| require f }
32
+
33
+ def load_test_config
34
+ Codeqa.configure do |c|
35
+ c.excludes = ['vendor/**/*']
36
+ c.enabled_checker = %w(CheckStrangeChars
37
+ CheckUtf8Encoding
38
+ CheckConflict
39
+ CheckPry
40
+ RubocopLint)
41
+ c.rubocop_formatter_cops = %w(EmptyLinesAroundBody
42
+ EmptyLines
43
+ TrailingWhitespace)
44
+ c.erb_engine = 'erb'
45
+ end
46
+ end
47
+
48
+ def check_with(klass, source)
49
+ checker = klass.new(source)
50
+ checker.check
51
+ checker
52
+ end
53
+
54
+ def source_with(content='#ruby file', filename='prog.rb')
55
+ Codeqa::Sourcefile.new(filename, content)
56
+ end
@@ -0,0 +1,20 @@
1
+ RSpec.shared_examples 'a checker' do
2
+ let(:checker){ described_class.new(double('SourceFile', :null_object => true)) }
3
+ %w(name hint check).each do |method|
4
+ it "should respond to :#{method}" do
5
+ expect(checker).to respond_to(method.to_sym)
6
+ end
7
+ end
8
+ %w(name hint).each do |method|
9
+ it "should return a non empty string from :#{method}" do
10
+ expect(checker.send(method.to_sym)).not_to be_empty
11
+ end
12
+ end
13
+ context 'ClassMethods' do
14
+ %w(check? available?).each do |method|
15
+ it "should respond to :#{method}" do
16
+ expect(described_class).to respond_to(method.to_sym)
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeqa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Schrammel
8
+ - Andreas Eger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: yard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Checks your code (esp Rails) for common errors
57
+ email:
58
+ - peter.schrammel@experteer.com
59
+ - andreas.eger@experteer.com
60
+ executables:
61
+ - codeqa
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".codeqa.rb"
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".rubocop.yml"
69
+ - ".ruby-version"
70
+ - ".travis.yml"
71
+ - ".vimrc"
72
+ - CHANGELOG
73
+ - Gemfile
74
+ - Guardfile
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - bin/codeqa
79
+ - codeqa.gemspec
80
+ - config/default.rb
81
+ - lib/codeqa.rb
82
+ - lib/codeqa/check_errors.rb
83
+ - lib/codeqa/checker.rb
84
+ - lib/codeqa/checkers/check_conflict.rb
85
+ - lib/codeqa/checkers/check_erb.rb
86
+ - lib/codeqa/checkers/check_erb_html.rb
87
+ - lib/codeqa/checkers/check_linkto.rb
88
+ - lib/codeqa/checkers/check_pry.rb
89
+ - lib/codeqa/checkers/check_rspec_focus.rb
90
+ - lib/codeqa/checkers/check_ruby_syntax.rb
91
+ - lib/codeqa/checkers/check_strange_chars.rb
92
+ - lib/codeqa/checkers/check_utf8_encoding.rb
93
+ - lib/codeqa/checkers/check_yard.rb
94
+ - lib/codeqa/checkers/pattern_checker.rb
95
+ - lib/codeqa/checkers/rubocop_formatter.rb
96
+ - lib/codeqa/checkers/rubocop_full.rb
97
+ - lib/codeqa/checkers/rubocop_lint.rb
98
+ - lib/codeqa/configuration.rb
99
+ - lib/codeqa/fake_erb.rb
100
+ - lib/codeqa/runner.rb
101
+ - lib/codeqa/runner_decorator.rb
102
+ - lib/codeqa/sourcefile.rb
103
+ - lib/codeqa/version.rb
104
+ - lib/templates/pre-commit
105
+ - spec/fixtures/html_error.html.erb
106
+ - spec/fixtures/html_error.text.html
107
+ - spec/fixtures/isolation/home/project/dir/.gitkeep
108
+ - spec/fixtures/isolation/home/project/file.rb
109
+ - spec/fixtures/isolation/home/project/ignored/some_file.txt
110
+ - spec/fixtures/ruby.rb
111
+ - spec/fixtures/ruby_error.rb
112
+ - spec/lib/codeqa/checkers/check_conflict_spec.rb
113
+ - spec/lib/codeqa/checkers/check_erb_html_spec.rb
114
+ - spec/lib/codeqa/checkers/check_erb_spec.rb
115
+ - spec/lib/codeqa/checkers/check_linkto_spec.rb
116
+ - spec/lib/codeqa/checkers/check_pry_spec.rb
117
+ - spec/lib/codeqa/checkers/check_rspec_focus_spec.rb
118
+ - spec/lib/codeqa/checkers/check_ruby_syntax_spec.rb
119
+ - spec/lib/codeqa/checkers/check_strange_chars_spec.rb
120
+ - spec/lib/codeqa/checkers/check_utf8_encoding_spec.rb
121
+ - spec/lib/codeqa/checkers/check_yard_spec.rb
122
+ - spec/lib/codeqa/checkers/rubocop_formatter_spec.rb
123
+ - spec/lib/codeqa/checkers/rubocop_full_spec.rb
124
+ - spec/lib/codeqa/checkers/rubocop_lint_spec.rb
125
+ - spec/lib/codeqa/configuration_spec.rb
126
+ - spec/lib/codeqa/runner_decorator_spec.rb
127
+ - spec/lib/codeqa/runner_spec.rb
128
+ - spec/lib/codeqa/sourcefile_spec.rb
129
+ - spec/lib/codeqa_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/support/checker.rb
132
+ homepage: ''
133
+ licenses: []
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Code checker
155
+ test_files:
156
+ - spec/fixtures/html_error.html.erb
157
+ - spec/fixtures/html_error.text.html
158
+ - spec/fixtures/isolation/home/project/dir/.gitkeep
159
+ - spec/fixtures/isolation/home/project/file.rb
160
+ - spec/fixtures/isolation/home/project/ignored/some_file.txt
161
+ - spec/fixtures/ruby.rb
162
+ - spec/fixtures/ruby_error.rb
163
+ - spec/lib/codeqa/checkers/check_conflict_spec.rb
164
+ - spec/lib/codeqa/checkers/check_erb_html_spec.rb
165
+ - spec/lib/codeqa/checkers/check_erb_spec.rb
166
+ - spec/lib/codeqa/checkers/check_linkto_spec.rb
167
+ - spec/lib/codeqa/checkers/check_pry_spec.rb
168
+ - spec/lib/codeqa/checkers/check_rspec_focus_spec.rb
169
+ - spec/lib/codeqa/checkers/check_ruby_syntax_spec.rb
170
+ - spec/lib/codeqa/checkers/check_strange_chars_spec.rb
171
+ - spec/lib/codeqa/checkers/check_utf8_encoding_spec.rb
172
+ - spec/lib/codeqa/checkers/check_yard_spec.rb
173
+ - spec/lib/codeqa/checkers/rubocop_formatter_spec.rb
174
+ - spec/lib/codeqa/checkers/rubocop_full_spec.rb
175
+ - spec/lib/codeqa/checkers/rubocop_lint_spec.rb
176
+ - spec/lib/codeqa/configuration_spec.rb
177
+ - spec/lib/codeqa/runner_decorator_spec.rb
178
+ - spec/lib/codeqa/runner_spec.rb
179
+ - spec/lib/codeqa/sourcefile_spec.rb
180
+ - spec/lib/codeqa_spec.rb
181
+ - spec/spec_helper.rb
182
+ - spec/support/checker.rb
183
+ has_rdoc: