codeclimate-engine-rb 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 439a853dc1e069802816f36dd3de911bfa46e5ad
4
+ data.tar.gz: abb3f787278011087b7078dade06ef9f94656de4
5
+ SHA512:
6
+ metadata.gz: b9b351cf613c18fc4c972ca9ae37f50f3973ae1f1608f931c855b79d2851074bd70b8f3872be3536c49167e2835c7737ae8ba24852c55a2970f5b2781f56dbd8
7
+ data.tar.gz: 2451dad2cfef7a78909403d40586951d7104dc442c4d3685ee279d8949d793643b9e6fb6cc4c064075aa7de3fe369aff03107276e051ab462f3da96094dc60ba
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+ Style/StringLiterals:
4
+ Enabled: false
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,75 @@
1
+ # codeclimate-engine-rb
2
+
3
+ A simple way to create issues in the JSON format described in the [Code Climate Engine specification].
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'codeclimate_engine'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install codeclimate_engine
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ location = CCEngine::Location::LineRange.new(
25
+ path: "foo/bar.txt",
26
+ line_range: 13..14
27
+ )
28
+
29
+ issue = CCEngine::Issue.new(
30
+ check_name: "Bug Risk/Unused Variable",
31
+ description: "Unused local variable `foo`",
32
+ categories: [CCEngine::Category.complexity, CCEngine::Category.style],
33
+ location: location
34
+ )
35
+
36
+ issue.to_json
37
+ ```
38
+
39
+ The result would be:
40
+
41
+ ```json
42
+ {
43
+ "type": "issue",
44
+ "check_name": "Bug Risk/Unused Variable",
45
+ "description": "Unused local variable `foo`",
46
+ "categories": ["Complexity", "Style"],
47
+ "location": {
48
+ "path": "foo/bar.txt",
49
+ "lines": {
50
+ "begin": 13,
51
+ "end": 14
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ There are some other ways to specify the location – please browse the gem's
58
+ tests for details.
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`.
65
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( https://github.com/andyw8/codeclimate-engine-rb/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create a new Pull Request
74
+
75
+ [Code Climate Engine specification]: https://github.com/codeclimate/spec/blob/master/SPEC.md
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codeclimate_engine"
5
+
6
+ require "irb"
7
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cc_engine/version'
5
+
6
+ # rubocop:disable Metrics/LineLength
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "codeclimate-engine-rb"
9
+ spec.version = CCEngine::VERSION
10
+ spec.authors = ["Andy Waite"]
11
+ spec.email = ["github.aw@andywaite.com"]
12
+
13
+ spec.summary = "JSON issue formatter for the Code Climate engine"
14
+ spec.homepage = "https://github.com/andyw8/codeclimate-engine-rb"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.3"
24
+ spec.add_dependency "virtus", "~> 1.0"
25
+ end
26
+ # rubocop:enable Metrics/LineLength
@@ -0,0 +1,31 @@
1
+ module CCEngine
2
+ module Category
3
+ def self.bug_risk
4
+ "Bug Risk"
5
+ end
6
+
7
+ def self.clarity
8
+ "Clarity"
9
+ end
10
+
11
+ def self.compatibility
12
+ "Compatibility"
13
+ end
14
+
15
+ def self.complexity
16
+ "Complexity"
17
+ end
18
+
19
+ def self.duplication
20
+ "Duplication"
21
+ end
22
+
23
+ def self.security
24
+ "Security"
25
+ end
26
+
27
+ def self.style
28
+ "Style"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require "json"
2
+
3
+ module CCEngine
4
+ class Config
5
+ def initialize(json_string)
6
+ @json_string = json_string
7
+ end
8
+
9
+ def include_paths
10
+ parsed_json.fetch("include_paths")
11
+ end
12
+
13
+ def exclude_paths
14
+ parsed_json.fetch("exclude_paths")
15
+ end
16
+
17
+ def enabled?
18
+ parsed_json.fetch("enabled")
19
+ end
20
+
21
+ protected
22
+
23
+ attr_reader :json_string
24
+
25
+ private
26
+
27
+ def parsed_json
28
+ @parsed_json = JSON.parse(json_string)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require "virtus"
2
+ require "json"
3
+
4
+ module CCEngine
5
+ class Issue
6
+ include Virtus.model(strict: true)
7
+
8
+ attribute :check_name, String
9
+ attribute :description, String
10
+ attribute :categories, Array[String]
11
+ attribute :location
12
+ attribute :remediation_points
13
+
14
+ def to_json
15
+ to_hash.to_json
16
+ end
17
+
18
+ def to_hash
19
+ {
20
+ type: "issue",
21
+ check_name: check_name,
22
+ description: description,
23
+ categories: categories,
24
+ location: location.to_hash
25
+ }.merge(remediation_points_hash)
26
+ end
27
+
28
+ private
29
+
30
+ def remediation_points_hash
31
+ return {} unless remediation_points
32
+
33
+ {
34
+ remediation_points: remediation_points
35
+ }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ require "cc_engine/location/line_range"
2
+ require "cc_engine/location/position"
@@ -0,0 +1,22 @@
1
+ require "virtus"
2
+
3
+ module CCEngine
4
+ module Location
5
+ class LineRange
6
+ include Virtus.model(strict: true)
7
+
8
+ attribute :path, String
9
+ attribute :line_range, Range
10
+
11
+ def to_hash
12
+ {
13
+ path: path,
14
+ lines: {
15
+ begin: line_range.begin,
16
+ end: line_range.end
17
+ }
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require "virtus"
2
+
3
+ module CCEngine
4
+ module Location
5
+ class Position
6
+ include Virtus.model(strict: true)
7
+
8
+ attribute :path, String
9
+ attribute :start_position
10
+ attribute :end_position
11
+
12
+ def to_hash
13
+ {
14
+ path: path,
15
+ positions: {
16
+ begin: start_position.to_hash,
17
+ end: end_position.to_hash
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require "virtus"
2
+
3
+ module CCEngine
4
+ module Position
5
+ class Grid
6
+ include Virtus.model(strict: true)
7
+
8
+ attribute :line, Integer
9
+ attribute :column, Integer
10
+
11
+ def to_hash
12
+ {
13
+ line: line,
14
+ column: column
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ require "virtus"
2
+
3
+ module CCEngine
4
+ module Position
5
+ class Offset
6
+ include Virtus.model(strict: true)
7
+
8
+ attribute :offset, Integer
9
+
10
+ def to_hash
11
+ {
12
+ offset: offset
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module CCEngine
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "cc_engine/version"
2
+ require "cc_engine/issue"
3
+ require "cc_engine/location"
4
+ require "cc_engine/category"
5
+ require "cc_engine/config"
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeclimate-engine-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Waite
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description:
70
+ email:
71
+ - github.aw@andywaite.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - codeclimate_engine.gemspec
86
+ - lib/cc_engine/category.rb
87
+ - lib/cc_engine/config.rb
88
+ - lib/cc_engine/issue.rb
89
+ - lib/cc_engine/location.rb
90
+ - lib/cc_engine/location/line_range.rb
91
+ - lib/cc_engine/location/position.rb
92
+ - lib/cc_engine/position/grid.rb
93
+ - lib/cc_engine/position/offset.rb
94
+ - lib/cc_engine/version.rb
95
+ - lib/codeclimate_engine.rb
96
+ homepage: https://github.com/andyw8/codeclimate-engine-rb
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: JSON issue formatter for the Code Climate engine
119
+ test_files: []
120
+ has_rdoc: