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 Jun 24, 2016
1 parent e533ede commit 0747b75
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 54 deletions.
7 changes: 4 additions & 3 deletions lib/report/error_dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,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 @@ -57,11 +57,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) {
var comment = [],
pos = el.position,
word = el.word;

if(utils.hasEnRu(word)) {
Expand All @@ -71,8 +72,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">' + (el.suggest ? (el.suggest.map(function(w) {
return '<span class="word">' + _.escape(w) + '</span>';
}).join(', ')) : '') + '</td>');
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
13 changes: 7 additions & 6 deletions lib/report/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ module.exports = {
var 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) {
var comment = [],
word = el.word,
pos = el.position,
buf = [];

if(utils.hasEnRu(word)) {
Expand All @@ -47,13 +48,13 @@ module.exports = {
}

buf.push('|' + (i + 1));
buf.push('|`' + _.escape(el.word) + '`');
buf.push('|' + el.count);
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('|' + (el.suggest ? (el.suggest.map(function(w) {
return '`' + _.escape(w) + '`';
}).join(', ')) : '&nbsp;'));
buf.push('|' + (comment.length ? comment.join('<br/>') : '&nbsp;') + '|\n');
buf.push('|' + (comment.length ? comment.join('<br/>') : '&nbsp;') + '|');

text.push(buf.join(''));
});
}
Expand Down
34 changes: 23 additions & 11 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 All @@ -40,7 +42,7 @@ module.exports = {
*/
forResources: function(resources, settings) {
var tasks = [];

resources.forEach(function(resource) {
tasks.push(function(cb) {
var subTasks = [];
Expand All @@ -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 All @@ -90,7 +92,7 @@ module.exports = {
}
});
});

return tasks;
},
/**
Expand All @@ -114,8 +116,18 @@ module.exports = {

process.stdin.on('end', function() {
var 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
Loading

0 comments on commit 0747b75

Please sign in to comment.