Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1c0a64e
Add Show Ruby Coverage command to Command Palette.
sentience Jun 12, 2015
fe582e8
Move utility functions to the end of the file.
sentience Jun 12, 2015
88bb71a
Simplify language of comment and status message.
sentience Jun 12, 2015
6e3edaa
Simplify EventListner class name.
sentience Jun 12, 2015
a3924b0
Remove debug output.
sentience Jun 12, 2015
a498709
Rename main code file in preparation for creating additional files.
sentience Jun 12, 2015
67b3188
Simplify function comment.
sentience Jun 12, 2015
ae61b1e
Highlight uncovered lines, rather than using gutter icons.
sentience Jun 12, 2015
7203dc4
Instead of showing coverage on load, make command toggle it on/off.
sentience Jun 12, 2015
27a7b78
Use output of simplecov-json formatter, not simplecov-sublime-ruby-co…
sentience Jun 13, 2015
edebcd8
Augment active color scheme with colors for coverage view.
sentience Jun 13, 2015
1c96093
Add configurable coverage highlighting levels.
sentience Jun 13, 2015
a1bd370
Fix broken color scheme on excluded files.
sentience Jun 13, 2015
a73cc7b
Display coverage level per line in status bar.
sentience Jun 13, 2015
2ab2ce2
Scroll to first uncovered line when showing coverage view (off by def…
sentience Jun 13, 2015
ed0fefe
Add package settings menu items.
sentience Jun 13, 2015
028fdce
Display file coverage percentage in status bar.
sentience Jun 13, 2015
579fa90
Combine adjacent lines with same coverage level into one region.
sentience Jun 13, 2015
3eb0b81
Extract shared functionality into JsonCoverageReader.
sentience Jun 13, 2015
cdfc37c
Move ThemeGenerator to common directory.
sentience Jun 13, 2015
7293e9e
Fix error on generating status for non-covered file.
sentience Jun 13, 2015
bdc7d54
Display coverage status immediately on file open.
sentience Jun 13, 2015
b7eeb94
Refactor: extract methods.
sentience Jun 13, 2015
dc33306
Fix error on status for last line in file.
sentience Jun 13, 2015
b38934c
DRY up coverage region chunking.
sentience Jun 13, 2015
e0808ce
Better support uncovered files.
sentience Jun 13, 2015
0507a20
Convert some functions into class methods.
sentience Jun 13, 2015
fa64cd3
Fix errors editing Ruby files with no coverage data.
sentience Jun 13, 2015
06acc6d
Add Show Project Ruby Coverage command.
sentience Jun 14, 2015
2a87f09
Remove obsolete imports.
sentience Jun 14, 2015
7a8cdbe
Right-justify coverage values in Project Coverage view.
sentience Jun 14, 2015
0ee306d
Tweak command names.
sentience Jun 14, 2015
85ebdf3
Add bar graph to project coverage view.
sentience Jun 14, 2015
82e7568
Display project coverage with color-coded bar graph.
sentience Jun 14, 2015
08c5eaf
Improve graph color gradient.
sentience Jun 15, 2015
7be2213
Display correct coverage graph dimensions on initial panel creation.
sentience Jun 15, 2015
bd3869c
Add compact project coverage graph layout when viewport is narrow.
sentience Jun 15, 2015
ae20c60
Split project coverage graph layouts into separate methods.
sentience Jun 15, 2015
375dfd6
Add licence. Update README for new features.
sentience Jun 15, 2015
a3d1c65
Get coverage for first open folder when no open file is available.
sentience Jun 15, 2015
99e874a
Only display Toggle Ruby Coverage command in Ruby files.
sentience Jun 15, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[
{ "keys": ["super+shift+c"], "command": "show_ruby_coverage"}
{ "keys": ["super+shift+c"], "command": "toggle_ruby_coverage"}
]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Kevin Yank <thatguy@kevinyank.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
29 changes: 29 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"id": "preferences",
"children": [
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children": [
{
"caption": "SublimeRubyCoverage",
"children": [
{
"command": "open_file",
"args": {"file": "${packages}/SublimeRubyCoverage/SublimeRubyCoverage.sublime-settings"},
"caption": "Settings – Default"
}, {
"command": "open_file",
"args": {"file": "${packages}/User/SublimeRubyCoverage.sublime-settings"},
"caption": "Settings – User"
}
]
}
]
}
]
}

]
64 changes: 26 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,43 @@
SublimeRubyCoverage
====================
Sublime Ruby Coverage
=====================

A plugin for Sublime Text 2 that can highlight lines of Ruby lacking test coverage.
A plugin for Sublime Text 3 for visualising SimpleCov code coverage data in your editor.

Features
--------

* Toggle highlighting of covered (green) and uncovered (red) lines of code.
* Shade of green indicates coverage level (with configurable thresholds).
* Highlight colors configurable.
* View whole file and current line coverage statistics in the status bar.
* Can be disabled in user settings.
* View list of all covered files in project, from least to most coverage.
* Includes color-coded coverage graph (colors configurable).
* Supports wide and compact layouts depending on window width.

Installation
------------

You will need to setup [simplecov-sublime-ruby-coverage](http://github.com/integrum/simplecov-sublime-ruby-coverage) in your project.
First, you must have [SimpleCov](https://github.com/colszowka/simplecov) installed and configured for your project.

Set up [Sublime Package Control](http://wbond.net/sublime_packages/package_control)
if you don't have it yet.
Next, install and set up the [simplecov-json](https://github.com/vicentllongo/simplecov-json) formatter. If you’re using SimpleCov 0.9 or later, you have the option of using multiple formatters, so you can continue to generate the default HTML report along with the JSON report required by this package.

Go to Tools > Command Palette.
Type `Package Control: Install Package` and hit enter.
Type `Ruby Coverage` and hit enter.
Finally, install Sublime Ruby Coverage using [Package Control](https://packagecontrol.io):

1. With Package Control installed, go to Tools > Command Palette.
2. Select the **Package Control: Install Package** command and hit Enter.
3. Type **Ruby Coverage** and hit Enter.

Usage
-----

To set color of the marks, add the following to your **color scheme** settings array:
Run your tests to generate a **coverage/coverage.json** file in your project. Then:

<dict>
<key>name</key>
<string>coverage.uncovered</string>
<key>scope</key>
<string>coverage.uncovered</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#ffff33</string>
</dict>
</dict>
* Move your cursor around in one of the project’s Ruby files to see file and line coverage info in the status bar.
* Open Command Palette and choose **Ruby Coverage: Toggle Coverage Highlight** to display file coverage as green and red colored highlights. By default, lines covered once are highlighted in dark green, lines covered twice are highlighted in brighter green, and lines covered 50 or more times are displayed in very bright green. Invoke the command again to turn highlights off.
* Open Command Palette and choose **Ruby Coverage: Show Project Coverage** to open a panel containing a list of covered Ruby files in your project, from least to most coverage, with a color-coded bar graph indicating the coverage for each file.

Ignoring Files
--------------

Add a .covignore file to your project root in order to add custom ignores.

Highlighting lines missing coverage
-----------------------------------

When you open a .rb file,
SublimeRubyCoverage tries to find coverage information
and highlight all uncovered lines with an outline.

It does this by looking in all parent directories
until it finds a `coverage/sublime-ruby-coverage` directory as produced by [simplecov-sublime-ruby-coverage](http://github.com/integrum/simplecov-sublime-ruby-coverage).
The coverage file is expected to have as many lines as the source file, with each line containing a 1 if the line is covered or a 0 if it is not.

You can force a reload of the coverage information
and redraw of the outlines
by running the `show_ruby_coverage` command,
bound to super+shift+c by default.
Common “non-code” Ruby files, such as spec files, are ignored automatically. Add a .covignore file to your project root in order to add additional, custom ignores.
95 changes: 0 additions & 95 deletions SublimeRubyCoverage.py

This file was deleted.

4 changes: 4 additions & 0 deletions SublimeRubyCoverage.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "caption": "Ruby Coverage: Toggle Coverage Highlight", "command": "toggle_ruby_coverage"},
{ "caption": "Ruby Coverage: Show Project Coverage", "command": "show_project_ruby_coverage"}
]
55 changes: 55 additions & 0 deletions SublimeRubyCoverage.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
/*
Change this to `true` to scroll to the first uncovered line
automatically when you activate the coverage view.
*/
"auto_scoll_to_uncovered": false,

/*
Sets the coverage levels at which coverage color
shades are applied to a line.
*/
"coverage_levels": {
"covered": 1,
"more_covered": 2,
"most_covered": 50
},

"colors": {
/*
Colors used to display coverage.
*/
"coverage": {
"uncovered_foreground": "#F9F9F4",
"uncovered_background": "#A83732",
"covered_foreground": "#F9F9F4",
"covered_background": "#287020",
"covered_foreground_bold": "#F9F9F4",
"covered_background_bold": "#37A832",
"covered_foreground_extrabold": "#F9F9F4",
"covered_background_extrabold": "#43D53E"
},

/*
Colors used in coverage bar graph.
*/
"graph": {
"0": "#FB0109",
"10": "#FB130A",
"20": "#FB360A",
"30": "#FB5B0A",
"40": "#FB7A0A",
"50": "#FD920A",
"60": "#FDB70B",
"70": "#FEE00A",
"80": "#FEFE0B",
"90": "#90FE09",
"100": "#36FF07"
}
},

/*
Change this to `false` to suppress coverage status in status bar.
*/
"coverage_status_in_status_bar": true
}
80 changes: 80 additions & 0 deletions common/json_coverage_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import json
import re

class JsonCoverageReader:
"""
For any file in a project with JSON SimpleCov coverage data,
makes whole-project, whole-file and line-specific coverage data available.
"""

def __init__(self, filename):
""" Load coverage data given the filename for any file in the project. """
self.project_root = get_project_root(filename)
self.coverage = self.get_coverage_data() if self.project_root else None

def get_project_coverage(self):
coverage_data = dict(self.coverage)
coverage_data['files'] = list(map(self.make_filename_relative, coverage_data['files']))
coverage_data['files'].sort(key=lambda file: file['covered_percent'])
return coverage_data

def get_file_coverage(self, filename):
if self.coverage is None or self.is_file_exempt(filename):
return

coverage_files = self.coverage['files']
for coverage_file in coverage_files:
if coverage_file['filename'] == filename:
return coverage_file

def is_file_exempt(self, filename):
normalized_filename = os.path.normpath(filename).replace('\\', '/')

exempt = [r'/test/', r'/spec/', r'/features/', r'Gemfile$', r'Rakefile$', r'\.rake$',
r'\.gemspec']

ignore = os.path.join(self.project_root, '.covignore')
if os.path.isfile(ignore):
for path in open(ignore).read().rstrip("\n").split("\n"):
exempt.append(path)

for pattern in exempt:
if re.compile(pattern).search(normalized_filename) is not None:
return True
return False

def get_coverage_data(self):
coverage_filename = self.get_coverage_filename()
if not coverage_filename:
return

return json.load(open(coverage_filename))

def make_filename_relative(self, file):
file['filename'] = os.path.relpath(file['filename'], self.project_root)
return file

def get_coverage_filename(self):
if not self.project_root:
return

coverage_filename = os.path.join(self.project_root, 'coverage', 'coverage.json')
if not os.access(coverage_filename, os.R_OK):
print('Could not find coverage.json file.')
return

return coverage_filename

def get_project_root(filename):
"""the parent directory that contains a directory called 'coverage'"""
coverage_directory = os.path.join(filename, 'coverage')
if os.access(coverage_directory, os.R_OK):
return filename

parent, current = os.path.split(filename)
if not current:
print('Could not find coverage directory.')
return

return get_project_root(parent)
Loading