Skip to content

Commit 2e0d650

Browse files
ryan953andrewshie-sentry
authored andcommitted
chore(eslint): Enable and auto-fix prefer-array-index-of (#88047)
1 parent 25295d2 commit 2e0d650

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export default typescript.config([
614614
'unicorn/prefer-array-find': 'error',
615615
'unicorn/prefer-array-flat-map': 'error',
616616
'unicorn/prefer-array-flat': 'off', // TODO(ryan953): Fix violations and enable this rule
617-
'unicorn/prefer-array-index-of': 'off', // TODO(ryan953): Fix violations and enable this rule
617+
'unicorn/prefer-array-index-of': 'error',
618618
'unicorn/prefer-array-some': 'off', // TODO(ryan953): Fix violations and enable this rule
619619
'unicorn/prefer-date-now': 'error',
620620
'unicorn/prefer-default-parameters': 'warn', // TODO(ryan953): Fix violations and enable this rule

static/app/components/deprecatedSmartSearchBar/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ class DeprecatedSmartSearchBar extends Component<DefaultProps & Props, State> {
658658

659659
let offset = filterTokens[0]!.location.end.offset;
660660
if (token) {
661-
const tokenIndex = filterTokens.findIndex(tok => tok === token);
661+
// @ts-expect-error: Mismatched types
662+
const tokenIndex = filterTokens.indexOf(token);
662663
if (tokenIndex !== -1 && tokenIndex + 1 < filterTokens.length) {
663664
offset = filterTokens[tokenIndex + 1]!.location.end.offset;
664665
}
@@ -677,7 +678,8 @@ class DeprecatedSmartSearchBar extends Component<DefaultProps & Props, State> {
677678
const hasExecCommand = typeof document.execCommand === 'function';
678679

679680
if (token && filterTokens.length > 0) {
680-
const index = filterTokens.findIndex(tok => tok === token) ?? -1;
681+
// @ts-expect-error: Mismatched types
682+
const index = filterTokens.indexOf(token) ?? -1;
681683
const newQuery =
682684
// We trim to remove any remaining spaces
683685
query.slice(0, token.location.start.offset).trim() +

static/app/components/replays/useJumpButtons.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export default function useJumpButtons({
2828
targetOffsetMs: currentTime,
2929
allowExact: true,
3030
});
31-
const index = frames.findIndex(spanFrame => frame === spanFrame);
31+
if (!frame) {
32+
return frames.length - 1;
33+
}
34+
const index = frames.indexOf(frame);
3235
// index is -1 at end of replay, so use last index
3336
return index === -1 ? frames.length - 1 : index;
3437
}, [currentTime, frames]);

static/app/stores/selectedGroupStore.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ const storeConfig: SelectedGroupStoreDefinition = {
139139
}
140140

141141
const ids = GroupStore.getAllItemIds();
142-
const lastIdx = ids.findIndex(id => id === this.state.lastSelected);
143-
const currentIdx = ids.findIndex(id => id === itemId);
142+
const lastIdx = ids.indexOf(this.state.lastSelected);
143+
const currentIdx = ids.indexOf(itemId);
144144

145145
if (lastIdx === -1 || currentIdx === -1) {
146146
return;

static/app/views/dashboards/widgetBuilder/buildSteps/groupByStep/groupBySelector.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ export function GroupBySelector({
129129
}>(
130130
(acc, key) => {
131131
const value = fieldOptions[key]!;
132-
const optionInColumnsIndex = columnFieldsAsString.findIndex(
133-
column => column === value.value.meta.name
134-
);
132+
const optionInColumnsIndex = columnFieldsAsString.indexOf(value.value.meta.name);
135133
if (optionInColumnsIndex === -1) {
136134
acc.filteredFieldOptions[key] = value;
137135
return acc;

static/app/views/projectDetail/projectCharts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ProjectCharts extends Component<Props, State> {
123123
.map(urlKey => {
124124
return decodeScalar(
125125
location.query[urlKey],
126-
this.defaultDisplayModes[visibleCharts.findIndex(value => value === urlKey)]!
126+
this.defaultDisplayModes[visibleCharts.indexOf(urlKey)]!
127127
);
128128
});
129129
}

0 commit comments

Comments
 (0)