Skip to content

feat(eslint-plugin): [no-array-delete] add rule #5852

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

mahdi-farnia
Copy link

@mahdi-farnia mahdi-farnia commented Oct 20, 2022

PR Checklist

Overview

Before:
Using delete operator for arrays in JavaScript leaves an empty value & unchanged length property as the actual index is not deleted, Just its value replaced by empty.

declare const array: any[];
declare const i: number;

delete array[i];

After:

declare const array: any[];
declare const i: number;

array.splice(i, 1);

Closes #4432

mahdi-farnia and others added 13 commits October 19, 2022 00:00
I rewrite it again after one month, and i figured out that the last
clone is outdated and i cloned the latest repo and just copied & pasted
the file.
Because of that there is no history available for this project.
Unnecessary Information Removed

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
Rule Is Now Off By Default

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
My bad!😱

Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
This option is unneeded because users can simply turn off the rule
Support for literal method names & better error message for computed and
non-computed method names.
First commit before PR
@nx-cloud
Copy link

nx-cloud bot commented Oct 20, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit bf6b1b6. 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


🟥 Failed Commands
nx run-many --target=lint --parallel
✅ Successfully ran 45 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @mahdi-farnia!

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.

@netlify
Copy link

netlify bot commented Oct 20, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 04ec031
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64c6b38a9021530008153a33
😎 Deploy Preview https://deploy-preview-5852--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.

@codecov
Copy link

codecov bot commented Oct 20, 2022

Codecov Report

Merging #5852 (8230f09) into main (78a5e62) will increase coverage by 0.04%.
Report is 369 commits behind head on main.
The diff coverage is 100.00%.

❗ Current head 8230f09 differs from pull request most recent head 04ec031. Consider uploading reports for the commit 04ec031 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5852      +/-   ##
==========================================
+ Coverage   87.36%   87.41%   +0.04%     
==========================================
  Files         386      387       +1     
  Lines       13190    13217      +27     
  Branches     3867     3870       +3     
==========================================
+ Hits        11524    11553      +29     
+ Misses       1300     1298       -2     
  Partials      366      366              
Flag Coverage Δ
unittest 87.41% <100.00%> (+0.04%) ⬆️

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

Files Changed Coverage Δ
...ackages/eslint-plugin/src/rules/no-array-delete.ts 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

@bradzacher bradzacher changed the title feat(no-array-delete): Disallow delete operator for arrays feat(eslint-plugin): [no-array-delete] add rule Oct 24, 2022
@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Oct 24, 2022
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.

Thanks for sending this in - I'm excited to see the no-array-delete rule land soon*! 🙌

Requesting changes on some structural smoothing-out and more test cases, as well as splitting out the unrelated code into their own PRs.

Let me know if any of this is unclear - and thanks for working with us on it all @mahdi-farnia!

*sorry it took three weeks to get to the review 😬 - it should be sooner after this!

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Nov 16, 2022
@JoshuaKGoldberg
Copy link
Member

Ping @mahdi-farnia - is this still something you have time to work on? No worries if not, just checking in - thanks!

@mahdi-farnia
Copy link
Author

Ping @mahdi-farnia - is this still something you have time to work on? No worries if not, just checking in - thanks!

Hi, Mmm... No nothing left hear.
But it seems I forget to correct my mistake 😅

That should be done in a few minutes...👍

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Feb 19, 2023

@mahdi-farnia I normally wait till folks re-request review - but it looks like this might be ready for review. Do you want me to take another look? 🙂

@mahdi-farnia
Copy link
Author

@mahdi-farnia I normally wait till folks re-request review - but it looks like this might be ready for review. Do you want me to take another look? 🙂

Omg, I thought i should wait till you review them and not to mention you again. 🫤

Yes, please 😄

@mahdi-farnia
Copy link
Author

The lint problem resolved, that was due to uninstalled (i don't know why) package eslint-plugin-unicorn.
Because of that i could not figure out linting problems

mahdi-farnia and others added 2 commits April 7, 2023 18:16
by split if conditions

Co-authored-by: Armano <armano2@users.noreply.github.com>
remove extra if statement
@mahdi-farnia
Copy link
Author

@armano2 thank you so much. your review saved a review and an edit by me.

@mahdi-farnia
Copy link
Author

Actually this is my first serious contribution to an open-source project.

If you see something strange in my code or something that experts don't do in their code, please don't blame me

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label May 6, 2023
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.

🔥 Looks great - very close to merge I think! I did a closer pass and think it's just a few small-ish things blocking review now. Mostly the bug around suggestions.

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Jul 17, 2023
@mahdi-farnia
Copy link
Author

Seems this path is too long 😄

I'll apply suggested changes in the next weekend... (or as soon as I can)

mahdi-farnia and others added 2 commits July 21, 2023 15:06
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@mahdi-farnia
Copy link
Author

After all, please help me resolving conflicts with packages/eslint-plugin/src/configs/strict.ts 🙏

@JoshuaKGoldberg
Copy link
Member

You should be able to run the command mentioned at the top of the file:

// For developers working in the typescript-eslint monorepo:
// You can regenerate it using `yarn generate:configs`

My typical strategy for autogenerated files that are giving me Git merge woes is:

  1. git checkout main -- path/to/file to undo any of my branch's changes to the file
  2. Re-run yarn to reinstall and rebuild everything
  3. Run the command to generate them: here, that's running yarn generate:configs from the packages/eslint-plugin directory

Does that help?

@JoshuaKGoldberg
Copy link
Member

👋 Hey @mahdi-farnia! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging.

@JoshuaKGoldberg JoshuaKGoldberg added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Oct 17, 2023
@mahdi-farnia
Copy link
Author

👋 Hey @mahdi-farnia! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging.

I was waiting for you :) (i requested a review)

@JoshuaKGoldberg
Copy link
Member

Ah, I was under the impression you were waiting for help on resolving the merge conflict with strict.ts. Is that not the case? #5852 (comment) -> #5852 (comment)

delete multiDimesnional[i][i][i][i][i].someProp;
`,
],
invalid: [
Copy link
Member

Choose a reason for hiding this comment

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

A few more test cases off the top of my head:

  • ReadonlyArray<...>
  • readonly ...[]
  • Readonly<...[]>
  • Readonly<Array<...>>

import { unionTypeParts } from 'tsutils';
import * as ts from 'typescript';

import * as util from '../util';
Copy link
Contributor

@StyleShit StyleShit Oct 23, 2023

Choose a reason for hiding this comment

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

util should probably be switched to named imports

@mahdi-farnia
Copy link
Author

Sorry for late response. I am busy these days. I'll apply every requested changes as soon as I touch my computer. 🙂

@JoshuaKGoldberg JoshuaKGoldberg removed the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Oct 23, 2023
@JoshuaKGoldberg
Copy link
Member

@mahdi-farnia since it's been a month I'm going to go ahead and close this PR to keep our queue small. Totally understand not having time for this - thanks for all the work you did to get it started!

If you end up having time to pick it back up, feel free to send a new PR (or re-open this one if it hasn't been auto-locked).

If anybody else ends up wanting to take on these changes in the interim, please do add a co-author attribution if you use any code from this PR.

Thanks!

@JoshuaKGoldberg JoshuaKGoldberg added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Nov 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: new plugin rule New rule request for eslint-plugin stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: no-array-delete
5 participants