Skip to content

Commit

Permalink
Standardize EOL to LF
Browse files Browse the repository at this point in the history
  • Loading branch information
friederbluemle committed Feb 2, 2018
1 parent c75c224 commit 90e8190
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 167 deletions.
152 changes: 76 additions & 76 deletions lizard.xsl
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="build">
<xsl:value-of select="build/message" disable-output-escaping="yes"/>
</xsl:template>
<xsl:output method="html" indent="yes"/>

<xsl:template match="cppncss">
<html>
<body>
<table>
<div class="app">
<div class="h3">
<h3>Summary</h3>
<p>Report generated by
<a href="https://github.com/terryyin/lizard">lizard</a>.</p>
</div>
<xsl:apply-templates select="measure[@type='Function']" mode="summary"/>

<xsl:apply-templates select="measure[@type='Function']" mode="fcc"/>

</div>
</table>
</body>
</html>
</xsl:template>


<xsl:template match="measure[@type='Function']" mode="fcc">
<div class="h4">
<h4>Function Code Complexity: </h4>
<table border="1" width="100%" cellspacing="2" cellpadding="3">
<tr>
<th>Function CC</th>
<th>Function lines</th>
<th>Function and File</th>
</tr>
<xsl:for-each select="item">
<xsl:sort data-type="number" order="descending" select="value[3]"/>
<xsl:if test="number(value[3]) >= number(15)">
<tr>
<td>
<xsl:value-of select="value[3]"/>
</td>
<td>
<xsl:value-of select="value[2]"/>
</td>
<td>
<xsl:value-of select="@name"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</div>
</xsl:template>


<xsl:template match="measure[@type='Function']" mode="summary">
<table border="1" width="100%" cellspacing="2" cellpadding="3">
<tr class="a">
<td>Average Function Cyclomatic Complexity</td>
<td>
<xsl:value-of select="format-number(sum(item/value[3]) div count(item), '#.##')"/>
</td>
</tr>
<tr class="b">
<td>Average Function lines of code without comments</td>
<td><xsl:value-of select="format-number(sum(item/value[2]) div count(item), '#.##')"/></td>
</tr>

</table>
</xsl:template>


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="build">
<xsl:value-of select="build/message" disable-output-escaping="yes"/>
</xsl:template>
<xsl:output method="html" indent="yes"/>

<xsl:template match="cppncss">
<html>
<body>
<table>
<div class="app">
<div class="h3">
<h3>Summary</h3>
<p>Report generated by
<a href="https://github.com/terryyin/lizard">lizard</a>.</p>
</div>
<xsl:apply-templates select="measure[@type='Function']" mode="summary"/>

<xsl:apply-templates select="measure[@type='Function']" mode="fcc"/>

</div>
</table>
</body>
</html>
</xsl:template>


<xsl:template match="measure[@type='Function']" mode="fcc">
<div class="h4">
<h4>Function Code Complexity: </h4>
<table border="1" width="100%" cellspacing="2" cellpadding="3">
<tr>
<th>Function CC</th>
<th>Function lines</th>
<th>Function and File</th>
</tr>
<xsl:for-each select="item">
<xsl:sort data-type="number" order="descending" select="value[3]"/>
<xsl:if test="number(value[3]) >= number(15)">
<tr>
<td>
<xsl:value-of select="value[3]"/>
</td>
<td>
<xsl:value-of select="value[2]"/>
</td>
<td>
<xsl:value-of select="@name"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</div>
</xsl:template>


<xsl:template match="measure[@type='Function']" mode="summary">
<table border="1" width="100%" cellspacing="2" cellpadding="3">
<tr class="a">
<td>Average Function Cyclomatic Complexity</td>
<td>
<xsl:value-of select="format-number(sum(item/value[3]) div count(item), '#.##')"/>
</td>
</tr>
<tr class="b">
<td>Average Function lines of code without comments</td>
<td><xsl:value-of select="format-number(sum(item/value[2]) div count(item), '#.##')"/></td>
</tr>

</table>
</xsl:template>


</xsl:stylesheet>
90 changes: 45 additions & 45 deletions lizard_ext/csvoutput.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
'''
This module extends the default output formatting to include CSV.
The output is intended to be the same in structure, with additional
tokens (to reduce the need to post-process), and a reduced verbosity
due to the nature of CSV outputs. The differences are:
* No summary of the included files, only the output
respective of each function.
* No additional output for functions that break any CCN
thresholds.
* Each line has four additional, individual tokens:
* File name
* Function Name
* Function line start
* Function line end
'''


def csv_output(result, verbose):
if verbose:
print("NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")

for source_file in result:
if source_file:
for source_function in source_file.function_list:
if source_function:
print('{},{},{},{},{},"{}","{}","{}","{}",{},{}'.format(
source_function.nloc,
source_function.cyclomatic_complexity,
source_function.token_count,
len(source_function.parameters),
source_function.end_line - source_function.start_line,
"{}@{}-{}@{}".format(
source_function.name.replace("\"","'"),
source_function.start_line,
source_function.end_line,
source_file.filename
),
source_file.filename,
source_function.name.replace("\"","'"),
source_function.long_name.replace("\"","'"),
source_function.start_line,
source_function.end_line
))
'''
This module extends the default output formatting to include CSV.
The output is intended to be the same in structure, with additional
tokens (to reduce the need to post-process), and a reduced verbosity
due to the nature of CSV outputs. The differences are:
* No summary of the included files, only the output
respective of each function.
* No additional output for functions that break any CCN
thresholds.
* Each line has four additional, individual tokens:
* File name
* Function Name
* Function line start
* Function line end
'''


def csv_output(result, verbose):
if verbose:
print("NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")

for source_file in result:
if source_file:
for source_function in source_file.function_list:
if source_function:
print('{},{},{},{},{},"{}","{}","{}","{}",{},{}'.format(
source_function.nloc,
source_function.cyclomatic_complexity,
source_function.token_count,
len(source_function.parameters),
source_function.end_line - source_function.start_line,
"{}@{}-{}@{}".format(
source_function.name.replace("\"","'"),
source_function.start_line,
source_function.end_line,
source_file.filename
),
source_file.filename,
source_function.name.replace("\"","'"),
source_function.long_name.replace("\"","'"),
source_function.start_line,
source_function.end_line
))
92 changes: 46 additions & 46 deletions test/testOutputCSV.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
from mock import Mock, patch
import unittest
import sys
from lizard_ext import csv_output
from test.helper_stream import StreamStdoutTestCase
from lizard import parse_args, print_and_save_modules, FunctionInfo, FileInformation,\
get_extensions, OutputScheme


class TestCSVOutput(StreamStdoutTestCase):


def setUp(self):
StreamStdoutTestCase.setUp(self)
self.option = parse_args("app")
self.foo = FunctionInfo("foo", 'FILENAME', 100)
self.fileSummary = FileInformation("FILENAME", 123, [self.foo])
self.extensions = get_extensions([])
self.scheme = OutputScheme(self.extensions)


def test_csv_header(self):
csv_output([self.fileSummary], True)
self.assertRegexpMatches(sys.stdout.stream,
r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")


def test_csv_no_header(self):
csv_output([self.fileSummary], False)
self.assertEquals(
'1,1,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
sys.stdout.stream.splitlines()[0]
)


def test_print_fileinfo(self):
self.foo.end_line = 100
self.foo.cyclomatic_complexity = 16
fileStat = FileInformation("FILENAME", 1, [self.foo])

csv_output([fileStat], True)

self.assertEquals(
'1,16,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
sys.stdout.stream.splitlines()[1]
)
from mock import Mock, patch
import unittest
import sys
from lizard_ext import csv_output
from test.helper_stream import StreamStdoutTestCase
from lizard import parse_args, print_and_save_modules, FunctionInfo, FileInformation,\
get_extensions, OutputScheme


class TestCSVOutput(StreamStdoutTestCase):


def setUp(self):
StreamStdoutTestCase.setUp(self)
self.option = parse_args("app")
self.foo = FunctionInfo("foo", 'FILENAME', 100)
self.fileSummary = FileInformation("FILENAME", 123, [self.foo])
self.extensions = get_extensions([])
self.scheme = OutputScheme(self.extensions)


def test_csv_header(self):
csv_output([self.fileSummary], True)
self.assertRegexpMatches(sys.stdout.stream,
r"NLOC,CCN,token,PARAM,length,location,file,function,long_name,start,end")


def test_csv_no_header(self):
csv_output([self.fileSummary], False)
self.assertEquals(
'1,1,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
sys.stdout.stream.splitlines()[0]
)


def test_print_fileinfo(self):
self.foo.end_line = 100
self.foo.cyclomatic_complexity = 16
fileStat = FileInformation("FILENAME", 1, [self.foo])

csv_output([fileStat], True)

self.assertEquals(
'1,16,1,0,0,"foo@100-100@FILENAME","FILENAME","foo","foo",100,100',
sys.stdout.stream.splitlines()[1]
)

0 comments on commit 90e8190

Please sign in to comment.