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

fix(eslint): Enable no-constant-binary-expression and fix violations #83273

Merged
merged 4 commits into from
Jan 14, 2025

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Jan 10, 2025

https://eslint.org/docs/latest/rules/no-constant-binary-expression

Found and fixed some bugs. Also removed some unneeded ?? '' fallbacks. ?? is only useful when the left side could be null or undefined.

@ryan953 ryan953 requested review from a team as code owners January 10, 2025 22:05
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jan 10, 2025
@@ -369,11 +369,7 @@ export function getProject(
eventData: EventData,
projects: Project[]
): Project | undefined {
const projectSlug = (eventData?.project as string) || undefined;

if (typeof projectSlug === undefined) {
Copy link
Member Author

Choose a reason for hiding this comment

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

typeof returns a string, it can never equal undefined... but it could equal "undefined"

Copy link
Member Author

Choose a reason for hiding this comment

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

both no-constant-binary-expression and valid-typeof would catch this statement.

Comment on lines +165 to +167
const hasDifferentialFlamegraphPageFeature = organization.features.includes(
'profiling-differential-flamegraph-page'
);
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @JonasBa @Zylphrex you're the only two mentioned in the flagpole config for this. It'll be enabled now for ya.

@@ -41,22 +41,21 @@ export function getDocsLinkForEventType(
event: DataCategoryExact | string // TODO(isabella): get rid of strings after removing need for backward compatibility on gs
) {
switch (event) {
case DataCategoryExact.TRANSACTION || 'transaction':
Copy link
Member Author

@ryan953 ryan953 Jan 10, 2025

Choose a reason for hiding this comment

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

This should resolve to be DataCategoryExact.TRANSACTION || 'transaction' === DataCategoryExact.TRANSACTION therefore the right hand side of the || isn't needed.

It doesn't really matter because the enum value and the string value are the same, so this is a true statement: DataCategoryExact.TRANSACTION === 'transaction'. We don't need to write it out twice, no matter what the function types are.

Comment on lines -47 to -50
case DataCategoryExact.SPAN ||
DataCategoryExact.SPAN_INDEXED ||
'span' ||
'span_indexed':
Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't working before when the function was called with DataCategoryExact.SPAN_INDEXED or span_indexed.

The case would boil down to be the same as case DataCategoryExact.SPAN only so values like "span_indexed" and "spanIndexed" wouldn't match at all and would fall through to the default case below.

Can play with it here: https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABFOA5EBbARgUwE4AUMYADiFAFyIDOUexA5gJSIDeAUO4jQO4xQQAFkVLkWHbtwgBDajkQByBDgUUuk7nhxQQeJAEYA3Jw0y5iqDzgLEAH1uKAJnGqr1GrTr2IATMfeIjjjA0iAANpQBmtq6BgAMccbcAL7sqewQCNRwYTgAdGFwDARKYCoANMhomLiEpSpMTMaZYNm5BUUlltaVKOjY+F1WCo3NWTn5hcUKzq691QN1syNNQA

SCR-20250110-mqxy

Copy link
Member Author

Choose a reason for hiding this comment

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

return true;
}
return false;
// TODO: do we need to return false when `newQueries[searchIndex] === undefined`?
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to 'fix' the existing if-statement because that would cause a change in behavior. But if we need that guard to exist, then it only needs to be if (newQueries[searchIndex] === undefined) { ...

Copy link

codecov bot commented Jan 13, 2025

Bundle Report

Changes will increase total bundle size by 86.42kB (0.28%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
app-webpack-bundle-array-push 31.02MB 86.42kB (0.28%) ⬆️

@ryan953 ryan953 requested a review from a team January 13, 2025 19:49
@ryan953 ryan953 merged commit a968724 into master Jan 14, 2025
43 checks passed
@ryan953 ryan953 deleted the ryan953/eslint-no-constant-binary-expression branch January 14, 2025 20:58
andrewshie-sentry pushed a commit that referenced this pull request Jan 22, 2025
…83273)

https://eslint.org/docs/latest/rules/no-constant-binary-expression

Found and fixed some bugs. Also removed some unneeded `?? ''` fallbacks.
`??` is only useful when the left side could be `null` or `undefined`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants