Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Added line number and columns number in reports
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Sep 4, 2016
1 parent 1268e62 commit dd808b8
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 78 deletions.
7 changes: 4 additions & 3 deletions lib/report/error_dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ module.exports = {

if (a > b) {
return 1;
} else if (a === b) {
return 0;
} else {
}
if (a < b) {
return -1;
}

return 0;
});

try {
Expand Down
9 changes: 6 additions & 3 deletions lib/report/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ module.exports = {
html.push('<table class="table"><caption>' + el.title + '</caption>');
html.push('<tr><th class="table-num">Num.</th>' +
'<th class="table-name">Typo</th>' +
'<th class="table-count">Count</th>' +
'<th class="table-line">Line:Col</th>' +
'<th class="table-suggest">Suggest</th>' +
'<th class="table-comment">Comment</th></tr>');
typos.forEach(function(el, i) {
const comment = [];
const pos = el.position;
const suggest = el.suggest ? el.suggest.map(w => '<span class="word">' + escape(w) + '</span>').join(', ') : '';

if (utils.hasEnRu(el.word)) {
Expand All @@ -74,8 +75,10 @@ module.exports = {

html.push('<tr>');
html.push('<td class="table-num">' + (i + 1) + '.</td>');
html.push('<td class="table-name"><span class="word">' + escape(el.word) + '</span></td>');
html.push('<td class="table-count">' + el.count + '</td>');
html.push('<td class="table-name"><span class="word">' + escape(el.word) + '</span>' +
(el.count > 1 ? '<sup class="table-count">' + el.count + '</sup>' : '') +
'</td>');
html.push('<td class="table-line">' + (pos.length ? pos[0].line + ':' + pos[0].column : '') + '</td>');
html.push('<td class="table-suggest">' + suggest + '</td>');
html.push('<td class="table-comment">' + (comment.length ? comment.join('<br/>') : '') + '</td>');
html.push('</tr>');
Expand Down
62 changes: 39 additions & 23 deletions lib/report/html/template.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
html, body
html,
body
{
font-size: 1em;
font-family: Arial, sans-serif;
font-size: 1em;
}

body.show-only-errors_checked .ok
Expand All @@ -11,7 +12,7 @@ body.show-only-errors_checked .ok

body.show-only-errors_checked .sym-ok-group
{
opacity: 0.2;
opacity: .2;
}

.page
Expand All @@ -21,30 +22,35 @@ body.show-only-errors_checked .sym-ok-group

.word
{
background-color: rgba(0, 0, 0, 0.05);
padding: .1em .2em;

border-radius: 3px;
padding: 0.1em 0.2em;
background-color: rgba(0, 0, 0, .05);
}

.table
{
table-layout: fixed;
font-size: .9em;

width: 100%;
margin-left: 2em;
font-size: 0.9em;

table-layout: fixed;
border-spacing: 0 0;
border-collapse: collapse;
}

.table th
{
font-weight: bold;

text-align: center;
}

.table th, .table td
.table th,
.table td
{
padding: 0.3em;
padding: .3em;
}

.table tr:nth-child(2n)
Expand All @@ -54,40 +60,46 @@ body.show-only-errors_checked .sym-ok-group

.table tr:hover
{
background-color: #f0f0f0;
background-color: #f0f0f0;
}

.table caption
{
font-size: 1.2em;
margin-top: 1em;
margin-bottom: 0.5em;
font-weight: bold;

margin-top: 1em;
margin-bottom: .5em;

text-align: left;
}

.table td,
.table th
{
border: 1px solid #ddd;
padding: 6px 13px;

text-align: left;

border: 1px solid #ddd;
}

.table-num,
.table-count
.table .table-num
{
width: 2em;

text-align: right;
}

.table-num
.table .table-line
{
width: 2em;
text-align: right;
width: 4em;
}

.table-count
.table sup.table-count
{
width: 2.5em;
margin-left: 3px;
font-size: 0.8em;
}

.syserr,
Expand Down Expand Up @@ -117,8 +129,10 @@ body.show-only-errors_checked .sym-ok-group
.sym-ok,
.sym-err
{
display: inline-block;
font-weight: bold;

display: inline-block;

width: 1em;
}

Expand All @@ -134,9 +148,11 @@ body.show-only-errors_checked .sym-ok-group

.time
{
margin-left: 0.5em;
font-size: .8em;

margin-left: .5em;

color: #999;
font-size: 0.8em;
}

a:not([href]),
Expand Down
16 changes: 9 additions & 7 deletions lib/report/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ module.exports = {
const typos = utils.getTyposByCode(el.code, data.data);
if (typos.length) {
text.push('**' + el.title + '**\n\n' +
'|Num.|Typo|Count|Suggest|Comment|\n' +
'|---:|----|----:|-------|-------|');
'|Num.|Typo|Line:Col|Suggest|Comment|\n' +
'|---:|----|--------|-------|-------|');
typos.forEach(function(el, i) {
const comment = [];
const buf = [];
const comment = [];
const pos = el.position;
const suggest = el.suggest ? el.suggest.map(word => '`' + escape(word) + '`').join(', ') : '&nbsp;';

if (utils.hasEnRu(el.word)) {
comment.push('`en: ' + escape(utils.replaceRu(el.word)) + '`');
comment.push('`ru: ' + escape(utils.replaceEn(el.word)) + '`');
}

buf.push('|' + (i + 1));
buf.push('|`' + escape(el.word) + '`');
buf.push('|' + el.count);
buf.push('|' + (el.suggest ? (el.suggest.map(w => '`' + escape(w) + '`').join(', ')) : '&nbsp;'));
buf.push('|' + (comment.length ? comment.join('<br/>') : '&nbsp;') + '|\n');
buf.push('|`' + escape(el.word) + '`' + (el.count > 1 ? ' <sup>' + el.count + '</sup>': ''));
buf.push('|' + (pos.length ? pos[0].line + ':' + pos[0].column : '&nbsp;'));
buf.push('|' + suggest);
buf.push('|' + (comment.length ? comment.join('<br/>') : '&nbsp;') + '|');

text.push(buf.join(''));
});
Expand Down
20 changes: 11 additions & 9 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ function hasData(err, data) {
return !err && data && Array.isArray(data.data) && data.data.length;
}

function onResource(err, data) {
function onResource(err, data, originalText) {
if (hasData(err, data)) {
data.data = dict.removeDictWords(data.data);
data.data = yaspeller.removeDuplicates(data.data);

yaspeller.addPositions(originalText, data.data);
}

if (!process.exitCode && hasData(err, data)) {
Expand Down Expand Up @@ -50,8 +52,8 @@ module.exports = {
cb();
}, settings, onResource);
} else {
yaspeller.checkUrl(resource, function(err, data) {
onResource(err, data);
yaspeller.checkUrl(resource, function(err, data, originalText) {
onResource(err, data, originalText);
cb();
}, settings);
}
Expand All @@ -62,8 +64,8 @@ module.exports = {
.findFiles(resource, settings.fileExtensions, settings.excludeFiles)
.forEach(function(file) {
subTasks.push(function(subcb) {
yaspeller.checkFile(file, function(err, data) {
onResource(err, data);
yaspeller.checkFile(file, function(err, data, originalText) {
onResource(err, data, originalText);
subcb();
}, settings);
});
Expand All @@ -77,8 +79,8 @@ module.exports = {
if (utils.isExcludedFile(file, settings.excludeFiles)) {
cb();
} else {
yaspeller.checkFile(file, function(err, data) {
onResource(err, data);
yaspeller.checkFile(file, function(err, data, originalText) {
onResource(err, data, originalText);
cb();
}, settings);
}
Expand Down Expand Up @@ -114,8 +116,8 @@ module.exports = {

process.stdin.on('end', function() {
const startTime = Date.now();
yaspeller.checkText(text, function(err, data) {
onResource(err, err ? data : {resource: 'stdin', data: data, time: Date.now() - startTime});
yaspeller.checkText(text, function(err, data, originalText) {
onResource(err, err ? data : {resource: 'stdin', data: data, time: Date.now() - startTime}, originalText);
cb();
}, settings);
});
Expand Down

0 comments on commit dd808b8

Please sign in to comment.