-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #6799: Add restricted globals rule to eslint #6923
Conversation
@@ -43,7 +43,7 @@ oppia.factory('MusicNotesInputRulesService', [ | |||
// TODO(wxy): validate that inputs.a <= inputs.b | |||
HasLengthInclusivelyBetween: function(answer, inputs) { | |||
var answerLength = _convertSequenceToMidi(answer).length; | |||
return length >= inputs.a && length <= inputs.b; | |||
return answerLength >= inputs.a && answerLength <= inputs.b; |
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.
Hi @seanlip, I am not sure if this change is right. There is no variable length declared in the function and we want to check if answerLength is inclusive between inputs.a and inputs.b (as from the function name and definition). So, was the variable length used here by mistake?
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.
@DubeySandeep can you also please help me here, Thanks!
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.
Goodness, yes, I think so. Really good catch. I wonder how it worked before ... :(
Just wondering, are there tests for this currently?
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.
Yes, this PR adds test to avoid the use of global variables directly.
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.
This was caught since length was flagged as a global variable used directly by eslint. Then, I realized that length here is used by mistake and is not a global variable actually.
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.
Ah I meant tests for HasLengthInclusivelyBetween. Think it's worth adding them? They should be fairly trivial.
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.
Done.
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.
LGTM! (Left one simple comment!)
@@ -41,12 +41,12 @@ oppia.directive('historyTab', ['UrlInterpolationService', function( | |||
'/pages/exploration-editor-page/history-tab/history-tab.directive.html'), | |||
controllerAs: '$ctrl', | |||
controller: [ | |||
'$http', '$log', '$rootScope', '$scope', | |||
'$http', '$log', '$rootScope', '$scope', '$window', |
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.
$window
should go after $uibModal
.
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.
Done!
Codecov Report
@@ Coverage Diff @@
## develop #6923 +/- ##
========================================
Coverage 95.68% 95.68%
========================================
Files 371 371
Lines 51429 51429
========================================
Hits 49212 49212
Misses 2217 2217 Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## develop #6923 +/- ##
========================================
Coverage 95.68% 95.68%
========================================
Files 371 371
Lines 51429 51429
========================================
Hits 49212 49212
Misses 2217 2217 Continue to review full report at Codecov.
|
.eslintrc
Outdated
@@ -73,6 +73,8 @@ | |||
"error", | |||
"always" | |||
], | |||
"no-restricted-globals": [ | |||
"error", "addEventListener", "blur", "close", "closed", "confirm", "defaultStatus", "event", "external", "defaultstatus", "find", "focus", "frameElement", "frames", "history", "innerHeight", "innerWidth", "length", "location", "locationbar", "menubar", "moveBy", "moveTo", "name", "onblur", "onerror", "onfocus", "onload", "onresize", "onunload", "open", "opener", "opera", "outerHeight", "outerWidth", "pageXOffset", "pageYOffset", "parent", "print", "removeEventListener", "resizeBy", "resizeTo", "screen", "screenLeft", "screenTop", "screenX", "screenY", "scroll", "scrollbars", "scrollBy", "scrollTo", "scrollX", "scrollY", "self", "sessionStorage", "status", "statusbar", "stop", "toolbar", "top"], |
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.
Just to check, what is this list representing (and should it be so big? Wondering if we can remove anything.)
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.
The list represents the common global variables which should not be used directly. I found the list from here.
I did not use the package directly since it is not maintained. Also, in the usage rules for this rule, the prescribed way was to add a list in eslintrc with the names of the globals we want to avoid. We can remove the globals which we don't think we need in the codebase. I am not sure how to find out such globals and remove from the list. Can you guide me here, Thanks!
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.
Ah I see, so this is the list we want to avoid. In that case, that sounds good! I was worried that it was a list of what we were willing to accept, and was concerned that the list of exceptions seemed to be so big. No further change needed here, then.
Thanks @ankita240796 !
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.
You're welcome!
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.
Can we also add document, console etc. in this list as we expect to use $log, $document?
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.
Hi folks -- a question for y'all. What's wrong with copying the list and maintaining our copy of it? It seems nice to not have to rely on any dependencies.
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.
Yes, it seems fine to me. Just one concern -- we'll have to update our copy of the list after some interval probably, 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.
Yes, if we plan to add some new globals. I am not sure if the eslint-restricted-globals package is being maintained a lot since the last commit was 7 months ago.
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 think maintaining our own copy has its own pros and cons, but let's not dive into that. I'm okay with having our own copy, but maybe it would be nice to make an PR on the eslint-restricted-globals package (if the globals that we are adding are universal).
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 agree with you on making a PR for the package. I will do that with the globals I have added in this PR as well.
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.
Couple small things, otherwise LGTM. I'll defer to you and @vojtechjelinek re the long comment thread on .eslintrc.
.eslintrc
Outdated
@@ -73,6 +73,8 @@ | |||
"error", | |||
"always" | |||
], | |||
"no-restricted-globals": [ | |||
"error", "addEventListener", "blur", "close", "closed", "confirm", "defaultStatus", "event", "external", "defaultstatus", "find", "focus", "frameElement", "frames", "history", "innerHeight", "innerWidth", "length", "location", "locationbar", "menubar", "moveBy", "moveTo", "name", "onblur", "onerror", "onfocus", "onload", "onresize", "onunload", "open", "opener", "opera", "outerHeight", "outerWidth", "pageXOffset", "pageYOffset", "parent", "print", "removeEventListener", "resizeBy", "resizeTo", "screen", "screenLeft", "screenTop", "screenX", "screenY", "scroll", "scrollbars", "scrollBy", "scrollTo", "scrollX", "scrollY", "self", "sessionStorage", "status", "statusbar", "stop", "toolbar", "top"], |
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.
One separate suggestion -- please add line breaks to the list so that this file is cleanly viewable within an 80-char-width workspace.
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.
Done.
@@ -43,7 +43,7 @@ oppia.factory('MusicNotesInputRulesService', [ | |||
// TODO(wxy): validate that inputs.a <= inputs.b | |||
HasLengthInclusivelyBetween: function(answer, inputs) { | |||
var answerLength = _convertSequenceToMidi(answer).length; | |||
return length >= inputs.a && length <= inputs.b; | |||
return answerLength >= inputs.a && answerLength <= inputs.b; |
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.
Ah I meant tests for HasLengthInclusivelyBetween. Think it's worth adding them? They should be fairly trivial.
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.
lgtm! (from code owner's)
@@ -38,12 +38,12 @@ oppia.factory('MusicNotesInputRulesService', [ | |||
_convertSequenceToMidi(inputs.x)); | |||
}, | |||
IsLongerThan: function(answer, inputs) { | |||
return _convertSequenceToMidi(answer).length > inputs.x; | |||
return _convertSequenceToMidi(answer).length > inputs.k; |
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.
Hi @seanlip, since I added test for the HasLengthInclusivelyBetween
function, I also thought of adding tests of IsLongerThan
since only these two functions did not have tests in the spec file. After looking into the function, I did not find this comparison correct as this was always returning false since inputs.x
is not an integer field but a list instead.
The format for inputs.x is:
x: [{
readableNoteName: 'A4',
noteDuration: {
num: 1,
den: 1
}
}]
I tried to see the exploration yaml by creating and downloading an exploration but it did not work due to #6931.
So, I checked the file pitch_perfect.yaml
where the rule isLongerThan
requires inputs.k
. You can check here.
I am not a lot familiar with this interaction. So, can you please confirm if this change is correct. Thanks!
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.
Yes, you are correct. Thank you very much for checking and for doing this!
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.
LGTM from code owner's perspective. Thanks!
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.
LGTM, thanks @ankita240796! All changes look great.
@apb7 this PR needs your review as codeowner. PTAL!
@@ -38,12 +38,12 @@ oppia.factory('MusicNotesInputRulesService', [ | |||
_convertSequenceToMidi(inputs.x)); | |||
}, | |||
IsLongerThan: function(answer, inputs) { | |||
return _convertSequenceToMidi(answer).length > inputs.x; | |||
return _convertSequenceToMidi(answer).length > inputs.k; |
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.
Yes, you are correct. Thank you very much for checking and for doing this!
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.
LGTM, thanks @ankita240796!
Explanation
Fixes #6799: Adds restricted globals rule to eslint and removes direct use of globals from codebase.