Skip to content

chore: enable unicorn/no-for-loop #9628

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export default tseslint.config(
//

'jsdoc/informative-docs': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-typeof-undefined': 'error',
},
},
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/no-unsafe-argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class FunctionSignature {
let restType: RestType | null = null;

const parameters = signature.getParameters();
for (let i = 0; i < parameters.length; i += 1) {
const param = parameters[i];
for (const [i, param] of parameters.entries()) {
Copy link
Member

Choose a reason for hiding this comment

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

Tim Gunn going 'eww' by sticking his tongue out and holding his hand up

const type = checker.getTypeOfSymbolAtLocation(param, tsNode);

const decl = param.getDeclarations()?.[0];
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/src/rules/prefer-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export default createRule({
return false;
}

for (let i = 0; i < paramsA.length; ++i) {
const paramA = paramsA[i];
for (const [i, paramA] of paramsA.entries()) {
const paramB = paramsB[i];

// Check name, type, and question token once.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ export default createRule<Options, MessageIds>({
return false;
}

for (let i = 0; i < tokens1.length; ++i) {
const token1 = tokens1[i];
for (const [i, token1] of tokens1.entries()) {
const token2 = tokens2[i];

if (token1.type !== token2.type || token1.value !== token2.value) {
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin/tests/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function renderLintResults(code: string, errors: Linter.LintMessage[]): string {
const output: string[] = [];
const lines = code.split(/\r?\n/);

for (let i = 0; i < lines.length; i++) {
const line = lines[i];
for (const [i, line] of lines.entries()) {
output.push(line);

for (const error of errors) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rule-schema-to-typescript-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function compile(

const refTypes: string[] = [];
const types: AST[] = [];
for (let i = 0; i < schema.length; i += 1) {
const result = compileSchema(schema[i], i);
for (const [i, element] of schema.entries()) {
const result = compileSchema(element, i);
refTypes.push(...result.refTypes);
types.push(result.type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,22 @@ describe('ES6 destructuring assignments', () => {
expect(variables).toHaveLength(6);
const expectedVariableNames = ['arguments', 'a', 'b', 'c', 'd', 'rest'];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}

expect(scope.references).toHaveLength(6);
const expectedReferenceNames = ['a', 'b', 'c', 'd', 'rest'];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
expect(scope.references[index].isWrite()).toBeTruthy();
}
Expand Down Expand Up @@ -639,8 +645,11 @@ describe('ES6 destructuring assignments', () => {
'world',
];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}
expect(scope.references).toHaveLength(8);
const expectedReferenceNames = [
Expand All @@ -653,9 +662,12 @@ describe('ES6 destructuring assignments', () => {
'world',
];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
expect(scope.references[index].isWrite()).toBeTruthy();
}
Expand Down Expand Up @@ -811,9 +823,12 @@ describe('ES6 destructuring assignments', () => {
expect(scope.references).toHaveLength(6);
const expectedReferenceNames = ['a', 'b', 'c', 'd', 'rest'];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
expect(scope.references[index].isWrite()).toBeTruthy();
expect(scope.references[index].resolved).toBeNull();
Expand Down Expand Up @@ -947,9 +962,12 @@ describe('ES6 destructuring assignments', () => {
'world',
];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
expect(scope.references[index].isWrite()).toBeTruthy();
}
Expand Down Expand Up @@ -1096,8 +1114,11 @@ describe('ES6 destructuring assignments', () => {
'world',
];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}
expect(scope.references).toHaveLength(0);
});
Expand All @@ -1124,8 +1145,11 @@ describe('ES6 destructuring assignments', () => {
expect(variables).toHaveLength(5);
const expectedVariableNames = ['arguments', 'a', 'b', 'c', 'd'];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}
expect(scope.references).toHaveLength(6);
const expectedReferenceNames = [
Expand All @@ -1137,9 +1161,12 @@ describe('ES6 destructuring assignments', () => {
'array',
];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
}
});
Expand All @@ -1166,8 +1193,11 @@ describe('ES6 destructuring assignments', () => {
expect(variables).toHaveLength(5);
const expectedVariableNames = ['arguments', 'a', 'b', 'c', 'd'];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}
expect(scope.references).toHaveLength(7);
const expectedReferenceNames = [
Expand All @@ -1180,9 +1210,12 @@ describe('ES6 destructuring assignments', () => {
'array',
];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
}
});
Expand All @@ -1209,8 +1242,11 @@ describe('ES6 destructuring assignments', () => {
expect(variables).toHaveLength(5);
const expectedVariableNames = ['arguments', 'a', 'b', 'c', 'd'];

for (let index = 0; index < expectedVariableNames.length; index++) {
expect(variables[index].name).toBe(expectedVariableNames[index]);
for (const [
index,
expectedVariableName,
] of expectedVariableNames.entries()) {
expect(variables[index].name).toBe(expectedVariableName);
}
expect(scope.references).toHaveLength(10);
const expectedReferenceNames = [
Expand All @@ -1226,9 +1262,12 @@ describe('ES6 destructuring assignments', () => {
'array',
];

for (let index = 0; index < expectedReferenceNames.length; index++) {
for (const [
index,
expectedReferenceName,
] of expectedReferenceNames.entries()) {
expect(scope.references[index].identifier.name).toBe(
expectedReferenceNames[index],
expectedReferenceName,
);
}
});
Expand Down
3 changes: 1 addition & 2 deletions packages/type-utils/src/isUnsafeAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ function isUnsafeAssignmentWorker(
const typeArguments = type.typeArguments ?? [];
const receiverTypeArguments = receiver.typeArguments ?? [];

for (let i = 0; i < typeArguments.length; i += 1) {
const arg = typeArguments[i];
for (const [i, arg] of typeArguments.entries()) {
const receiverArg = receiverTypeArguments[i];

const unsafe = isUnsafeAssignmentWorker(
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-estree/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,8 @@ export function firstDefined<T, U>(
return undefined;
}

for (let i = 0; i < array.length; i++) {
const result = callback(array[i], i);
for (const [i, element] of array.entries()) {
const result = callback(element, i);
if (result !== undefined) {
return result;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/website/src/components/ast/selectedRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ function findInObject(
};
}
} else if (Array.isArray(child)) {
for (let index = 0; index < child.length; ++index) {
const arrayChild: unknown = child[index];
// typescript array like elements have other iterable items
if (typeof index === 'number' && isRecord(arrayChild)) {
for (const [index, arrayChild] of child.entries()) {
if (isRecord(arrayChild)) {
Copy link
Member

Choose a reason for hiding this comment

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

Ok this one actually kind of makes sense IMO 😄

if (isInRange(cursorPosition, arrayChild)) {
return {
key: [name, String(index)],
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy