codeqa 0.4.0.pre → 0.4.0.pre2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ae0299a503f1cb9639e037907ade194edfe3db0
4
- data.tar.gz: 859128b8f52f560cc2dedb79157134237179b042
3
+ metadata.gz: b47b37862da4f231fa163a9161ea66758c543de5
4
+ data.tar.gz: a36f9e4ac2f21942121b32be320dccfbf0198b17
5
5
  SHA512:
6
- metadata.gz: 198df6738b57d3fbfb076bd3522b7b715b10245ce40769bbfb6b67e3e4af07df622504edc2d867d98cf8fc713582cbf95aa63de01c9a69e914e78c7d6d00c991
7
- data.tar.gz: ec6c8833e4b66ba642b0ee30016f2c7d5d7e477f64cc59f69c5d6c49202c41667496e998631687e2ae863fa95f8f9c37a3cbbe0bfab81370ff2ceddecb5dc626
6
+ metadata.gz: 23e80489e8084d42a8d3a7c760bd70af2a34f7023fa9612c507d0800e8cd334e06164b9e366a277c263a2b639a674db69ee191b314cf159b4e3f1dbf5d2c9419
7
+ data.tar.gz: f1c7db9caef0fed024e0f6a64d6de6dc931adfbed55c37718eeab541a3861cbc0f834329034b734bf7e07329e78cee9c311fa62094cb2c1df21901d4d4a058c7
data/Gemfile CHANGED
@@ -12,9 +12,7 @@ group :development do
12
12
  end
13
13
 
14
14
  group :development, :test do
15
- gem 'pry-byebug'
16
- gem 'nokogiri'
17
- gem 'rubocop'
15
+ gem 'pry-byebug', :platform => :mri
18
16
  end
19
17
 
20
18
  group :test do
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Codeqa
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/codeqa.svg)](http://badge.fury.io/rb/codeqa)
4
- [![Build Status](https://travis-ci.org/experteer/codeqa.svg?branch=master)](https://travis-ci.org/experteer/codeqa)
5
- [![Coverage Status](https://img.shields.io/coveralls/experteer/codeqa.svg)](https://coveralls.io/r/experteer/codeqa)
6
- [![Code Climate](https://codeclimate.com/github/experteer/codeqa/badges/gpa.svg)](https://codeclimate.com/github/experteer/codeqa)
3
+ [![Gem Version](http://img.shields.io/gem/v/codeqa.svg?style=flat)](https://rubygems.org/gems/codeqa)
4
+ [![Build Status](http://img.shields.io/travis/experteer/codeqa.svg?style=flat)](https://travis-ci.org/experteer/codeqa)
5
+ [![Coverage Status](https://img.shields.io/coveralls/experteer/codeqa.svg?style=flat)](https://coveralls.io/r/experteer/codeqa)
6
+ [![Code Climate](http://img.shields.io/codeclimate/github/experteer/codeqa.svg?style=flat)](https://codeclimate.com/github/experteer/codeqa)
7
7
 
8
8
  With codeqa you can check your code to comply to certain coding rules (utf8 only chars, indenting) or to avoid typical errors or
9
9
  enforce deprecations. You might even put it into a pre commit hook.
@@ -85,6 +85,7 @@ end
85
85
  - erb
86
86
  - CheckErb (tests erb template for syntax errors using either `erb` or `action_view`
87
87
  - CheckErbHtml (removes all erb tags and tests with `tidy` if the template is valid XML)
88
+ - HtmlValidator (uses Nokogiri to check stripped html.erb files against XML errors)
88
89
  - yard
89
90
  - CheckYard (checks YARD for warnings)
90
91
  - CheckRubySyntax (runs file though `ruby -c`, use RubocopLint if possible)
data/bin/codeqa CHANGED
@@ -15,9 +15,14 @@ ARGV.options do |opts|
15
15
  opts.separator ''
16
16
  opts.separator 'Specific Options:'
17
17
 
18
- opts.on('-s', '--silent', 'No output if no error') do
18
+ opts.on('-s', '--silent', 'No output') do
19
19
  options[:silent] = true
20
20
  end
21
+
22
+ opts.on('-e', '--silent-success', 'only Output errors') do
23
+ options[:silent_success] = true
24
+ end
25
+
21
26
  opts.on('-f', '--fail-fast', 'Fail right after the first error.') do
22
27
  options[:failfast] = true
23
28
  end
data/codeqa.gemspec CHANGED
@@ -18,7 +18,11 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.required_ruby_version = '>= 2.0'
20
20
 
21
+ gem.add_dependency 'multi_json', '>= 1.0'
22
+
21
23
  gem.add_development_dependency 'rake'
22
24
  gem.add_development_dependency 'rspec', '>=3.0'
23
25
  gem.add_development_dependency 'yard'
26
+ gem.add_development_dependency 'nokogiri'
27
+ gem.add_development_dependency 'rubocop'
24
28
  end
@@ -1,4 +1,5 @@
1
1
  require 'codeqa/utils/erb_sanitizer'
2
+ require 'nokogiri'
2
3
 
3
4
  module Codeqa
4
5
  module Checkers
@@ -23,7 +24,8 @@ module Codeqa
23
24
  /Opening and ending tag mismatch: (special line 1|\w+ line 1 and special)/,
24
25
  /Premature end of data in tag special/,
25
26
  /Extra content at the end of the document/,
26
- /xmlParseEntityRef: no name/
27
+ /xmlParseEntityRef: no name/,
28
+ /Entity 'nbsp' not defined/
27
29
  )
28
30
  def check
29
31
  return unless self.class.nokogiri?
@@ -31,14 +33,16 @@ module Codeqa
31
33
 
32
34
  doc.errors.delete_if{ |e| e.message =~ REMOVED_NOKOGIRI_ERRORS }
33
35
  errors.add(:source, sourcefile.content) unless doc.errors.empty?
34
- # errors.add(:source, stripped_html) unless doc.errors.empty?
35
36
  doc.errors.each do |error|
36
37
  errors.add(error.line, error.message) unless error.warning?
37
38
  end
38
39
  end
39
40
 
40
41
  def stripped_html
41
- @html ||= ErbSanitizer.new(sourcefile.content).result
42
+ ErbSanitizer.
43
+ new(sourcefile.content).
44
+ result.
45
+ gsub(%r{<script[ >](.*)</script>}m){ "<!-- script#{"\n" * $1.scan("\n").count} /script -->" }
42
46
  end
43
47
 
44
48
  def self.nokogiri?
@@ -1,4 +1,4 @@
1
- require 'ostruct'
1
+ require 'multi_json'
2
2
 
3
3
  module Codeqa
4
4
  module Checkers
@@ -45,15 +45,14 @@ module Codeqa
45
45
  end
46
46
 
47
47
  def handle_rubocop_results(raw)
48
- data = JSON.parse raw, :object_class => OpenStruct
49
- data.files.
50
- reject{ |f| f.offenses.empty? }.
51
- each do |file|
52
- file.offenses.each do |offense|
53
- position = [offense.location.line, offense.location.column]
54
- errors.add(position, "#{offense.cop_name}: #{offense.message}")
55
- end
56
- end
48
+ MultiJson.load(raw)['files'].
49
+ reject{ |f| f['offenses'].empty? }.
50
+ each do |file|
51
+ file['offenses'].each do |offense|
52
+ position = [offense['location']['line'], offense['location']['column']]
53
+ errors.add(position, "#{offense['cop_name']}: #{offense['message']}")
54
+ end
55
+ end
57
56
  end
58
57
  def self.rubocop?
59
58
  @loaded ||= begin
@@ -63,7 +62,8 @@ module Codeqa
63
62
  end
64
63
 
65
64
  # Since using the json format we only care about stdout
66
- # stderr will be silent
65
+ # stderr will be silenced
66
+ # (internal rubocop errors/warning will be printed there)
67
67
  def capture
68
68
  $stdout, stdout = StringIO.new, $stdout
69
69
  $stderr, stderr = StringIO.new, $stderr
@@ -49,7 +49,7 @@ module Codeqa
49
49
  case token
50
50
  when '%>'
51
51
  # in here we deal with the content of a erb tag
52
- (content.scan("\n").count).times do
52
+ content.scan("\n").count.times do
53
53
  add_put_cmd(out, "\n")
54
54
  end
55
55
  # case scanner.stag
@@ -1,3 +1,3 @@
1
1
  module Codeqa
2
- VERSION = '0.4.0.pre'
2
+ VERSION = '0.4.0.pre2'
3
3
  end
@@ -54,25 +54,39 @@ describe Codeqa::Checkers::HtmlValidator do
54
54
  checker = check_with(described_class, source)
55
55
  expect(checker).to be_success
56
56
  end
57
+ it "should no complain about nbsp 'spaces'" do
58
+ source = source_with('<div>something&nbsp;fooo</div>')
59
+ checker = check_with(described_class, source)
60
+ expect(checker).to be_success
61
+ end
62
+
63
+ context 'script tags' do
64
+ it 'should replace script tags with html comment' do
65
+ text = '<div><script>foo</script></div>'
66
+ source = source_with(text)
67
+ checker = described_class.new(source)
68
+ expect(checker.stripped_html).to eq('<div><!-- script /script --></div>')
69
+ end
57
70
 
58
- # context 'javascript' do
59
- # it 'should ignore javascript' do
60
- # source = source_with('<div><script></ul></script></div>')
61
- # checker = check_with(described_class, source)
62
- # expect(checker).to be_success
63
- # end
64
- # it 'should ignore javascript' do
65
- # source = source_with('<div><script type="text/javascript" charset="utf-8"></ul></script></div>')
66
- # checker = check_with(described_class, source)
67
- # expect(checker).to be_success
68
- # source = source_with("<div><script>multiline\n</ul></script></div>")
69
- # checker = check_with(described_class, source)
70
- # expect(checker).to be_success
71
- # end
72
- # it 'should ignore javascript' do
73
- # source = source_with('<div><style></ul></style></div>')
74
- # checker = check_with(described_class, source)
75
- # expect(checker).to be_success
76
- # end
77
- # end
71
+ it 'should replace multiline script tags while keeping the linecount correct' do
72
+ text = <<-EOR
73
+ <div>
74
+ <script>
75
+ var some = 'javascript';
76
+ console.log(some);
77
+ </script>
78
+ </div>
79
+ EOR
80
+ source = source_with(text)
81
+ checker = described_class.new(source)
82
+ expect(checker.stripped_html).to eq(<<-EOR)
83
+ <div>
84
+ <!-- script
85
+
86
+
87
+ /script -->
88
+ </div>
89
+ EOR
90
+ end
91
+ end
78
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeqa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.pre
4
+ version: 0.4.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-26 00:00:00.000000000 Z
12
+ date: 2014-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: rake
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +67,34 @@ dependencies:
53
67
  - - ">="
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: nokogiri
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
56
98
  description: Checks your code (esp Rails) for common errors
57
99
  email:
58
100
  - peter.schrammel@experteer.com