Skip to content

Commit

Permalink
escaped $ in growl messages
Browse files Browse the repository at this point in the history
  • Loading branch information
magnars committed Jun 24, 2011
1 parent 8d476fb commit 57c6abb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
File renamed without changes
File renamed without changes
27 changes: 14 additions & 13 deletions lib/growl-reporter.js
Expand Up @@ -13,15 +13,23 @@ function listen() {
this.repository.on('errorsFixed', this.handleErrorsFixed.bind(this)); this.repository.on('errorsFixed', this.handleErrorsFixed.bind(this));
} }


function escape(text) {
return text.replace('$', '\\$');
}

function notify(title, text, icon) {
growl.notify(escape(text), {
title: escape(title),
image: __dirname + '/../icons/' + icon + '.png'
});
}

function handleErrorsIntroduced(file, errors) { function handleErrorsIntroduced(file, errors) {
var error = 'First error at line ' + errors[0].line + var error = 'First error at line ' + errors[0].line +
' char ' + errors[0].character + ' char ' + errors[0].character +
':\n' + errors[0].reason; ':\n' + errors[0].reason;
var title = 'You introduced ' + pluralize(errors.length, 'lint error') + ' in ' + file.name + ':'; var title = 'You introduced ' + pluralize(errors.length, 'lint error') + ' in ' + file.name + ':';
growl.notify(error, { notify(title, error, 'error');
title: title,
image: __dirname + '/../icons/no.png'
});
} }


var cheers = [ var cheers = [
Expand Down Expand Up @@ -52,22 +60,15 @@ function cheer() {
} }


function congratulate(file) { function congratulate(file) {
growl.notify(file.name + ' is clean.', { notify(cheer(), file.name + ' is clean.', 'clean');
title: cheer(),
image: __dirname + '/../icons/ok.png'
});
} }


function nextError(file) { function nextError(file) {
var error = file.errors[0]; var error = file.errors[0];
var text = 'Next error at line ' + error.line + var text = 'Next error at line ' + error.line +
' char ' + error.character + ' char ' + error.character +
':\n' + error.reason; ':\n' + error.reason;
var title = 'Nice cleanup!'; notify('Nice cleanup!', text, 'more');
growl.notify(text, {
title: title,
image: __dirname + '/../icons/more.png'
});
} }


function handleErrorsFixed(file, fixedError) { function handleErrorsFixed(file, fixedError) {
Expand Down
6 changes: 6 additions & 0 deletions test/growl-reporter-test.js
Expand Up @@ -67,5 +67,11 @@ buster.testCase("growlReporter", {
reason: 'Bah, humbug!' reason: 'Bah, humbug!'
}]}, [{}]); }]}, [{}]);
assert.calledWith(growl.notify, 'Next error at line 19 char 0:\nBah, humbug!'); assert.calledWith(growl.notify, 'Next error at line 19 char 0:\nBah, humbug!');
},

"should escape $": function () {
this.reporter.handleErrorsFixed({name: 'file$.js', errors: []}, [{}]);
assert.calledWith(growl.notify, 'file\\$.js is clean.');
} }

}); });
2 changes: 0 additions & 2 deletions todo.md
@@ -1,7 +1,5 @@
Todo Todo
==== ====
* `$` needs to be escaped in growl messages

* being blamed for introducing an error, AND praised for fixing it, * being blamed for introducing an error, AND praised for fixing it,
when changing around whitespace (changes lines) when changing around whitespace (changes lines)


Expand Down

0 comments on commit 57c6abb

Please sign in to comment.