Skip to content

Commit 4f3b3d4

Browse files
committed
initial commit
0 parents  commit 4f3b3d4

13 files changed

+253
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.6.3

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
# Specify your gem's dependencies in solargraph_test_coverage.gemspec
4+
gemspec
5+
6+
gem "rake", "~> 12.0"

Gemfile.lock

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
PATH
2+
remote: .
3+
specs:
4+
solargraph_test_coverage (0.1.0)
5+
solargraph (>= 0.43)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
ast (2.4.2)
11+
backport (1.2.0)
12+
benchmark (0.1.1)
13+
diff-lcs (1.4.4)
14+
e2mmap (0.1.0)
15+
jaro_winkler (1.5.4)
16+
kramdown (2.3.1)
17+
rexml
18+
kramdown-parser-gfm (1.1.0)
19+
kramdown (~> 2.0)
20+
nokogiri (1.12.3-x86_64-darwin)
21+
racc (~> 1.4)
22+
parallel (1.20.1)
23+
parser (3.0.2.0)
24+
ast (~> 2.4.1)
25+
racc (1.5.2)
26+
rainbow (3.0.0)
27+
rake (12.3.2)
28+
regexp_parser (2.1.1)
29+
reverse_markdown (2.0.0)
30+
nokogiri
31+
rexml (3.2.5)
32+
rubocop (1.20.0)
33+
parallel (~> 1.10)
34+
parser (>= 3.0.0.0)
35+
rainbow (>= 2.2.2, < 4.0)
36+
regexp_parser (>= 1.8, < 3.0)
37+
rexml
38+
rubocop-ast (>= 1.9.1, < 2.0)
39+
ruby-progressbar (~> 1.7)
40+
unicode-display_width (>= 1.4.0, < 3.0)
41+
rubocop-ast (1.11.0)
42+
parser (>= 3.0.1.1)
43+
ruby-progressbar (1.11.0)
44+
solargraph (0.43.0)
45+
backport (~> 1.2)
46+
benchmark
47+
bundler (>= 1.17.2)
48+
diff-lcs (~> 1.4)
49+
e2mmap
50+
jaro_winkler (~> 1.5)
51+
kramdown (~> 2.3)
52+
kramdown-parser-gfm (~> 1.1)
53+
parser (~> 3.0)
54+
reverse_markdown (>= 1.0.5, < 3)
55+
rubocop (>= 0.52)
56+
thor (~> 1.0)
57+
tilt (~> 2.0)
58+
yard (~> 0.9, >= 0.9.24)
59+
thor (1.1.0)
60+
tilt (2.0.10)
61+
unicode-display_width (2.0.0)
62+
yard (0.9.26)
63+
64+
PLATFORMS
65+
x86_64-darwin-20
66+
67+
DEPENDENCIES
68+
rake (~> 12.0)
69+
solargraph_test_coverage!
70+
71+
BUNDLED WITH
72+
2.2.12

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Cameron
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SolargraphTestCoverage
2+
3+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/solargraph_test_coverage`. To experiment with that code, run `bin/console` for an interactive prompt.
4+
5+
TODO: Delete this and the text above, and describe your gem
6+
7+
## Installation
8+
9+
Add this line to your application's Gemfile:
10+
11+
```ruby
12+
gem 'solargraph_test_coverage'
13+
```
14+
15+
And then execute:
16+
17+
$ bundle install
18+
19+
Or install it yourself as:
20+
21+
$ gem install solargraph_test_coverage
22+
23+
## Usage
24+
25+
TODO: Write usage instructions here
26+
27+
## Development
28+
29+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30+
31+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32+
33+
## Contributing
34+
35+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/solargraph_test_coverage.
36+
37+
38+
## License
39+
40+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "bundler/gem_tasks"
2+
task :default => :spec

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "solargraph_test_coverage"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start(__FILE__)

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

lib/solargraph_test_coverage.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'solargraph_test_coverage/version'
2+
require "json"
3+
require "solargraph"
4+
5+
module SolargraphTestCoverage
6+
class Error < StandardError; end
7+
8+
class TestCoverageReporter < Solargraph::Diagnostics::Base
9+
def diagnose(source, _api_map)
10+
return [] if source.code.empty? || !source.location.filename.include?("/app/")
11+
12+
test_file = locate_test_file(source)
13+
return [] unless File.file?(test_file)
14+
15+
test_file_content = File.read(test_file)
16+
return [] unless test_file_content.include? "SingleCov.covered"
17+
18+
pid = Process.spawn("SINGLE_COV_GEN_REPORT=1 bundle exec rspec #{test_file}", out: "/dev/null")
19+
Process.wait(pid)
20+
21+
results_file = source.location.filename.sub(%r{/app/.*}, "/coverage/.resultset_singlecov.json")
22+
results = JSON.parse(File.read(results_file)).dig("Minitest", "coverage", source.location.filename)
23+
24+
results.map.with_index { |count, index| coverage_error(source, index) if count&.zero? }
25+
.compact
26+
end
27+
28+
private
29+
30+
def locate_test_file(source)
31+
source.location.filename.sub("/app/", "/spec/")
32+
.sub(".rb", "_spec.rb")
33+
end
34+
35+
def coverage_error(source, index)
36+
{
37+
range: Solargraph::Range.from_to(index, 0, index, source.code.lines[index].length).to_hash,
38+
severity: Solargraph::Diagnostics::Severities::WARNING,
39+
source: 'TestCoverage',
40+
message: 'Line is not covered by spec'
41+
}
42+
end
43+
end
44+
45+
Solargraph::Diagnostics.register 'test_coverage', TestCoverageReporter
46+
end
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module SolargraphTestCoverage
2+
VERSION = "0.1.0"
3+
end

solargraph_test_coverage-0.1.0.gem

7.5 KB
Binary file not shown.

solargraph_test_coverage.gemspec

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require_relative 'lib/solargraph_test_coverage/version'
2+
3+
Gem::Specification.new do |spec|
4+
spec.name = 'solargraph_test_coverage'
5+
spec.version = SolargraphTestCoverage::VERSION
6+
spec.authors = ['Cameron Kolkey']
7+
spec.email = ['[email protected]']
8+
9+
spec.summary = 'Solargraph Plugin'
10+
spec.description = 'Solargraph Plugin that uses SingleCov to report line coverage'
11+
spec.homepage = 'https://github.com/ckolkey/solargraph_test_coverage'
12+
spec.license = 'MIT'
13+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14+
15+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
16+
17+
spec.metadata['homepage_uri'] = spec.homepage
18+
spec.metadata['source_code_uri'] = spec.homepage
19+
spec.metadata['changelog_uri'] = spec.homepage
20+
21+
# Specify which files should be added to the gem when it is released.
22+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
24+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25+
end
26+
spec.bindir = 'exe'
27+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28+
spec.require_paths = ['lib']
29+
30+
# spec.add_runtime_dependency 'pry-byebug', '~>3'
31+
spec.add_runtime_dependency 'solargraph', '~> 0.43'
32+
end

0 commit comments

Comments
 (0)