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

chore(eslint): Enable and auto-fix prefer-array-index-of #88047

Merged
merged 2 commits into from
Apr 2, 2025
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: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export default typescript.config([
'unicorn/prefer-array-find': 'off', // TODO(ryan953): Fix violations and enable this rule
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-flat': 'off', // TODO(ryan953): Fix violations and enable this rule
'unicorn/prefer-array-index-of': 'off', // TODO(ryan953): Fix violations and enable this rule
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'off', // TODO(ryan953): Fix violations and enable this rule
'unicorn/prefer-date-now': 'error',
'unicorn/prefer-default-parameters': 'warn', // TODO(ryan953): Fix violations and enable this rule
Expand Down
6 changes: 4 additions & 2 deletions static/app/components/deprecatedSmartSearchBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ class DeprecatedSmartSearchBar extends Component<DefaultProps & Props, State> {

let offset = filterTokens[0]!.location.end.offset;
if (token) {
const tokenIndex = filterTokens.findIndex(tok => tok === token);
// @ts-expect-error: Mismatched types
const tokenIndex = filterTokens.indexOf(token);
Comment on lines +661 to +662
Copy link
Member Author

Choose a reason for hiding this comment

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

There's a type error here i didn't dig into, the type of token is huge.

That the types don't match might indicate an (existing?) problem

if (tokenIndex !== -1 && tokenIndex + 1 < filterTokens.length) {
offset = filterTokens[tokenIndex + 1]!.location.end.offset;
}
Expand All @@ -677,7 +678,8 @@ class DeprecatedSmartSearchBar extends Component<DefaultProps & Props, State> {
const hasExecCommand = typeof document.execCommand === 'function';

if (token && filterTokens.length > 0) {
const index = filterTokens.findIndex(tok => tok === token) ?? -1;
// @ts-expect-error: Mismatched types
const index = filterTokens.indexOf(token) ?? -1;
const newQuery =
// We trim to remove any remaining spaces
query.slice(0, token.location.start.offset).trim() +
Expand Down
5 changes: 4 additions & 1 deletion static/app/components/replays/useJumpButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export default function useJumpButtons({
targetOffsetMs: currentTime,
allowExact: true,
});
const index = frames.findIndex(spanFrame => frame === spanFrame);
if (!frame) {
return frames.length - 1;
}
const index = frames.indexOf(frame);
// index is -1 at end of replay, so use last index
return index === -1 ? frames.length - 1 : index;
}, [currentTime, frames]);
Expand Down
4 changes: 2 additions & 2 deletions static/app/stores/selectedGroupStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ const storeConfig: SelectedGroupStoreDefinition = {
}

const ids = GroupStore.getAllItemIds();
const lastIdx = ids.findIndex(id => id === this.state.lastSelected);
const currentIdx = ids.findIndex(id => id === itemId);
const lastIdx = ids.indexOf(this.state.lastSelected);
const currentIdx = ids.indexOf(itemId);

if (lastIdx === -1 || currentIdx === -1) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export function GroupBySelector({
}>(
(acc, key) => {
const value = fieldOptions[key]!;
const optionInColumnsIndex = columnFieldsAsString.findIndex(
column => column === value.value.meta.name
);
const optionInColumnsIndex = columnFieldsAsString.indexOf(value.value.meta.name);
if (optionInColumnsIndex === -1) {
acc.filteredFieldOptions[key] = value;
return acc;
Expand Down
2 changes: 1 addition & 1 deletion static/app/views/projectDetail/projectCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ProjectCharts extends Component<Props, State> {
.map(urlKey => {
return decodeScalar(
location.query[urlKey],
this.defaultDisplayModes[visibleCharts.findIndex(value => value === urlKey)]!
this.defaultDisplayModes[visibleCharts.indexOf(urlKey)]!
);
});
}
Expand Down
Loading