-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add eslint checks to CI #85285
Add eslint checks to CI #85285
Conversation
Some changes occurred in HTML/CSS/JS. |
This comment has been minimized.
This comment has been minimized.
cd062c4
to
6b09ee6
Compare
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.
Is there a way for this to print the command for replicating the error when it fails?
@@ -37,4 +38,5 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \ | |||
python3 ../x.py doc --stage 0 library/std && \ | |||
/scripts/validate-toolstate.sh && \ | |||
# Runs checks to ensure that there are no ES5 issues in our JS code. | |||
es-check es5 ../src/librustdoc/html/static/*.js | |||
es-check es5 ../src/librustdoc/html/static/*.js && \ | |||
eslint ../src/librustdoc/html/static/*.js |
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.
Wouldn't it be better to make this part of x.py? That way it's easier for people to run locally, this is really hard to find.
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, installing eslint isn't "easy" (requires to have npm
then to run npm install eslint
and if you're lucky, everything has been installed correctly) and I have no idea how all of that can work on windows. Considering that it fails pretty quickly and everyone has access to the log, I think it's enough.
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.
Also I juste realized that I added a tab instead of whitespaces...
6b09ee6
to
55bec99
Compare
This comment has been minimized.
This comment has been minimized.
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 is great! Nice work.
src/librustdoc/html/static/search.js
Outdated
@@ -254,7 +257,7 @@ window.initSearch = function(rawSearchIndex) { | |||
}); | |||
|
|||
for (i = 0, len = results.length; i < len; ++i) { | |||
var result = results[i]; |
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 this code was correct; result
is only needed inside the scope of this for
loop. The problem is up at line 178, where var result
is declared with a large scope than it needs. Instead that one should be moved inside the for loop like this one. Arguably the same is true of i
and len
: narrowness of scope decrees the loops should be something like for (var i = 0, len = results.length
. Though also the fact we have two loops that use the same vars suggests the function is a bit too big.
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.
Agreed!
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.
So, actually, it's an issue because when when you create a var
inside a loop, its scope is still the whole function. So no, we need to keep this change unfortunately.
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 dang, I was wondering if I was misremembering JS's scoping rules. That sounds right. How about using a different variable name to indicate that the lower for
loop doesn't depend on output from the upper for
loop?
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.
They're actually both at the same level. result
is just used in a loop later on. I really miss "normal" scopes when doing JS...
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, by "lower" and "upper" I meant lower in the file and higher in the file, not in different scopes. But this is not too important.
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'll keep things as is then.
@@ -84,7 +84,7 @@ function onEachLazy(lazyArray, func, reversed) { | |||
} | |||
|
|||
// eslint-disable-next-line no-unused-vars | |||
function hasOwnProperty(obj, property) { | |||
function hasOwnPropertyRustdoc(obj, property) { |
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.
What was the lint finding that prompted the rename?
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.
It was complaining about the fact that hasOwnProperty
shouldn't be overloaded.
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 is a polyfill, right? Is it still needed? It looks like it has very wide support: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty.
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.
True, since we don't support IE anymore, should be fine to get rid of it now.
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.
Like said below, eslint complains about it...
c910aaa
to
4950580
Compare
When I removed the
|
c5c2a85
to
4950580
Compare
Ah, got it. It looks like
But that's pretty awkward! I'm guessing that's why we have a function that wraps it. That part looks good to me now. |
👍 |
4950580
to
dcf85c3
Compare
@bors r+ |
📌 Commit dcf85c3233b9e28718d7ee243df26306b3dd2c9f has been approved by |
@bors r- Please land the eslint fixes separately from enforcing them in CI, I'd like @Mark-Simulacrum (or I guess me, but it will take a while) to take a look first. The current setup is very unusual. |
…=jsha Fix eslint errors I cherry-picked the two non-CI commits from rust-lang#85285. r? `@jsha`
Done in #85323. Let's wait for it to get merged and then I'll remove the non-CI catch. |
…=jsha Fix eslint errors I cherry-picked the two non-CI commits from rust-lang#85285. r? ``@jsha``
…=jsha Fix eslint errors I cherry-picked the two non-CI commits from rust-lang#85285. r? ```@jsha```
dcf85c3
to
c9b4c5a
Compare
Rebased, now let's wait for @Mark-Simulacrum. :) |
@bors r=jsha,Mark-Simulacrum I agree that the checks here aren't really standard, and that we may want to explore alternatives (including x.py integration, such as we did with the rustdoc-gui tests). Given that these are stylistic checks though I'm OK leaving them here for now, especially given that this is just adding an extra layer atop the existing es5 check. |
📌 Commit c9b4c5afeba6a64b19f2ae3e3d9f943ebd869149 has been approved by |
⌛ Testing commit c9b4c5afeba6a64b19f2ae3e3d9f943ebd869149 with merge b143d0aa0b95e7bbc8f48e1c3749cd90c24ea3a4... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
c9b4c5a
to
558b073
Compare
Fixed missing eslint for newly added JS file and rebased (not in that order). @bors: r=jsha,Mark-Simulacrum |
📌 Commit 558b073 has been approved by |
…laumeGomez Rollup of 8 pull requests Successful merges: - rust-lang#85285 (Add eslint checks to CI) - rust-lang#85709 (Use correct edition when parsing `:pat` matchers) - rust-lang#85762 (Do not try to build LLVM with Zlib on Windows) - rust-lang#85770 (Remove `--print unversioned-files` from rustdoc ) - rust-lang#85781 (Add documentation for aarch64-apple-ios-sim target) - rust-lang#85801 (Add `String::extend_from_within`) - rust-lang#85817 (Fix a typo) - rust-lang#85818 (Don't drop `PResult` without handling the error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
It also allowed me to fix some potential issues that went unnoticed. Having this process automated will hopefully prevent us to add more errors. :)
cc @Mark-Simulacrum (for the add in the CI).
r? @jsha