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

fix(eslint-plugin): fix schemas across several rules and add schema tests #6947

Merged
merged 11 commits into from Jul 10, 2023

Conversation

domdomegg
Copy link
Contributor

PR Checklist

Overview

Rebase of #6894 on top of v6, as per #6894 (comment)

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @domdomegg!

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 Apr 22, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 218f866
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64ac791cbdc0840007912d71
😎 Deploy Preview https://deploy-preview-6947--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 configuration.

@nx-cloud
Copy link

nx-cloud bot commented Apr 22, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 218f866. 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 31 targets

Sent with 💌 from NxCloud.

@codecov
Copy link

codecov bot commented Apr 22, 2023

Codecov Report

Merging #6947 (218f866) into main (6ae1fa7) will decrease coverage by 0.01%.
The diff coverage is 92.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6947      +/-   ##
==========================================
- Coverage   87.55%   87.54%   -0.01%     
==========================================
  Files         375      377       +2     
  Lines       13167    13181      +14     
  Branches     3899     3899              
==========================================
+ Hits        11528    11539      +11     
- Misses       1259     1262       +3     
  Partials      380      380              
Flag Coverage Δ
unittest 87.54% <92.85%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...es/eslint-plugin/src/rules/parameter-properties.ts 94.11% <ø> (ø)
packages/utils/src/ts-utils/isArray.ts 0.00% <ø> (ø)
...s/eslint-plugin/src/rules/no-restricted-imports.ts 95.38% <92.30%> (-0.92%) ⬇️
packages/utils/src/ts-utils/index.ts 100.00% <100.00%> (ø)

@bradzacher bradzacher added this to the 6.0.0 milestone Apr 27, 2023
@bradzacher bradzacher added the bug Something isn't working label Apr 27, 2023
}
};

const baseSchema = baseRule.meta.schema as {
Copy link
Member

Choose a reason for hiding this comment

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

question: why did you switch back to basing off of the base rule's schema here?
Any reason or was it just to go back to de-duping things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No strong reason: just to dedupe things / keep things in sync.

packages/eslint-plugin/tests/areOptionsValid.ts Outdated Show resolved Hide resolved
Comment on lines +2161 to +2175
describe('schema validation', () => {
// https://github.com/typescript-eslint/typescript-eslint/issues/6852
test("array-type does not accept 'simple-array' option", () => {
if (areOptionsValid(rule, [{ default: 'simple-array' }])) {
throw new Error(`Options succeeded validation for bad options`);
}
});

// https://github.com/typescript-eslint/typescript-eslint/issues/6892
test('array-type does not accept non object option', () => {
if (areOptionsValid(rule, ['array'])) {
throw new Error(`Options succeeded validation for bad options`);
}
});
});
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should do a rule-tester style API here to remove the boilerplate.
For example something like this:

ruleOptionsTester(rule, {
  valid: [ ... ],
  invalid: [
    [{ default: 'simple-array' }],
    ['array'],
  ],
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think something like this would be neat if we end up doing a lot of these kinds of tests. For now I think it's simple enough that we can leave this to be done in future if necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Note that there is
eslint/rfcs#103 and the implementing PR eslint/eslint#16823

This would allow us to include these tests in the rule like:

tester.run('rule', rule, {
  valid: [ ... ],
  invalid: [ ... ],
  fatal: [
    {
      options: ['simple-array'],
      error: {
        name: 'SchemaValidationError',
        message: 'Whatever the json schema error is',
      },
    },
    {
      options: ['array'],
      error: {
        name: 'SchemaValidationError',
        message: 'Whatever the json schema error is',
      },
    },
  ],
}

so definitely we don't need to bother with building a bespoke test framework!

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg removed this from the 6.0.0 milestone May 25, 2023
@JoshuaKGoldberg
Copy link
Member

Removing from the v6 milestone as it doesn't actually block releasing v6 (I believe). Someone yell at me if that's wrong. 🙂

@JoshuaKGoldberg
Copy link
Member

Oh also, @domdomegg just checking in - are you waiting on us for anything? I believe our last status was waiting on you to re-request review to take another look.

@domdomegg domdomegg requested a review from bradzacher May 31, 2023 02:41
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Jun 24, 2023
bradzacher
bradzacher previously approved these changes Jun 24, 2023
@bradzacher
Copy link
Member

@domdomegg if you want to update this against v6 and resolve the conflicts, and get the CI passing - then we're good to merge this in!

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready labels Jun 24, 2023
@domdomegg
Copy link
Contributor Author

I think we're ready @bradzacher / @JoshuaKGoldberg :)

@JoshuaKGoldberg JoshuaKGoldberg deleted the branch typescript-eslint:main July 10, 2023 17:52
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jul 10, 2023

This was unintentionally auto-closed when we merged the v6 branch 🙃 it'll be recreated reopened.

@JoshuaKGoldberg JoshuaKGoldberg merged commit dd31bed into typescript-eslint:main Jul 10, 2023
44 of 45 checks passed
@domdomegg
Copy link
Contributor Author

Thanks @JoshuaKGoldberg 🙌

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [array-type] the config simple-array should be disallowed by the schema
3 participants