CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fixes the exception thrown when the provider list for a given language is undefined. #10068
Fixes the exception thrown when the provider list for a given language is undefined. #10068
Conversation
…e is empty/undefined.
No problem. We should probably add a unit test for that and other similar smallish code paths |
I'm surprised that this unit test didn't catch this bug -- and I'm not sure about any other code paths that could be tested. Should I add a unit test that modifiying the returned array doesn't modify CodeInspection's version of the array? |
The unit test I was thinking about is to go back to the crash, add a test that reproduces the issue, then fix it so that the unit test passes. |
There are 3 failing tests due to this in master. No need to add additional ones. @Mark-Simulacrum, it's necessary to reload/restart Brackets before running the tests again. Otherwise you run old code (which didn't fail because it didn't have EDIT: or better yet -- use Debug -> New Brackets Window and run the tests from it. |
Ah, that must have been my mistake -- I opened and closed the test window, but didn't reload Brackets. |
@@ -161,7 +161,7 @@ define(function (require, exports, module) { | |||
* @return ?{Array.<{name:string, scanFileAsync:?function(string, string):!{$.Promise}, scanFile:?function(string, string):?{errors:!Array, aborted:boolean}}>} provider | |||
*/ | |||
function getProvidersForPath(filePath) { | |||
return _providers[LanguageManager.getLanguageForPath(filePath).getId()].slice(0) || []; | |||
return (_providers[LanguageManager.getLanguageForPath(filePath).getId()] || []).slice(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.
Could you actually split this into two steps? Something like
var providers = _providers[LanguagerManager...];
return (providers && providers.slice(0)) || [];
It's not easily readable...
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.
Fixed.
@busykai Cool. If we have failing tests than that means it was just an oversight rather than lack of unit tests. So no need to add a unit test. |
There is still more to be done. Since |
there's a |
@Mark-Simulacrum you run a |
@busykai I agree with you... immutable objects would be nice |
@MiguelCastillo @busykai You suggested adding the |
@Mark-Simulacrum I am torn about the deep clone though. We want to keep people from unintentionally messing up the providers. |
If we do a deep copy, it is somewhat difficult to check within a unit test environment if the linter(s) returned from the function are the linters that we registered, because they are cloned and as such are not strictly equal to each other. |
I think freezing providers on registration is a good idea, but it's out of scope of this PR. This one fixes much more immediate issue and needs to be merged ASAP. :) |
@busykai agreed. Merging. |
Fixes the exception thrown when the provider list for a given language is undefined.
Sorry, I have missed this. Thanks for fixing to quickly. |
My fault for not noticing this before. Hope that no one is majorly affected by this error!
/cc @MiguelCastillo