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

[Misc] Code style: use for loops instead of .forEach() #690

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions api/src/components/defaultLoggerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class DefaultLoggerConfig implements LoggerConfig {
addLevel(module: string, level: string): void {
const nbLevel = this.levels.get(level);
if (nbLevel != undefined) {
this.config.forEach((key) => {
for (const key of this.config.keys()) {
if (key.startsWith(module)) {
const currentLevel = this.computedConfig.get(key);
if (currentLevel == null || (nbLevel && nbLevel > currentLevel)) {
Expand All @@ -53,7 +53,7 @@ export class DefaultLoggerConfig implements LoggerConfig {
}
}
}
});
}
}
}
getLevels(): Map<string, string> {
Expand Down
50 changes: 24 additions & 26 deletions core/hierarchy/hierarchy-xwiki/src/components/componentsInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,30 @@ class XWikiPageHierarchyResolver implements PageHierarchyResolver {
const response = await fetch(restApiUrl, { headers });
const jsonResponse = await response.json();
const hierarchy: Array<PageHierarchyItem> = [];
jsonResponse.hierarchy.items.forEach(
(hierarchyItem: { label: string; url: string; type: string }) => {
// If a document item is not terminal (i.e., WebHome) we exclude it.
if (
hierarchyItem.type != "document" ||
!hierarchyItem.url.endsWith("/")
) {
hierarchy.push({
label: hierarchyItem.label,
pageId: this.storageProvider
.get()
.getPageFromViewURL(hierarchyItem.url)!,
url: this.cristalApp.getRouter().resolve({
name: "view",
params: {
page: this.referenceSerializer.serialize(
this.urlParser.parse(
hierarchyItem.url,
)! as DocumentReference,
),
},
}).href,
});
}
},
);

for (const hierarchyItem of jsonResponse.hierarchy.items) {
// If a document item is not terminal (i.e., WebHome) we exclude it.
if (
hierarchyItem.type != "document" ||
!hierarchyItem.url.endsWith("/")
) {
hierarchy.push({
label: hierarchyItem.label,
pageId: this.storageProvider
.get()
.getPageFromViewURL(hierarchyItem.url)!,
url: this.cristalApp.getRouter().resolve({
name: "view",
params: {
page: this.referenceSerializer.serialize(
this.urlParser.parse(hierarchyItem.url)! as DocumentReference,
),
},
}).href,
});
}
}

hierarchy[0].label = "Home";
return hierarchy;
} catch (error) {
Expand Down
7 changes: 3 additions & 4 deletions core/markdown/markdown-default/src/parseInternalImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ export function parseInternalImages(
modelReferenceParser: ModelReferenceParser,
remoteURLSerializer: RemoteURLSerializer,
): MarkdownIt.Core.RuleCore {
return function (state: StateCore): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.tokens.forEach((blockToken: any) => {
return (state) => {
for (const blockToken of state.tokens) {
if (blockToken.type == "inline") {
handleInlineBlockToken(
blockToken,
Expand All @@ -184,6 +183,6 @@ export function parseInternalImages(
modelReferenceParser,
);
}
});
}
};
}
7 changes: 3 additions & 4 deletions core/markdown/markdown-default/src/parseInternalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ export function parseInternalLinks(
modelReferenceParser: ModelReferenceParser,
remoteURLSerializer: RemoteURLSerializer,
): MarkdownIt.Core.RuleCore {
return function (state: StateCore): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.tokens.forEach((blockToken: any) => {
return (state) => {
for (const blockToken of state.tokens) {
if (blockToken.type == "inline") {
handleInlineBlockToken(
blockToken,
Expand All @@ -207,6 +206,6 @@ export function parseInternalLinks(
modelReferenceParser,
);
}
});
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,21 @@ class GitHubNavigationTreeSource implements NavigationTreeSource {
},
});
const jsonResponse = await response.json();
jsonResponse.payload.tree.items.forEach(
(treeNode: { name: string; path: string; contentType: string }) => {
navigationTree.push({
id: treeNode.path,
label: treeNode.name,
location: new SpaceReference(
undefined,
...treeNode.path.split("/"),
),
url: this.cristalApp.getRouter().resolve({
name: "view",
params: {
page: treeNode.path,
},
}).href,
has_children: treeNode.contentType == "directory",
});
},
);

for (const treeNode of jsonResponse.payload) {
navigationTree.push({
id: treeNode.path,
label: treeNode.name,
location: new SpaceReference(undefined, ...treeNode.path.split("/")),
url: this.cristalApp.getRouter().resolve({
name: "view",
params: {
page: treeNode.path,
},
}).href,
has_children: treeNode.contentType == "directory",
});
}
} catch (error) {
this.logger.error(error);
this.logger.debug("Could not load navigation tree.");
Expand Down
8 changes: 4 additions & 4 deletions macros/src/vue/c-error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export default {
mounted() {
logger?.debug("In warning mounted");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
updated() {
logger?.debug("In field updated");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
};
</script>
8 changes: 4 additions & 4 deletions macros/src/vue/c-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export default {
mounted() {
logger?.debug("In warning mounted");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
updated() {
logger?.debug("In field updated");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
};
</script>
8 changes: 4 additions & 4 deletions macros/src/vue/c-success.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export default {
mounted() {
logger?.debug("In warning mounted");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
updated() {
logger?.debug("In field updated");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
};
</script>
8 changes: 4 additions & 4 deletions macros/src/vue/c-warning.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export default {
mounted() {
logger?.debug("In warning mounted");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
updated() {
logger?.debug("In field updated");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
};
</script>
8 changes: 4 additions & 4 deletions skin/src/vue/c-config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const configList: Array<WikiConfig> = [];
const cristal = inject<CristalApp>("cristal")!;
let configs = cristal.getAvailableConfigurations();

configs.forEach((wikiConfig: WikiConfig) => {
for (const wikiConfig of configs.values()) {
configList.push(wikiConfig);
});
}
const currentConfig = cristal.getWikiConfig().name;
</script>
<template>
Expand Down Expand Up @@ -88,7 +88,7 @@ p {
align-items: center;
}

.grid-container > * {
.grid-container>* {
display: grid;
gap: var(--cr-spacing-medium);
align-items: center;
Expand All @@ -98,7 +98,7 @@ p {
padding: var(--cr-spacing-x-small) var(--cr-spacing-2x-small);
}

.grid-container > *:last-child {
.grid-container>*:last-child {
border-bottom: 0;
}
</style>
8 changes: 4 additions & 4 deletions skin/src/vue/c-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ export default defineComponent({
mounted() {
logger?.debug("In field mounted");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
updated() {
logger?.debug("In field updated");
const cristal = inject<CristalApp>("cristal")!;
addedHTMLField.forEach((fieldName) => {
for (const fieldName of addedHTMLField) {
logger?.debug("Transform image", fieldName);
ContentTools.transformImages(cristal, fieldName);
});
}
},
});
</script>
Loading