Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): [no-duplicate-enum-values] add rule#4833

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

aifreedom
Copy link
Contributor

PR Checklist

Overview

This PR creates a new rule ineslint-plugin to disallow duplicate enum values. Per discussion in the issue (#2693), in this version, it only checks enum members initialized with literals, and does not cover the ones without an initializer or initialized with an expression.

@nx-cloud
Copy link

nx-cloudbot commentedApr 17, 2022
edited
Loading

☁️ Nx Cloud Report

CI is running/has finished running commands for commit42515fd. 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 43 targets

Sent with 💌 fromNxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@aifreedom!

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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@netlify
Copy link

netlifybot commentedApr 17, 2022
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit42515fd
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/62688bbc120c8e0009f39bff
😎 Deploy Previewhttps://deploy-preview-4833--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 yourNetlify site settings.

@aifreedomaifreedom changed the titlefeat(eslint-plugin): create a new rule to disallow duplicate enum valuesfeat(eslint-plugin): new rule to disallow duplicate enum valuesApr 17, 2022
@codecov
Copy link

codecovbot commentedApr 17, 2022
edited
Loading

Codecov Report

Merging#4833 (5484161) intomain (f3cf87b) willincrease coverage by2.48%.
The diff coverage is100.00%.

❗ Current head5484161 differs from pull request most recent head42515fd. Consider uploading reports for the commit42515fd to get more accurate results

@@            Coverage Diff             @@##             main    #4833      +/-   ##==========================================+ Coverage   91.77%   94.25%   +2.48%==========================================  Files         227      153      -74       Lines       10611     8305    -2306       Branches     3283     2703     -580     ==========================================- Hits         9738     7828    -1910+ Misses        591      263     -328+ Partials      282      214      -68
FlagCoverage Δ
unittest94.25% <100.00%> (+2.48%)⬆️

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

Impacted FilesCoverage Δ
packages/eslint-plugin/src/configs/all.ts100.00% <ø> (ø)
...slint-plugin/src/rules/no-duplicate-enum-values.ts100.00% <100.00%> (ø)
...ges/type-utils/src/getConstrainedTypeAtLocation.ts
...ils/src/ast-utils/eslint-utils/ReferenceTracker.ts
...s/utils/src/eslint-utils/batchedSingleLineTests.ts
packages/utils/src/ts-eslint-scope/Referencer.ts
packages/eslint-plugin-tslint/src/custom-linter.ts
packages/type-utils/src/isUnsafeAssignment.ts
...pt-estree/src/create-program/createWatchProgram.ts
packages/utils/src/ast-utils/index.ts
... and67 more

@bradzacherbradzacher changed the titlefeat(eslint-plugin): new rule to disallow duplicate enum valuesfeat(eslint-plugin): [no-duplicate-enum-values] add ruleApr 18, 2022
@bradzacherbradzacher added the enhancement: new plugin ruleNew rule request for eslint-plugin labelApr 18, 2022
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

The new rule and tests generally looks great, very nicely done@aifreedom!

Requesting changes for added test coverage. I can't view the Codecov coverage report at the moment to see why the file only has 80% 🙃 -- will take another look when more tests are added.

return (
node.type === AST_NODE_TYPES.Literal && typeof node.value === 'number'
);
}

Choose a reason for hiding this comment

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

[Nitpicking] Is there a need to separate these two functions out? They both check thatnode.type === AST_NODE_TYPES.Literal.

I'd suggest either making a single separate function:

functiongetExpressionLiteralValue(node:TSESTree.Expression){if(node.type===AST_NODE_TYPES.Literal){switch(typeofnode.value){// ...}}}...orinliningthembelow:```tsletvalue: string|number|undefined;if(node.type===AST_NODE_TYPES.Literal){// ...}

Just suggestions, feel free to ignore if you don't like either of these changes 😄

aifreedom reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I had to do this because typescript doesn't know the type ofmember.initializer without the util functions, and would complain when I cast itsvalue toString orNumber.

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelApr 21, 2022
Copy link
ContributorAuthor

@aifreedomaifreedom left a comment

Choose a reason for hiding this comment

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

The coverage drop is a bit weird. It's an unrelated rule's coverage that dropped (no-magic-numbers). The coverage for the new rule is 100%.

image

return (
node.type === AST_NODE_TYPES.Literal && typeof node.value === 'number'
);
}
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I had to do this because typescript doesn't know the type ofmember.initializer without the util functions, and would complain when I cast itsvalue toString orNumber.

@bradzacherbradzacher removed the awaiting responseIssues waiting for a reply from the OP or another party labelApr 25, 2022
@aifreedomaifreedomforce-pushed theno-duplicate-enum-members branch from93aaa38 to5484161CompareApril 26, 2022 07:36
@aifreedom
Copy link
ContributorAuthor

Oh, no… I updated the branch using the “rebase” button and it seemed to have forced push the commits. Sorry about the inconvenience.@JoshuaKGoldberg you can review the last two commits which have the updates addressing your comments.

@JoshuaKGoldberg
Copy link
Member

Ha, no worries - thanks for the heads up!

And yeah I don't know what's going on with Codecov. The service has been flaky off and on the last few... years. 🙃

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks so much@aifreedom!

@JoshuaKGoldbergJoshuaKGoldbergenabled auto-merge (squash)April 27, 2022 00:18
@JoshuaKGoldbergJoshuaKGoldberg merged commit5899164 intotypescript-eslint:mainApr 27, 2022
@aifreedomaifreedom deleted the no-duplicate-enum-members branchApril 27, 2022 00:24
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull requestMay 8, 2022
This PR contains the following updates:| Package | Type | Update | Change ||---|---|---|---|| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.21.0` -> `5.22.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/5.21.0/5.22.0) || [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.21.0` -> `5.22.0`](https://renovatebot.com/diffs/npm/@typescript-eslint%2fparser/5.21.0/5.22.0) |---### Release Notes<details><summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>### [`v5.22.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5220-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5210v5220-2022-05-02)[Compare Source](typescript-eslint/typescript-eslint@v5.21.0...v5.22.0)##### Bug Fixes-   **eslint-plugin:** \[comma-spacing] verify `nextToken` exists ([#&#8203;4868](typescript-eslint/typescript-eslint#4868)) ([23746f8](typescript-eslint/typescript-eslint@23746f8))##### Features-   **eslint-plugin:** \[no-duplicate-enum-values] add rule ([#&#8203;4833](typescript-eslint/typescript-eslint#4833)) ([5899164](typescript-eslint/typescript-eslint@5899164))</details><details><summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/parser)</summary>### [`v5.22.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5220-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5210v5220-2022-05-02)[Compare Source](typescript-eslint/typescript-eslint@v5.21.0...v5.22.0)**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)</details>---### Configuration📅 **Schedule**: At any time (no schedule defined).🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.--- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.---This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).Co-authored-by: cabr2-bot <cabr2.help@gmail.com>Reviewed-on:https://codeberg.org/Calciumdibromid/CaBr2/pulls/1338Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMay 28, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

Assignees
No one assigned
Labels
enhancement: new plugin ruleNew rule request for eslint-plugin
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

disallow duplicate enum values
3 participants
@aifreedom@JoshuaKGoldberg@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp