Skip to content
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

Merged
merged 2 commits into from
May 30, 2021
Merged

Add eslint checks to CI #85285

merged 2 commits into from
May 30, 2021

Conversation

GuillaumeGomez
Copy link
Member

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

@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label May 14, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jyn514 jyn514 left a 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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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...

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@jsha jsha left a 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/main.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/main.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/search.js Outdated Show resolved Hide resolved
@@ -254,7 +257,7 @@ window.initSearch = function(rawSearchIndex) {
});

for (i = 0, len = results.length; i < len; ++i) {
var result = results[i];
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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...

Copy link
Contributor

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.

Copy link
Member Author

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.

src/librustdoc/html/static/search.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/source-script.js Outdated Show resolved Hide resolved
src/librustdoc/html/static/storage.js Outdated Show resolved Hide resolved
@@ -84,7 +84,7 @@ function onEachLazy(lazyArray, func, reversed) {
}

// eslint-disable-next-line no-unused-vars
function hasOwnProperty(obj, property) {
function hasOwnPropertyRustdoc(obj, property) {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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...

@GuillaumeGomez
Copy link
Member Author

When I removed the hasOwnPropertyRustdoc, eslint is complaining about it:

/home/imperio/rust/rust/src/librustdoc/html/static/search.js
   176:29  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  1248:67  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  1299:33  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  1389:34  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins
  1393:41  error  Do not access Object.prototype method 'hasOwnProperty' from target object  no-prototype-builtins

@jsha
Copy link
Contributor

jsha commented May 14, 2021

Ah, got it. It looks like hasOwnProperty (or hasOwnPropertyRustdoc) is not actually a polyfill but a shortcut. According to https://eslint.org/docs/rules/no-prototype-builtins you should call hasOwnProperty like so:

Object.prototype.hasOwnProperty.call(foo, "bar");

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.

@GuillaumeGomez
Copy link
Member Author

👍

@jsha
Copy link
Contributor

jsha commented May 14, 2021

@bors r+

@bors
Copy link
Contributor

bors commented May 14, 2021

📌 Commit dcf85c3233b9e28718d7ee243df26306b3dd2c9f has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2021
@jyn514
Copy link
Member

jyn514 commented May 14, 2021

@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.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 14, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…=jsha

Fix eslint errors

I cherry-picked the two non-CI commits from rust-lang#85285.

r? `@jsha`
@GuillaumeGomez
Copy link
Member Author

Done in #85323. Let's wait for it to get merged and then I'll remove the non-CI catch.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…=jsha

Fix eslint errors

I cherry-picked the two non-CI commits from rust-lang#85285.

r? ``@jsha``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…=jsha

Fix eslint errors

I cherry-picked the two non-CI commits from rust-lang#85285.

r? ```@jsha```
@GuillaumeGomez GuillaumeGomez added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 15, 2021
@GuillaumeGomez
Copy link
Member Author

Rebased, now let's wait for @Mark-Simulacrum. :)

@GuillaumeGomez
Copy link
Member Author

r? @Mark-Simulacrum

@jyn514 jyn514 added the A-testsuite Area: The testsuite used to check the correctness of rustc label May 29, 2021
@Mark-Simulacrum
Copy link
Member

@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.

@bors
Copy link
Contributor

bors commented May 29, 2021

📌 Commit c9b4c5afeba6a64b19f2ae3e3d9f943ebd869149 has been approved by jsha,Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2021
@bors
Copy link
Contributor

bors commented May 30, 2021

⌛ Testing commit c9b4c5afeba6a64b19f2ae3e3d9f943ebd869149 with merge b143d0aa0b95e7bbc8f48e1c3749cd90c24ea3a4...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented May 30, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 30, 2021
@GuillaumeGomez
Copy link
Member Author

Fixed missing eslint for newly added JS file and rebased (not in that order).

@bors: r=jsha,Mark-Simulacrum

@bors
Copy link
Contributor

bors commented May 30, 2021

📌 Commit 558b073 has been approved by jsha,Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2021
…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
@bors bors merged commit 9c873c1 into rust-lang:master May 30, 2021
@bors
Copy link
Contributor

bors commented May 30, 2021

⌛ Testing commit 558b073 with merge c1e8f3a...

@rustbot rustbot added this to the 1.54.0 milestone May 30, 2021
@GuillaumeGomez GuillaumeGomez deleted the eslint-check branch May 31, 2021 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants