Skip to content

chore(eslint-plugin-internal): [plugin-test-formatting] support random object literal tests #5895

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
merged 4 commits into from
Nov 2, 2022

Conversation

bradzacher
Copy link
Member

Overview

I was looking at some of our tests and noticed they weren't formatted correctly.
Investigating it was because they were declared as variables instead of as part of a test run.

This PR just adds support to the rule for random object literals by doing some fuzzy checks using types.

@bradzacher bradzacher added the repo maintenance things to do with maintenance of the repo, and not with code/docs label Oct 27, 2022
@nx-cloud
Copy link

nx-cloud bot commented Oct 27, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit ffff806. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 46 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

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.

@netlify
Copy link

netlify bot commented Oct 27, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit ffff806
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6361f87aea4ead0009b97836
😎 Deploy Preview https://deploy-preview-5895--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Merging #5895 (ffff806) into main (2089e5a) will decrease coverage by 0.02%.
The diff coverage is 85.36%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5895      +/-   ##
==========================================
- Coverage   91.32%   91.29%   -0.03%     
==========================================
  Files         365      365              
  Lines       12212    12251      +39     
  Branches     3564     3577      +13     
==========================================
+ Hits        11152    11185      +33     
- Misses        752      758       +6     
  Partials      308      308              
Flag Coverage Δ
unittest 91.29% <85.36%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
...lugin-internal/src/rules/plugin-test-formatting.ts 80.92% <85.36%> (+1.07%) ⬆️

@bradzacher bradzacher force-pushed the check-variables-formatting-plugin-test branch from 74828bc to 9d928ca Compare October 27, 2022 07:10
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.

Super, thanks! ✨

import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

const grouped: TSESLint.RunTests<MessageIds, Options> = {
const grouped: RunTests<MessageIds, Options> = {
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we just pass this directly to ruleTester.run? There's only one variable here.

import { RuleTester } from '../../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

const sortedCiWithoutGrouping: TSESLint.RunTests<MessageIds, Options> = {
const sortedCiWithoutGrouping: RunTests<MessageIds, Options> = {
Copy link
Member

Choose a reason for hiding this comment

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

Similar suggestion: I like the idea behind describing the variables, but it just seems like extra cruft to me. How about passing them directly to ruleTester.run?

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'm personally not too miffed either way.

I think the separate variables is nice as a way to document and group the tests.
it's much clearer than the alternative:

ruleTester.run('member-ordering', rule, {
  valid: [
    //
    // Sorted case insensitive without grouping
    //
    'test1',
    // ...

    //
    // Sorted case insensitive with grouping
    //
    'testn+1',
    // ...
  ],
});

I find it really easy to lose the comments in the array when it gets really big.

But the indirection is a bit of a pain overall.

I think either way has trade-offs, so IDK which one we want as the standard in the repo.

Copy link
Member

Choose a reason for hiding this comment

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

My mild preference would be for less code, but it's not a hill I'm going to die on 😄

testProp.computed ||
testProp.key.type !== AST_NODE_TYPES.Identifier ||
testProp.key.name !== 'errors' ||
testProp.value.type !== AST_NODE_TYPES.ArrayExpression
Copy link
Member

Choose a reason for hiding this comment

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

Nit: this is almost the same as the previous .type === AST_NODE_TYPES.SpreadElement || ... check, but for the 'errors' case. I wonder if there's a good way to dedup? 🤷 definitely not a blocker IMO.

@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 27, 2022
@bradzacher bradzacher merged commit f11183c into main Nov 2, 2022
@bradzacher bradzacher deleted the check-variables-formatting-plugin-test branch November 2, 2022 05:12
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants