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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 76abd3e514881ba020ce7be60294367f7a449a6e
4
+ data.tar.gz: 22c52858996a5ff6f762fb286998d4f87b56d3d7
5
+ SHA512:
6
+ metadata.gz: 7c6f4a03915e49f2075e9b7491baec61b64a7396860491bc04abf813b93428794820e0ed26b399017c9055fff48a823d7c0d9a983b9ea3ad6ead5f32ac2ca449
7
+ data.tar.gz: 1febdf733bdf6f47cfd95c77a39172c64c0ce60495e1273e04d06181ff2345654ee4a9195fe8811c6425fae2d3e59d4527d275ddd0aa8d5fd1c6e98ae20b511a
data/.codeqa.rb ADDED
@@ -0,0 +1,22 @@
1
+ Codeqa.configure do |config|
2
+ config.excludes = ['spec/fixtures/html_error.html.erb',
3
+ 'spec/fixtures/html_error.text.html',
4
+ 'spec/fixtures/ruby_error.rb',
5
+ 'lib/codeqa/checkers/check_pry.rb',
6
+ 'spec/lib/codeqa/checkers/check_pry_spec.rb',
7
+ 'spec/lib/codeqa/checkers/check_rspec_focus_spec.rb',
8
+ 'coverage/*',
9
+ 'pkg/*']
10
+
11
+ config.enabled_checker.delete 'CheckRubySyntax'
12
+ config.enabled_checker << 'RubocopLint'
13
+ config.enabled_checker << 'RubocopFormatter'
14
+
15
+ config.rubocop_formatter_cops << 'AlignHash'
16
+ config.rubocop_formatter_cops << 'SignalException'
17
+ config.rubocop_formatter_cops << 'DeprecatedClassMethods'
18
+ config.rubocop_formatter_cops << 'RedundantBegin'
19
+ config.rubocop_formatter_cops << 'RedundantSelf'
20
+ config.rubocop_formatter_cops << 'RedundantReturn'
21
+ config.rubocop_formatter_cops << 'CollectionMethods'
22
+ end
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ .rvmrc
20
+ !.keep
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --tty
2
+ --color
3
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,93 @@
1
+
2
+ AllCops:
3
+ Exclude:
4
+ - spec/fixtures/ruby_error.rb
5
+
6
+ # changed config ---------------------------
7
+
8
+ AlignHash:
9
+ EnforcedHashRocketStyle: table
10
+
11
+ HashSyntax:
12
+ EnforcedStyle: hash_rockets
13
+
14
+ LineLength:
15
+ Max: 119
16
+
17
+ AccessModifierIndentation:
18
+ EnforcedStyle: outdent
19
+
20
+ MethodDefParentheses:
21
+ EnforcedStyle: require_parentheses
22
+
23
+ SpaceBeforeBlockBraces:
24
+ EnforcedStyle: no_space
25
+
26
+ SpaceAroundEqualsInParameterDefault:
27
+ EnforcedStyle: no_space
28
+
29
+ DotPosition:
30
+ EnforcedStyle: trailing
31
+
32
+ #SpaceInsideBlockBraces:
33
+ # EnforcedStyle: no_space
34
+ # SupportedStyles:
35
+ # - space
36
+ # - no_space
37
+ # # Valid values are: space, no_space
38
+ # EnforcedStyleForEmptyBraces: no_space
39
+ # # Space between { and |. Overrides EnforcedStyle if there is a conflict.
40
+ # SpaceBeforeBlockParameters: false
41
+
42
+ # http://www.ruby-doc.org/core-2.1.1/Kernel.html#method-i-fail
43
+ SignalException:
44
+ EnforcedStyle: only_raise
45
+
46
+
47
+ CollectionMethods:
48
+ Enabled: true
49
+
50
+ MethodLength:
51
+ Enabled: true
52
+ CountComments: false # count full line comments?
53
+ Max: 10
54
+ Severity: refactor
55
+
56
+ FileName:
57
+ Exclude:
58
+ - 'lib/templates/pre-commit'
59
+ - '.codeqa.rb'
60
+
61
+ # Disabled cops ------------------------------
62
+
63
+ DoubleNegation:
64
+ Enabled: false
65
+
66
+ ClassLength:
67
+ Enabled: false
68
+ CountComments: false # count full line comments?
69
+ Max: 100
70
+
71
+ # complains about use of class vars
72
+ ClassVars:
73
+ Enabled: false
74
+
75
+ # checks for top-level docu of classes and modules
76
+ Documentation:
77
+ Enabled: false
78
+
79
+ # checks to avoid \1 in regex
80
+ PerlBackrefs:
81
+ Enabled: false
82
+
83
+ SpecialGlobalVars:
84
+ Enabled: false
85
+
86
+ SignalException:
87
+ EnforcedStyle: only_raise
88
+
89
+ MethodLength:
90
+ Enabled: false
91
+
92
+ RegexpLiteral:
93
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.0.0
5
+ - rbx
6
+ - ruby-head
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: rbx
10
+ - rvm: ruby-head
data/.vimrc ADDED
@@ -0,0 +1 @@
1
+ noremap <buffer> <leader>t :!bundle exec rspec --no-color --fail-fast %:p:h<cr>
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ 0.2.1
2
+ * fixing missing ERB error
3
+ 0.2.0
4
+ * .codeqa config file
5
+ * lots of refactorings
6
+ * ruby 2.0.0 compliant
7
+ 0.1.0
8
+ * checking for old style link_to blocks (without equal signs)
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codeqa.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rubocop'
8
+ gem 'guard-rspec'
9
+ gem 'guard-rubocop'
10
+ gem 'rb-inotify', :require => false
11
+ # gem 'rb-fsevent', :require => false #mac only
12
+ # gem 'rb-fchange', :require => false #windows only
13
+ end
14
+
15
+ group :test do
16
+ gem 'simplecov', :require => false
17
+ gem 'coveralls', :require => false
18
+ end
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ notification :tmux,
2
+ :display_message => true,
3
+ :timeout => 3 # in seconds
4
+
5
+ # ignore /doc/
6
+
7
+ group :red_green_refactor, halt_on_fail: true do
8
+ guard 'rspec', cmd: "bundle exec rspec --color --format p", all_after_pass: true do
9
+ watch(%r{^spec/.+_spec\.rb$})
10
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
11
+ watch('spec/spec_helper.rb') { 'spec' }
12
+ watch('spec/factories.rb') { 'spec' }
13
+ watch('spec/support/jobs.json') { 'spec' }
14
+ watch(%r{^spec/factories/(.+)\.rb}) { 'spec' }
15
+ end
16
+
17
+ guard :rubocop, cli: %w(--display-cop-names --auto-correct) do
18
+ watch(%r{.+\.rb$})
19
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
20
+ end
21
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Peter Schrammel
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,97 @@
1
+ # Codeqa
2
+
3
+ [![Build Status](https://travis-ci.org/experteer/codeqa.svg?branch=master)](https://travis-ci.org/experteer/codeqa)
4
+ [![Coverage Status](https://img.shields.io/coveralls/experteer/codeqa.svg)](https://coveralls.io/r/experteer/codeqa)
5
+ [![Code Climate](https://codeclimate.com/github/experteer/codeqa/badges/gpa.svg)](https://codeclimate.com/github/experteer/codeqa)
6
+
7
+ With codeqa you can check your code to comply to certain coding rules (utf8 only chars, indenting) or to avoid typical errors or
8
+ enforce deprecations. You might even put it into a pre commit hook.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'codeqa'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install codeqa
23
+
24
+ ## Usage
25
+
26
+ codeqa filename
27
+
28
+
29
+ ## Config
30
+
31
+ Since Version 0.3 codeqa uses ruby for configuration, therefore the config file
32
+ is now named `.codeqa.rb`. The loading of configuration files is still the same,
33
+ meaning we have to following load order:
34
+
35
+ 1. Initialize with default settings (see `config/default..rb`)
36
+ 2. load `.codeqa.rb` from your home directory and merge it with the defaults.
37
+ 3. load `.codeqa.rb` placed in the project root, which is determined by finding
38
+ the closest `.git` folder.
39
+
40
+ Both the config in your home directory and the project config file are optional
41
+ and will be automatically skiped if they do not exist.
42
+
43
+ Because codeqa now uses ruby for configuration we can more easily change settings
44
+ without replacing it completely.
45
+
46
+ ### Example Config
47
+
48
+ ```ruby
49
+ Codeqa.configure do |config|
50
+ # override the list of excludes
51
+ config.excludes = ['coverage/*',
52
+ 'pkg/*',
53
+ 'tmp/*',
54
+ /\.log/]
55
+
56
+ # remove the default ruby lint in favor of rubocop
57
+ config.enabled_checker.delete 'CheckRubySyntax'
58
+ config.enabled_checker << 'RubocopLint'
59
+ # also enable the rubocop autoformatter
60
+ config.enabled_checker << 'RubocopFormatter'
61
+
62
+ # add some more active formatters/cops to rubocop
63
+ config.rubocop_formatter_cops << 'AlignHash'
64
+ config.rubocop_formatter_cops << 'SignalException'
65
+ config.rubocop_formatter_cops << 'DeprecatedClassMethods'
66
+ config.rubocop_formatter_cops << 'RedundantBegin'
67
+ config.rubocop_formatter_cops << 'RedundantSelf'
68
+ config.rubocop_formatter_cops << 'RedundantReturn'
69
+ config.rubocop_formatter_cops << 'CollectionMethods'
70
+ end
71
+ ```
72
+
73
+ ## Checkers
74
+
75
+ - pattern
76
+ - CheckPry
77
+ - CheckRspecFocus
78
+ - CheckConflict
79
+ - CheckStrangeChars
80
+ - CheckLinkTo
81
+ - rubocop
82
+ - RubocopLint (replacement for CheckRubySyntax)
83
+ - RubocopFormatter
84
+ - erb
85
+ - CheckErb (tests erb template for syntax errors using either `erb` or `action_view`
86
+ - CheckErbHtml (removes all erb tags and tests with `tidy` if the template is valid XML)
87
+ - yard
88
+ - CheckYard (checks YARD for warnings)
89
+ - CheckRubySyntax (runs file though `ruby -c`, use RubocopLint if possible)
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc 'Run all specs'
4
+ task :specs do
5
+ opts = %w(rspec -c)
6
+ opts += ['--require', File.join(File.dirname(__FILE__), 'spec', 'spec_helper')]
7
+ # opts += ['-I', YARD::ROOT]
8
+ if ENV['DEBUG']
9
+ $DEBUG = true
10
+ opts += ['-d']
11
+ end
12
+ opts += FileList['spec/**/*_spec.rb'].sort
13
+ cmd = opts.join(' ')
14
+ puts cmd if Rake.application.options.trace
15
+ system(cmd)
16
+ raise "Command failed with status (#{$?.to_i}): #{cmd}" if $?.to_i != 0
17
+ end
18
+ task :spec => :specs
19
+ task :default => :specs
data/bin/codeqa ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.join(File.dirname(__FILE__), '../lib') if ENV['CODEQA_DEV']
4
+ require 'rubygems'
5
+ require 'codeqa'
6
+
7
+ require 'pathname'
8
+ require 'optparse'
9
+
10
+ options = { :silent => false, :failfast => false }
11
+
12
+ ARGV.options do |opts|
13
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] FILES"
14
+
15
+ opts.separator ''
16
+ opts.separator 'Specific Options:'
17
+
18
+ opts.on('-s', '--silent', 'No output if no error') do
19
+ options[:silent] = true
20
+ end
21
+ opts.on('-f', '--fail-fast', 'Fail right after the first error.') do
22
+ options[:failfast] = true
23
+ end
24
+
25
+ opts.on('-i', '--install', 'Install a basic pre-commit hook.') do
26
+ options[:install] = true
27
+ end
28
+
29
+ opts.separator 'Common Options:'
30
+
31
+ opts.on('-h', '--help',
32
+ 'Show this message.') do
33
+ puts opts
34
+ exit
35
+ end
36
+ opts.on('-v', '--version',
37
+ "Show version (it's #{Codeqa::VERSION})") do
38
+ puts Codeqa::VERSION
39
+ exit
40
+ end
41
+
42
+ begin
43
+ opts.parse!
44
+ rescue
45
+ puts opts
46
+ exit
47
+ end
48
+ end
49
+
50
+ if options[:install]
51
+ Codeqa.install(ARGV.first || '.')
52
+ exit
53
+ end
54
+
55
+ exploded_args = ARGV.map do |e|
56
+ if File.directory?(e)
57
+ Dir["#{e}/**/*"]
58
+ else
59
+ e
60
+ end
61
+ end
62
+
63
+ files_to_check = exploded_args.
64
+ flatten.
65
+ map{ |e| Pathname.new(e).realpath.to_s }.
66
+ reject{ |e| File.directory?(e) || Codeqa.configuration.excluded?(e) }.
67
+ uniq
68
+
69
+ puts "#{files_to_check.count} files to check" unless options[:silent]
70
+ if options[:failfast]
71
+ # all? is already lazy/fail-fast so it will stop after the first false
72
+ exit 1 unless files_to_check.all?{ |e| Codeqa.check(e, options) }
73
+ else
74
+ exit 1 unless files_to_check.map{ |e| Codeqa.check(e, options) }.all?
75
+ end
data/codeqa.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/codeqa/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Peter Schrammel', 'Andreas Eger']
6
+ gem.email = ['peter.schrammel@experteer.com', 'andreas.eger@experteer.com']
7
+ gem.description = 'Checks your code (esp Rails) for common errors'
8
+ gem.summary = 'Code checker'
9
+ gem.homepage = ''
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'codeqa'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Codeqa::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ gem.add_development_dependency 'rspec', '>=3.0'
20
+ gem.add_development_dependency 'yard'
21
+ end
data/config/default.rb ADDED
@@ -0,0 +1,42 @@
1
+ Codeqa.configure do |config|
2
+ config.excludes = ['vendor/**/*']
3
+ config.enabled_checker = %w(CheckErb
4
+ CheckErbHtml
5
+ CheckRubySyntax
6
+ CheckStrangeChars
7
+ CheckUtf8Encoding
8
+ CheckConflict
9
+ CheckPry
10
+ CheckLinkto
11
+ CheckRspecFocus)
12
+ config.erb_engine = 'erb'
13
+ config.rubocop_formatter_cops = %w( EmptyLinesAroundBody
14
+ EmptyLines
15
+ TrailingWhitespace
16
+ SpaceBeforeBlockBraces
17
+ SpaceInsideBlockBraces
18
+ SpaceAroundEqualsInParameterDefault
19
+ SpaceAfterComma
20
+ SingleSpaceBeforeFirstArg
21
+ SpaceInsideHashLiteralBraces
22
+ SpaceAroundOperators
23
+ SpaceInsideParens
24
+ LeadingCommentSpace
25
+ EmptyLineBetweenDefs
26
+ IndentationConsistency
27
+ IndentationWidth
28
+ MethodDefParentheses
29
+ DefWithParentheses
30
+ HashSyntax
31
+ AlignArray
32
+ AlignParameters
33
+ BracesAroundHashParameters )
34
+ # other interessting but currently not enabled default cops
35
+ # AlignHash
36
+ # SignalException
37
+ # DeprecatedClassMethods
38
+ # RedundantBegin
39
+ # RedundantSelf
40
+ # RedundantReturn
41
+ # CollectionMethods
42
+ end
@@ -0,0 +1,21 @@
1
+ module Codeqa
2
+ class CheckErrors
3
+ def initialize
4
+ @details = []
5
+ end
6
+
7
+ attr_reader :details
8
+
9
+ def add(place, message)
10
+ @details << [place, message]
11
+ end
12
+
13
+ def success?
14
+ @details.empty?
15
+ end
16
+
17
+ def errors?
18
+ !success?
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,47 @@
1
+ require 'stringio'
2
+ require 'tempfile'
3
+ require 'forwardable'
4
+
5
+ module Codeqa
6
+ class Checker
7
+ extend ::Forwardable
8
+
9
+ def initialize(sourcefile)
10
+ @errors = CheckErrors.new
11
+ @sourcefile = sourcefile
12
+ end
13
+
14
+ attr_reader :sourcefile
15
+ attr_reader :errors
16
+ def_delegators :@errors, :success?, :errors?
17
+
18
+ def self.available?
19
+ true
20
+ end
21
+
22
+ private
23
+
24
+ def with_existing_file(content=sourcefile.content)
25
+ if sourcefile.exist? && sourcefile.content == content
26
+ yield sourcefile.filename
27
+ else
28
+ Tempfile.open('codeqa') do |tmpfile|
29
+ tmpfile.write(content)
30
+ tmpfile.flush
31
+ tmpfile.rewind
32
+ yield tmpfile.path
33
+ end
34
+ end
35
+ end
36
+
37
+ def capture
38
+ $stdout, stdout = StringIO.new, $stdout
39
+ $stderr, stderr = StringIO.new, $stderr
40
+ result = yield
41
+ [result, $stdout.string + $stderr.string]
42
+ ensure
43
+ $stdout = stdout
44
+ $stderr = stderr
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ require 'codeqa/checkers/pattern_checker'
2
+
3
+ module Codeqa
4
+ module Checkers
5
+ class CheckConflict < PatternChecker
6
+ def name
7
+ 'conflict'
8
+ end
9
+
10
+ def hint
11
+ 'Remove the lines which are beginning with <<<<<<< or >>>>>>> or =======.'
12
+ end
13
+
14
+ def self.check?(sourcefile)
15
+ sourcefile.text?
16
+ end
17
+
18
+ private
19
+
20
+ def self.pattern
21
+ @pattern ||= /^<<<<<<<|^>>>>>>>|^=======$/m
22
+ end
23
+ def error_msg(_line, line_number, _pos)
24
+ "conflict leftovers in line #{line_number}, please merge properly"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ module Codeqa
2
+ module Checkers
3
+ class CheckErb < Checker
4
+ def self.check?(sourcefile)
5
+ sourcefile.erb?
6
+ end
7
+
8
+ def self.available?
9
+ engine?
10
+ end
11
+
12
+ def name
13
+ 'erb syntax'
14
+ end
15
+
16
+ def hint
17
+ 'There is a syntax error in the ruby code of the erb parsed file.'
18
+ end
19
+
20
+ # rubocop:disable RescueException,HandleExceptions
21
+ def check
22
+ if defined?(ActionView)
23
+ ActionView::Template::Handlers::Erubis.new(erb).result
24
+ else
25
+ ERB.new(sourcefile.content.gsub('<%=', '<%'), nil, '-').result
26
+ end
27
+ rescue SyntaxError
28
+ errors.add(nil, <<-EOF)
29
+ #{$!.message}
30
+ #{$!.backtrace.join("\n")}
31
+ EOF
32
+ rescue Exception
33
+ true # valid syntax - just the proper setup for the template/rendering is missing
34
+ end
35
+ # rubocop:enable RescueException,HandleExceptions
36
+
37
+ def self.engine?
38
+ @@engine ||= if %w(actionview action_view).include? Codeqa.configuration.erb_engine.downcase
39
+ require 'action_view'
40
+ true
41
+ else
42
+ require 'erb'
43
+ true
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end