Skip to content

feat(eslint-plugin): add no-dynamic-delete rule #1058

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

Closed

Conversation

dvorsky
Copy link

@dvorsky dvorsky commented Oct 9, 2019

Hi! I wanted to contribute to the project so I looked at roadmap and saw that no-dynamic-delete rule was unimplemented. There was no issue for it so I'm not sure if you're open to merging this, but wanted to try my hand at creating eslint rules anyway 😄

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @dvorsky!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Oct 9, 2019

Codecov Report

Merging #1058 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1058      +/-   ##
==========================================
+ Coverage   94.14%   94.15%   +<.01%     
==========================================
  Files         115      116       +1     
  Lines        5023     5031       +8     
  Branches     1406     1408       +2     
==========================================
+ Hits         4729     4737       +8     
  Misses        166      166              
  Partials      128      128
Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/no-dynamic-delete.ts 100% <100%> (ø)
packages/eslint-plugin/src/rules/index.ts 100% <100%> (ø) ⬆️

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

thanks for your contribution!

A tip for future - the issues are usually a better place to find things that need contributing to. That way you can find rules / options that other people have requested.
Happy to accept this PR and get closer to parity with tslint though.

I see you copied the test cases from the tslint repo. These form a good basis, but they mostly only test the positive case (i.e. the case where the rule matches).

One thing we look for in tests is coverage for the negative cases as well, to ensure there are no unexpected crashes, or false positives.

Could you please add some test cases like

delete container[variable];
delete container[++i];
delete container[i--];
delete container;
delete container.fn();
delete 'a';
delete 1;
delete container!;
delete (container as any).a;

Whilst some of these are semantically invalid code (typescript will report an error for them), they are syntactically valid, which means we have to ensure the rule doesn't crash on them.

return;
}

if ((node.argument as TSESTree.MemberExpression).computed) {
Copy link
Member

Choose a reason for hiding this comment

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

prefer a physical check to a type cast, as it increases safety

Suggested change
if ((node.argument as TSESTree.MemberExpression).computed) {
if (node.argument.type === TSESTree.MemberExpression && node.argument.computed) {

},
schema: [],
},
defaultOptions: [null],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
defaultOptions: [null],
defaultOptions: [],

@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Oct 10, 2019
@bradzacher
Copy link
Member

I completely forgot that there was already a PR for this: #565.
It's been in progress for a while, but it should be ready to review, closing this in favour of that.

@bradzacher bradzacher closed this Oct 15, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants