-
Notifications
You must be signed in to change notification settings - Fork 515
Errors.add should throw on invalid calls #744
Errors.add should throw on invalid calls #744
Conversation
e14f790
to
ee4dfd6
Compare
To simplify rules debugging and prevent dumb mistakes. Fixes jscs-dev#743 Closes jscs-dev#744
@@ -28,6 +28,10 @@ Errors.prototype = { | |||
line = line.line; | |||
} | |||
|
|||
if (typeof line !== 'number' || (column && typeof column !== 'number')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the '(column & & ' clause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, because it's declared as optional in jsdoc. Probably it isn't right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K. Makes sense. Please comment above that line with that explanation.
Can you add a test for this please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but I don't know where to place it. In string-checkers?
Also test will look like:
function makeThrowingEsprima(description, line, column) {
return {
parse: function() {
var error = new Error(description);
error.lineNumber = line;
error.column = column;
throw error;
}
};
};
it('should throw an error on errors.add', function() {
checker = new Checker({ esprima: makeThrowingEsprima('object') });
checker.registerDefaultRules();
var errors = checker.checkString('import { foo } from "bar";');
var error = errors.getErrorList()[0];
// check error...
});
Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, because it's declared as optional in jsdoc. Probably it isn't right.
If it is optional, write column === undefined
, don't go with implicit boolean conversion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid error location data: <' + message + '> at <' + line + '>, <' + column + '>
I think this is a bad error message.
I would go for more specific errors like "Unable to add an error,
column should be a number"
, "Unable to add an error,
line should be a number"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I'll change message.
It was a useful proposal with minimal functionality.
ee4dfd6
to
443e68a
Compare
- simplify rules debugging to prevent dumb mistakes and crashes in error reporters. - set 0 as column in rules/disallow-mixed-spaces-and-tabs - add throwing tests for add method Fixes jscs-dev#743 Closes jscs-dev#744
@mdevils @mrjoelkemp Guys, I'm done. Need review. |
443e68a
to
44effc7
Compare
- simplify rules debugging to prevent dumb mistakes and crashes in error reporters. - set 0 as column in rules/disallow-mixed-spaces-and-tabs - add throwing tests for add method Fixes jscs-dev#743 Closes jscs-dev#744
44effc7
to
daded70
Compare
- add method now throws on calls with invalid values - set 0 as column in rules/disallow-mixed-spaces-and-tabs - add throwing tests for add method Fixes jscs-dev#743 Closes jscs-dev#744
} | ||
|
||
it('should throw an error on invalid line', function() { | ||
var checker = new Checker({ esprima: makeThrowingEsprima('msg', 0) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why makeThrowingEsprima is necessary. Why can't you just call errors.add
with arguments that trigger the exception?
Something like:
assert.throws(function() {
errors.add('foo', -1, -1);
})
All of the arguments that you passed to makeThrowingEsprima
could be passed to errors.add
instead.
Would that not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yes. Idk why I did it like that. Gonna fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrjoelkemp fixed, thanks!
43453b2
to
1fe8870
Compare
Great job. The last thing, can you use Example: https://github.com/jscs-dev/node-jscs/blob/master/lib/config/configuration.js#L200 |
@mdevils Sure. I was afraid it's not possible to use there. Going to do that. |
Looks good to me. @mrjoelkemp, @markelog, OK to merge? |
@mdevils I would squash before merging. Should I? |
Yep :) |
- `add` method now throws on calls with invalid values - set 0 as column in rules/disallow-mixed-spaces-and-tabs - `add` throwing tests for add method Fixes jscs-dev#743 Closes jscs-dev#744
4f1a14b
to
1ac6e34
Compare
Done. |
Merged, thanks! |
You are welcome 🌴 |
To simplify rules debugging, prevent dumb mistakes and crashes in error reporters.