-
Notifications
You must be signed in to change notification settings - Fork 25
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
Drop unused code #5067
Drop unused code #5067
Conversation
❯ ts-prune > a ❯ cat a | rg -e '([^:]+).+ - (\w+) \(used in module\)' --only-matching --no-filename --replace 'sed -i "" "s/export type $2/type $2/" $1' | sh also with const and function instead of type ❯ git checkout -- src/**/*.stories.*
Codecov Report
@@ Coverage Diff @@
## main #5067 +/- ##
==========================================
+ Coverage 59.70% 60.30% +0.60%
==========================================
Files 972 961 -11
Lines 29404 29064 -340
Branches 5636 5557 -79
==========================================
- Hits 17555 17527 -28
+ Misses 11849 11537 -312
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -26,7 +26,7 @@ import { PipelineFlavor } from "@/pageEditor/pageEditorTypes"; | |||
|
|||
export const MULTIPLE_RENDERERS_ERROR_MESSAGE = | |||
"A panel can only have one renderer. There are one or more other renderers configured for this extension."; | |||
export const RENDERER_MUST_BE_LAST_BLOCK_ERROR_MESSAGE = | |||
const RENDERER_MUST_BE_LAST_BLOCK_ERROR_MESSAGE = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This export could be useful!"
If/when it is, re-exporting it takes seconds
@@ -1,61 +0,0 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module for example has a copy in /brickModalNoTags/
import SwitchButtonWidget from "@/components/form/widgets/switchButton/SwitchButtonWidget"; | ||
import { makeLabelForSchemaField } from "@/components/fields/schemaFields/schemaFieldUtils"; | ||
|
||
const BooleanField: React.FunctionComponent<SchemaFieldProps> = (props) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the last usage was dropped in #2915
@@ -1,38 +0,0 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last usage dropped in #4071
@@ -239,86 +212,6 @@ export async function runRendererBlock( | |||
} | |||
} | |||
|
|||
export async function runReaderBlock({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,53 +0,0 @@ | |||
export function globalSearch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A whole vendor dependency could now be dropped!
Which tool did you run? Is it eslint? Would be nice to mark which functions must be exported b/c they're used by the app. And then enforce no unnecessary exports/dead code in CI |
@@ -54,7 +52,6 @@ export async function init(): Promise<void> { | |||
registerBuiltinBlocks(); | |||
registerContribBlocks(); | |||
|
|||
addListenerForUpdateSelectedElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fregante Why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you follow the imported file you'll reach one of the functions that was unused. First I deleted that one, then the file became unused, then this import did nothing. It's related to one of the pageScript WITH_WINDOW functions or something like that.
The tool is ts-prune
It can't be automated because it has a lot of false positives and it doesn't actually edit the files. I just clicked its list and looked at the inline blame on my IDE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't be automated because it has a lot of false positives
I ran the report, and it doesn't look like many false positives. There's way to ignore file patterns: --ignore '.test.tsx?|.stories.tsx?'
and also ignore individual lines (which would be useful for API surface area called by extension)
I'll ping @mnholtz and @alanb43 as a potential tool to add to our CI
export const detectFrameworks = getMethod("DETECT_FRAMEWORKS"); | ||
|
||
export const runBlock = getMethod("RUN_SINGLE_BLOCK"); | ||
export const runRendererBlock = getMethod("RUN_RENDERER_BLOCK"); | ||
export const runReaderBlock = getMethod("RUN_READER_BLOCK"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -40,7 +40,7 @@ export type RendererOptions = { | |||
* Returns true if `literalOrTemplate` includes any template expressions that would be replaced by `context`. | |||
* @param literalOrTemplate the string literal or Nunjucks/Handlebars template. | |||
*/ | |||
export function containsTemplateExpression(literalOrTemplate: string): boolean { | |||
function containsTemplateExpression(literalOrTemplate: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is is replicated in 3-4 places (search for .includes("{{")
). We might want to consolidate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open an issue or PR, I'm not familiar with this code. It's best to leave logic changes out of large "cleanup" PRs so they're easier to follow
src/services/api.ts
Outdated
@@ -437,7 +436,6 @@ export const { | |||
useUpdatePackageMutation, | |||
useDeletePackageMutation, | |||
useListPackageVersionsQuery, | |||
useUpdateScopeMutation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely used by the app? Or is it repeated in the app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That I don't know unfortunately. I can open a temporary App PR based on this branch to find out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this export is used locally but due to the way it's being exported it's not being detected correctly by ts-prune.
useGetGroupsQuery
is used by the app but it seems to be repeated there.
I reverted the changes made to this file anyway.
@fregante looks good overall. Which tool are you using for the analysis?
|
All good, you can see the full test suite on https://github.com/pixiebrix/pixiebrix-app/actions/runs/3982507927/jobs/6827031840 There was only one missed export: pixiebrix-app/src/auth/authUtils.ts:19:10 - error TS2459: Module '"@/auth/authUtils"' declares 'selectOrganizations' locally, but it is not exported.
import { selectOrganizations } from "@/auth/authUtils";
~~~~~~~~~~~~~~~~~~~
pixiebrix-extension/src/auth/authUtils.ts:22:10
function selectOrganizations(
~~~~~~~~~~~~~~~~~~~
'selectOrganizations' is declared here. |
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
@@ -19,6 +19,7 @@ import { type Me } from "@/types/contract"; | |||
import { type UserDataUpdate, type AuthState } from "@/auth/authTypes"; | |||
import { type UUID } from "@/core"; | |||
|
|||
// Used by the app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fregante it's better to use the ts-prune-ignore-next
with a comment so that it doesn't show up in future reports
https://github.com/nadeesha/ts-prune#how-do-i-ignore-a-specific-identifier
What this PR does
This PR deletes unused code + drops exports that aren't imported anywhere (which helps with the automated detection of first part)
Discussion
I found a lot of surprisingly-unused code in the extension, some dating back to the original commit, replaced by modern alternatives or simply no longer useful. Some of this code requires maintenance via linting and missed "TODOs", so keeping it is counterproductive.
The tool also found more recent code (~6-7 months ago) which I did not delete.
Reviewer notes
To keep reviews speedy, if you see anything potentially useful again in the future, leave a comment with just "keep" and I'll restore with any of its dependencies. 👍
It's also possible that this PR highlights some issues, so please leave a comment if something doesn't look right.
One of the surprises is that we had two identical
SelectorSelectorField
components and neither one of them was used 🤔