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

Clean-up lodash.clone dep, as it serves no purpose #74

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@
"@babel/parser": "^7.21.8",
"@babel/traverse": "^7.21.5",
"@babel/types": "^7.21.5",
"lodash.clone": "^4.5.0",
"semver": "^7.5.0"
},
"devDependencies": {
"@types/babel__generator": "^7.6.4",
"@types/babel__traverse": "^7.18.3",
"@types/lodash.clone": "4.5.7",
"@types/node": "^18.15.13",
"@types/prettier": "^2.7.2",
"@types/semver": "^7.3.13",
Expand Down
10 changes: 5 additions & 5 deletions src/utils/get-sorted-nodes-by-import-order.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import clone from 'lodash.clone';

import {
BUILTIN_MODULES,
newLineNode,
Expand All @@ -14,13 +12,15 @@ import { getSortedNodesGroup } from './get-sorted-nodes-group';
* This function returns the given nodes, sorted in the order as indicated by
* the importOrder array from the given options.
* The plugin considers these import nodes as local import declarations.
* @param nodes A subset of all import nodes that should be sorted.
* @param originalNodes A subset (of all import nodes) that should be sorted.
* @param options Options to influence the behavior of the sorting algorithm.
*/
export const getSortedNodesByImportOrder: GetSortedNodes = (nodes, options) => {
export const getSortedNodesByImportOrder: GetSortedNodes = (
originalNodes,
options,
) => {
let { importOrder } = options;

const originalNodes = nodes.map(clone);
Copy link
Owner

Choose a reason for hiding this comment

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

Are we sure we don't need to clone? It looks like the use of getSortedNodesGroup has a .sort, which will change them in place. Though, I guess it's not mutating the nodes themselves, just their order within our importOrderGroups array. So yeah, I think I've convinced myself this is fine.

const finalNodes: ImportOrLine[] = [];

if (!importOrder.includes(THIRD_PARTY_MODULES_SPECIAL_WORD)) {
Expand Down
17 changes: 0 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,6 @@
resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.5.tgz#ae69bcbb1bebb68c4ac0b11e9d8ed04526b3562b"
integrity sha512-mEo1sAde+UCE6b2hxn332f1g1E8WfYRu6p5SvTKr2ZKC1f7gFJXk4h5PyGP9Dt6gCaG8y8XhwnXWC6Iy2cmBng==

"@types/lodash.clone@4.5.7":
version "4.5.7"
resolved "https://registry.yarnpkg.com/@types/lodash.clone/-/lodash.clone-4.5.7.tgz#110e28a71b3328c24d367162f48ae6aa9dab1973"
integrity sha512-jugWYM+xBUQCpWbn7p6BSbf8bRMHtJYnEIGZYngbStaU0aN4VFgAAkGgsc+MtHuepBOmjyUGiGv+dHnQQIGLZA==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.194"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
integrity sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==

"@types/node@*":
version "20.1.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.1.2.tgz#8fd63447e3f99aba6c3168fd2ec4580d5b97886f"
Expand Down Expand Up @@ -747,11 +735,6 @@ local-pkg@^0.4.3:
resolved "https://registry.yarnpkg.com/local-pkg/-/local-pkg-0.4.3.tgz#0ff361ab3ae7f1c19113d9bb97b98b905dbc4963"
integrity sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==

lodash.clone@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clone/-/lodash.clone-4.5.0.tgz#195870450f5a13192478df4bc3d23d2dea1907b6"
integrity sha512-GhrVeweiTD6uTmmn5hV/lzgCQhccwReIVRLHp7LT4SopOjqEZ5BbX8b5WWEtAKasjmy8hR7ZPwsYlxRCku5odg==

lodash@^4.17.15:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
Expand Down