Repository: Bachmann1234/diff_cover

Issue:
any ways to get all measured lines' numbers from json report
# background
I develop a tool to collect diff coverage based on diff_cover json output for further source code rendering in web.  
In this case, all measured lines(or all lines that should be covered by testing) and violation lines of each source file are important.

Are there any options to output the measured(tracked) lines in json report? Or other possible outputs that can make it easy to compute it like covered lines(covered lines + violation lines = tracked lines).

I use this command. `diff-cover  diff-cover coverage.xml --json-report report.json`

e.g.

Currently, for given git diff like:  
```
diff --git a/my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java b/my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java
index 1633ede..52b785e 100644
--- a/my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java
+++ b/my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java
@@ -9,6 +9,10 @@ public class JCalculator {
         if (b == 0) {
             throw new ArithmeticException("Divide zero!");
         }
+        // neg divide
+        if (b < 0) {
+            throw new ArithmeticException("Divide neg!");
+        }
         return a / b;
     }
 }
\ No newline at end of file
```

```json
{
  "report_name": "XML",
  "diff_name": "origin/master...HEAD, staged and unstaged changes",
  "src_stats": {
    "my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java": {
      "percent_covered": 50.0,
      "violation_lines": [
        14
      ],
      "violations": [
        [
          14,
          null
        ]
      ]
    }
  },
  "total_num_lines": 2,
  "total_num_violations": 1,
  "total_percent_covered": 50,
  "num_changed_lines": 4
}
```

# expected

For source file `my_module/src/main/java/com/zsmallx/example/java_calculator/JCalculator.java`, the output be like:  
```
"violation_lines": [
        14
 ],
"measured_lines": [
        13,
        14
]
```

Comments:

Patch:
diff --git a/diff_cover/report_generator.py b/diff_cover/report_generator.py
index ad2e58a..0262838 100644
--- a/diff_cover/report_generator.py
+++ b/diff_cover/report_generator.py
@@ -105,6 +105,25 @@ class BaseReportGenerator(ABC):
 
         return None
 
+    def covered_lines(self, src_path):
+        """
+        Returns a list of lines covered in measured lines (integers)
+        in `src_path` that were changed.
+
+        If we have no coverage information for
+        `src_path`, returns an empty list.
+        """
+        diff_violations = self._diff_violations().get(src_path)
+
+        if diff_violations is None:
+            return []
+
+        return sorted(
+            set(diff_violations.measured_lines).difference(
+                set(self.violation_lines(src_path))
+            )
+        )
+
     def violation_lines(self, src_path):
         """
         Return a list of lines in violation (integers)
@@ -213,6 +232,8 @@ class BaseReportGenerator(ABC):
         Return a dict of statistics for the source file at `src_path`.
         """
 
+        covered_lines = self.covered_lines(src_path)
+
         # Find violation lines
         violation_lines = self.violation_lines(src_path)
         violations = sorted(self._diff_violations()[src_path].violations)
@@ -220,6 +241,7 @@ class BaseReportGenerator(ABC):
         return {
             "percent_covered": self.percent_covered(src_path),
             "violation_lines": violation_lines,
+            "covered_lines": covered_lines,
             "violations": violations,
         }
 


Test patch:
diff --git a/tests/test_report_generator.py b/tests/test_report_generator.py
index e7e7180..926d82b 100644
--- a/tests/test_report_generator.py
+++ b/tests/test_report_generator.py
@@ -280,11 +280,13 @@ class TestJsonReportGenerator(BaseReportGeneratorTest):
                 "diff_name": "main",
                 "src_stats": {
                     "file1.py": {
+                        "covered_lines": [2, 3, 4, 15],
                         "percent_covered": 66.66666666666667,
                         "violation_lines": [10, 11],
                         "violations": [[10, None], [11, None]],
                     },
                     "subdir/file2.py": {
+                        "covered_lines": [2, 3, 4, 15],
                         "percent_covered": 66.66666666666667,
                         "violation_lines": [10, 11],
                         "violations": [[10, None], [11, None]],
@@ -312,6 +314,7 @@ class TestJsonReportGenerator(BaseReportGeneratorTest):
                 "diff_name": "main",
                 "src_stats": {
                     "file.py": {
+                        "covered_lines": [2],
                         "percent_covered": 100.0,
                         "violation_lines": [],
                         "violations": [],