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

Hand-roll faster and safer version of import/no-restricted-paths #7593

Merged
merged 8 commits into from
Feb 9, 2024

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Feb 9, 2024

What does this PR do?

👆 😅 it was so slow that I opened two issues for the same thing over the years.

Before (2m 20s)

Rule                                            | Time (ms) | Relative
:-----------------------------------------------|----------:|--------:
import/no-restricted-paths                      | 50222.336 |    49.1%
@typescript-eslint/no-unsafe-assignment         |  8793.188 |     8.6%
unicorn/no-unnecessary-polyfills                |  4247.493 |     4.1%
@typescript-eslint/no-floating-promises         |  3331.880 |     3.3%
@typescript-eslint/no-confusing-void-expression |  2293.998 |     2.2%
@typescript-eslint/no-unsafe-argument           |  1524.524 |     1.5%
import/no-self-import                           |  1359.165 |     1.3%
@typescript-eslint/no-redeclare                 |  1191.053 |     1.2%
react/no-direct-mutation-state                  |   915.010 |     0.9%
unicorn/expiring-todo-comments                  |   900.622 |     0.9%

After (1m 30s)

Rule                                            | Time (ms) | Relative
:-----------------------------------------------|----------:|--------:
@typescript-eslint/no-unsafe-assignment         |  9179.275 |    17.2%
import/no-self-import                           |  4934.737 |     9.2%
unicorn/no-unnecessary-polyfills                |  4443.853 |     8.3%
@typescript-eslint/no-floating-promises         |  3233.091 |     6.1%
@typescript-eslint/no-confusing-void-expression |  2376.571 |     4.5%
@typescript-eslint/no-unsafe-argument           |  1567.075 |     2.9%
@typescript-eslint/no-redeclare                 |  1303.585 |     2.4%
react/no-direct-mutation-state                  |   941.887 |     1.8%
unicorn/prevent-abbreviations                   |   934.537 |     1.8%
unicorn/expiring-todo-comments                  |   920.177 |     1.7%

Checklist

Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (30993bf) 72.72% compared to head (6409061) 72.72%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7593   +/-   ##
=======================================
  Coverage   72.72%   72.72%           
=======================================
  Files        1220     1220           
  Lines       38126    38126           
  Branches     7170     7170           
=======================================
  Hits        27727    27727           
  Misses      10399    10399           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

"sidebar",
"pageScript",
],
allowedGlobs: ["**/messenger/**", "**/*.scss*"],
Copy link
Contributor Author

@fregante fregante Feb 9, 2024

Choose a reason for hiding this comment

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

⚡️ Improvement: Glob support

message: `Cross-context imports break expectations. Shared components should be in shared folders.
Solution 1: Keep both importing and imported modules in the same context (shared or @/${exporter}).
Solution 2: Use the Messenger if they are in the correct context.
Solution 3: Propose a clearly-shared component within the context, like we do for Messenger and *Types files.`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

`../${exporter}/pageEditorTypes.ts`,
`../${exporter}/runBlockTypes.ts`,
`../${exporter}/extensionPoints/formStateTypes.ts`,
`../${exporter}/tabs/editTab/dataPanel/dataPanelTypes.ts`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

⚡️ Improvement: type imports are automatically detected and allowed.

// All of these files cannot import `from` (exclude self-imports)
target:
exporter === "contentScript"
? `./src/!(${exporter}|bricks|starterBricks)/**/*` // Temporary: Bricks and starterBricks are implicitly run from CS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👋 Change: this gave free rein to bricks. If "bricks are implicitly run from CS", they should be under @/contentScript so that we can enforce this rule on all imports.

@@ -29,7 +29,6 @@ import { recreateDB as recreateBrickDB } from "@/registry/packageRegistry";
import {
recreateDB as recreateEventDB,
clear as clearEvents,
// eslint-disable-next-line import/no-restricted-paths -- safe import because IDB is shared resource
} from "@/background/telemetry";
Copy link
Contributor Author

@fregante fregante Feb 9, 2024

Choose a reason for hiding this comment

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

⚠️ If it's shared, it shouldn't be in @/background, that's why we have this lint rule

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. But why is it not getting flagged by the new rule? We should be moving this, shouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, but the rule is set to be a warning. This inline exclusion was not "mandatory" so the linter continues without it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wanted to be sure that there wasn't something broken here before I approved. I overlooked that it was set to "warn"

Copy link

github-actions bot commented Feb 9, 2024

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@fregante fregante merged commit f0f254f into main Feb 9, 2024
26 checks passed
@fregante fregante deleted the F/lint/restricted-paths branch February 9, 2024 19:00
@ljharb
Copy link

ljharb commented Feb 10, 2024

@fregante fwiw if this actually is a faster 1:1 replacement for the import rule, i'd love an upstream PR :-)

@fregante
Copy link
Contributor Author

Unfortunately this rule takes a lot of shortcuts and just compares the top-level folder. It also changes how the comparison is done (one rule per folder vs "list of folders that can't import from each other")

@grahamlangford grahamlangford added this to the 1.8.9 milestone Feb 16, 2024
fregante pushed a commit that referenced this pull request Feb 20, 2024
…he rendered document (#7507)

* add stylesheets to the document view

* add a document test

* default input for document view component

---------

Co-authored-by: Ben Loe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants