Skip to content

chore(rule-tester): rethrow exceptions in RuleTester to avoid circular JSON issue #10134

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

Merged

Conversation

kirkwaiblinger
Copy link
Member

PR Checklist

Overview

I don't really get the circular JSON problem but looks like we can suppress it by just rethrowing the exception 🤷‍♂️

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Oct 11, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 416d69b
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/670db8409ac6690008dfb277
😎 Deploy Preview https://deploy-preview-10134--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 8 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Oct 11, 2024

@kirkwaiblinger kirkwaiblinger changed the title chore(rule-tester): Rethrow exceptions in RuleTester to avoid circular JSON issue chore(rule-tester): rethrow exceptions in RuleTester to avoid circular JSON issue Oct 11, 2024
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.18%. Comparing base (ef5df2f) to head (416d69b).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
packages/rule-tester/src/RuleTester.ts 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10134      +/-   ##
==========================================
+ Coverage   86.09%   86.18%   +0.08%     
==========================================
  Files         428      428              
  Lines       14969    14988      +19     
  Branches     4343     4344       +1     
==========================================
+ Hits        12888    12917      +29     
+ Misses       1734     1725       -9     
+ Partials      347      346       -1     
Flag Coverage Δ
unittest 86.18% <88.88%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/rule-tester/src/RuleTester.ts 63.77% <88.88%> (+2.11%) ⬆️

... and 5 files with indirect coverage changes

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Sigh. I really hate going with bandaids like this... but given how slow Jest maintenance is, I don't see a way around it. Blagh.

OTOH, nice fix! 👏

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Oct 14, 2024
@kirkwaiblinger
Copy link
Member Author

Sigh. I really hate going with bandaids like this...

Yeah, it really is yucky IMO 🙁 but what can you do 🤷

// see also https://github.com/typescript-eslint/typescript-eslint/issues/8942
//
// For some reason rethrowing exceptions skirts around the circular JSON error.
this.#linter = new Proxy(
Copy link
Member

Choose a reason for hiding this comment

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

Can't we just wrap the verify call directly?

// Verify if suggestion fix makes a syntax error or not.
const errorMessageInSuggestion = this.#linter
.verify(
codeWithAppliedSuggestion,
omitCustomConfigProperties(result.config),
result.filename,
)
.find(m => m.fatal);

Or failing that - directly override verify, eg

const linter = new Linter(...);
const oldVerify = linter.verify;
linter.verify = (...args) => { ... oldVerify(...args) ... };

Copy link
Member Author

@kirkwaiblinger kirkwaiblinger Oct 15, 2024

Choose a reason for hiding this comment

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

Can't we just wrap the verify call directly?

There are three this.#linter.verify calls so I at least wanted to put them all in one codepath.

Or failing that - directly override verify, eg

const linter = new Linter(...);
const oldVerify = linter.verify;
linter.verify = (...args) => { ... oldVerify(...args) ... };

Yeah, that works too. I just wasn't sure if Linter was some arcane class object that depended on crazy this-context and/or getter binding stuff to work correctly (like, for example, the context parameter within the rules) or if we were safe to do that. Can switch it to that if it seems safe.

Copy link
Member

Choose a reason for hiding this comment

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

oh yeah now that Brad mentions it, +1 to that more direct strategy

@github-actions github-actions bot removed the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Oct 15, 2024
@bradzacher bradzacher merged commit 38ad9e2 into typescript-eslint:main Oct 15, 2024
62 of 63 checks passed
@kirkwaiblinger kirkwaiblinger deleted the rule-tester-exceptions branch October 15, 2024 01:53
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Repo: handle exceptions that occur while testing a rule better
3 participants