Skip to content

Commit

Permalink
move code to util
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkwaiblinger committed Apr 7, 2024
1 parent 4c65fcc commit 5d13494
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions packages/eslint-plugin/src/rules/no-for-in-array.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { TSESTree } from '@typescript-eslint/utils';
import * as ts from 'typescript';

import {
createRule,
getConstrainedTypeAtLocation,
getParserServices,
isTypeArrayTypeOrUnionOfArrayTypes,
nullThrows,
} from '../util';
import { getForStatementHeadLoc } from '../util/getForStatementHeadLoc';

export default createRule({
name: 'no-for-in-array',
Expand All @@ -26,22 +25,6 @@ export default createRule({
},
defaultOptions: [],
create(context) {
function getReportLoc(
forInNode: TSESTree.ForInStatement,
): TSESTree.SourceLocation {
const closingParens = nullThrows(
context.sourceCode.getTokenBefore(
forInNode.body,
token => token.value === ')',
),
'for-in must have a closing parenthesis.',
);
return {
start: structuredClone(forInNode.loc.start),
end: structuredClone(closingParens.loc.end),
};
}

return {
ForInStatement(node): void {
const services = getParserServices(context);
Expand All @@ -54,7 +37,7 @@ export default createRule({
(type.flags & ts.TypeFlags.StringLike) !== 0
) {
context.report({
loc: getReportLoc(node),
loc: getForStatementHeadLoc(context.sourceCode, node),
messageId: 'forInViolation',
});
}
Expand Down

0 comments on commit 5d13494

Please sign in to comment.