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

H-3134: Apply ESLint autofixes #4745

Draft
wants to merge 12 commits into
base: bm/repo/eslint
Choose a base branch
from
Draft

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Jul 19, 2024

🌟 What is the purpose of this PR?

This PR adds a new ESLint configuration, which is more encompassing and stricter than the previous one.

This is the second PR, building on top of #4232, and applies all auto fixes. The next PRs will focus on different subpackages to remove the remaining errors.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • affected the execution graph, and the turbo.json's have been updated to reflect this

@github-actions github-actions bot added area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) area/blocks Relates to first-party blocks (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team area/tests New or updated tests area/tests > integration New or updated integration tests area/tests > playwright New or updated Playwright tests area/apps > hash-realtime area/apps > hash-search-loader area/apps labels Jul 19, 2024
@indietyp indietyp changed the title eslint-fix auto apply ES-Lint fixes Jul 19, 2024
@indietyp indietyp changed the base branch from main to bm/repo/eslint July 19, 2024 21:32
Comment on lines 63 to 67
try {
({ operationName } = JSON.parse(options.body));
} catch (err) {
// eslint-disable-next-line no-console -- TODO: consider using logger
console.error(err);
} catch (error) {
console.error(error);
}
Copy link

Choose a reason for hiding this comment

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

Error messages with stack traces may expose sensitive information about the application.

Ignore this finding from generic_error_disclosure.

Copy link
Member

Choose a reason for hiding this comment

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

Where removing comments, there will be cases when we want to ensure that manually added notes/todos (e.g. consideration for using a logger) are persisted.

// eslint-disable-next-line no-console -- TODO: consider using logger
console.error(err);
} catch (error) {
console.error(error);
}
Copy link

Choose a reason for hiding this comment

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

Error messages with stack traces may expose sensitive information about the application.

Ignore this finding from generic_error_disclosure.

@@ -71,7 +77,6 @@ export const generateEntityLabel = (

entityType = entityTypeAndAncestors[0];
} catch (error) {
// eslint-disable-next-line no-console -- prefer not to crash here but still have some feedback that there's an issue
console.error(
`Error looking for entity type and ancestors in provided subgraph: ${
(error as Error).message
Copy link

Choose a reason for hiding this comment

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

Error messages with stack traces may expose sensitive information about the application.

Ignore this finding from generic_error_disclosure.

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) type/eng > frontend Owned by the @frontend team labels Jul 20, 2024

return () => window.removeEventListener("message", msgHandler);
window.addEventListener("message", messageHandler);
Copy link

Choose a reason for hiding this comment

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

No validation of origin is done by the addEventListener API. It may be possible to exploit this flaw to perform Cross Origin attacks such as Cross-Site Scripting(XSS).

Ignore this finding from insufficient-postmessage-origin-validation.

}
}
request.send(conf.body ?? null);
request.send(config.body ?? null);
}),
{
abort() {
Copy link

Choose a reason for hiding this comment

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

Depending on the context, user control data in Object.assign can cause web response to include data that it should not have or can lead to a mass assignment vulnerability.

View Dataflow Graph
flowchart LR
    classDef invis fill:white, stroke: none
    classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none

    subgraph File0["<b>apps/hash-frontend/src/pages/shared/block-collection/collab/http.ts</b>"]
        direction LR
        %% Source

        subgraph Source
            direction LR

            v0["<a href=https://github.com/hashintel/hash/blob/56b6061ed2cd662197c1442071258c0501aa60bf/apps/hash-frontend/src/pages/shared/block-collection/collab/http.ts#L72 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 72] config.headers</a>"]
        end
        %% Intermediate

        %% Sink

        subgraph Sink
            direction LR

            v1["<a href=https://github.com/hashintel/hash/blob/56b6061ed2cd662197c1442071258c0501aa60bf/apps/hash-frontend/src/pages/shared/block-collection/collab/http.ts#L37 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 37] Object.assign(<br>    new Promise&lt;string&gt;((resolve, reject) =&gt; {<br>      request.open(config.method, config.url, true);<br>      request.withCredentials = true;<br>      request.addEventListener(&quot;load&quot;, () =&gt; {<br>        if (aborted) {<br>          return;<br>        }<br>        if (request.status &lt; 400) {<br>          finished = true;<br>          resolve(request.responseText);<br>        } else {<br>          let text = request.responseText;<br><br>          if (<br>            text &&<br>            (request.getResponseHeader(&quot;content-type&quot;) ?? &quot;&quot;).includes(&quot;html&quot;)<br>          ) {<br>            text = makePlain(text);<br>          }<br>          const error = new StatusError(<br>            request.status,<br>            `Request failed: ${request.statusText}${text ? `\n\n${text}` : &quot;&quot;}`,<br>          );<br><br>          finished = true;<br>          reject(error);<br>        }<br>      });<br>      request.addEventListener(&quot;error&quot;, () =&gt; {<br>        if (!aborted) {<br>          finished = true;<br>          reject(new Error(&quot;Network error&quot;));<br>        }<br>      });<br>      if (config.headers) {<br>        for (const header of Object.keys(config.headers)) {<br>          request.setRequestHeader(header, config.headers[header]!);<br>        }<br>      }<br>      request.send(config.body ?? null);<br>    }),<br>    {<br>      abort() {<br>        if (!aborted && !finished) {<br>          request.abort();<br>          onAbort?.();<br>          aborted = true;<br>        }<br>      },<br>    },<br>  )</a>"]
        end
    end
    %% Class Assignment
    Source:::invis
    Sink:::invis

    File0:::invis

    %% Connections

    Source --> Sink

Loading
Ignore this finding from express-data-exfiltration.

Copy link
Contributor

Benchmark results

@rust/graph-benches – Integrations

representative_read_multiple_entities

Function Value Mean Flame graphs
link_by_source_by_property depths: DT=255, PT=255, ET=255, E=255 $$1.99 \mathrm{s} \pm 5.40 \mathrm{ms}\left({\color{gray}-0.038 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=2, ET=2, E=2 $$1.03 \mathrm{s} \pm 6.25 \mathrm{ms}\left({\color{gray}-0.658 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=2, PT=2, ET=2, E=2 $$1.03 \mathrm{s} \pm 2.66 \mathrm{ms}\left({\color{gray}-0.944 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=0 $$39.0 \mathrm{ms} \pm 269 \mathrm{μs}\left({\color{gray}-2.577 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=2, E=2 $$405 \mathrm{ms} \pm 1.58 \mathrm{ms}\left({\color{gray}0.318 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=2 $$75.0 \mathrm{ms} \pm 383 \mathrm{μs}\left({\color{gray}-3.830 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=255, PT=255, ET=255, E=255 $$2.89 \mathrm{s} \pm 10.1 \mathrm{ms}\left({\color{gray}-0.006 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=2, ET=2, E=2 $$981 \mathrm{ms} \pm 3.11 \mathrm{ms}\left({\color{gray}-3.833 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=2, PT=2, ET=2, E=2 $$994 \mathrm{ms} \pm 3.97 \mathrm{ms}\left({\color{gray}-1.203 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=0 $$37.4 \mathrm{ms} \pm 274 \mathrm{μs}\left({\color{gray}-0.070 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=2, E=2 $$362 \mathrm{ms} \pm 1.61 \mathrm{ms}\left({\color{gray}-3.186 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=2 $$41.2 \mathrm{ms} \pm 226 \mathrm{μs}\left({\color{gray}-1.570 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_linkless

Function Value Mean Flame graphs
entity_by_id 100 entities $$2.03 \mathrm{ms} \pm 10.2 \mathrm{μs}\left({\color{gray}0.119 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$1.84 \mathrm{ms} \pm 7.10 \mathrm{μs}\left({\color{gray}0.170 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.84 \mathrm{ms} \pm 8.47 \mathrm{μs}\left({\color{gray}-0.029 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$2.76 \mathrm{ms} \pm 10.3 \mathrm{μs}\left({\color{gray}-2.383 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10000 entities $$13.3 \mathrm{ms} \pm 160 \mathrm{μs}\left({\color{gray}-0.387 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: d4e16033-c281-4cde-aa35-9085bf2e7579 $$1.41 \mathrm{ms} \pm 6.03 \mathrm{μs}\left({\color{gray}0.400 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_one_depth

Function Value Mean Flame graphs
entity_by_id 25 entities $$76.0 \mathrm{ms} \pm 353 \mathrm{μs}\left({\color{gray}-1.039 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$24.5 \mathrm{ms} \pm 222 \mathrm{μs}\left({\color{gray}1.55 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$273 \mathrm{ms} \pm 1.53 \mathrm{ms}\left({\color{gray}0.048 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$50.0 \mathrm{ms} \pm 1.19 \mathrm{ms}\left({\color{red}20.3 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$19.8 \mathrm{ms} \pm 93.0 \mathrm{μs}\left({\color{gray}-0.936 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_zero_depth

Function Value Mean Flame graphs
entity_by_id 25 entities $$3.13 \mathrm{ms} \pm 11.0 \mathrm{μs}\left({\color{red}22.5 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$1.89 \mathrm{ms} \pm 11.1 \mathrm{μs}\left({\color{gray}-0.555 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$4.20 \mathrm{ms} \pm 34.0 \mathrm{μs}\left({\color{red}6.90 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$2.08 \mathrm{ms} \pm 19.3 \mathrm{μs}\left({\color{gray}1.16 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.86 \mathrm{ms} \pm 7.58 \mathrm{μs}\left({\color{gray}-0.014 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$16.8 \mathrm{ms} \pm 188 \mathrm{μs}\left({\color{lightgreen}-7.460 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$16.8 \mathrm{ms} \pm 197 \mathrm{μs}\left({\color{gray}3.72 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$17.2 \mathrm{ms} \pm 239 \mathrm{μs}\left({\color{gray}1.48 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$16.9 \mathrm{ms} \pm 228 \mathrm{μs}\left({\color{gray}-3.447 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$16.8 \mathrm{ms} \pm 257 \mathrm{μs}\left({\color{lightgreen}-33.218 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$16.9 \mathrm{ms} \pm 235 \mathrm{μs}\left({\color{gray}0.498 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$17.2 \mathrm{ms} \pm 228 \mathrm{μs}\left({\color{gray}3.93 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$16.7 \mathrm{ms} \pm 242 \mathrm{μs}\left({\color{lightgreen}-6.717 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$17.1 \mathrm{ms} \pm 262 \mathrm{μs}\left({\color{gray}2.09 \mathrm{\%}}\right) $$ Flame Graph

@vilkinsons vilkinsons changed the title auto apply ES-Lint fixes H-3134: Apply ESLint autofixes Jul 21, 2024
@vilkinsons vilkinsons assigned vilkinsons and indietyp and unassigned vilkinsons Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) area/apps > hash-realtime area/apps > hash-search-loader area/apps area/blocks Relates to first-party blocks (area) area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests > integration New or updated integration tests area/tests > playwright New or updated Playwright tests area/tests New or updated tests type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team
Development

Successfully merging this pull request may close these issues.

2 participants