Fix eslint errors

This commit is contained in:
Eric NGUYEN 2023-02-23 13:54:38 +01:00
parent 5b3ab651e6
commit 4e41fda93a
87 changed files with 1003 additions and 702 deletions

View file

@ -14,7 +14,9 @@ import { type IDimensionStyle } from '../Components/SVG/Elements/Dimension';
/// EDITOR DEFAULTS ///
/** Enable fast boot and disable main menu (0 = disabled, 1 = loading, 2 = loaded) */
export const FAST_BOOT = import.meta.env.PROD ? AppState.Loaded : AppState.MainMenu;
export const FAST_BOOT = import.meta.env.PROD
? AppState.Loaded
: AppState.MainMenu;
/** Disable any call to the API (default = false) */
export const DISABLE_API = false;
@ -89,7 +91,9 @@ export function GetDefaultEditorState(configuration: IConfiguration): IEditorSta
throw new Error('Cannot initialize project! Main container has an undefined size');
}
const containerConfig = configuration.AvailableContainers.find(config => config.Type === configuration.MainContainer.Type);
const containerConfig = configuration.AvailableContainers.find(
config => config.Type === configuration.MainContainer.Type
);
let mainContainerConfig: IContainerProperties;
if (containerConfig !== undefined) {
@ -128,9 +132,7 @@ export function GetDefaultEditorState(configuration: IConfiguration): IEditorSta
configuration.MainContainer
);
}
const mainContainer = new ContainerModel(
mainContainerConfig
);
const mainContainer = new ContainerModel(mainContainerConfig);
const containers = new Map<string, IContainerModel>();
containers.set(mainContainer.properties.id, mainContainer);
@ -244,14 +246,16 @@ export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = {
* @param containerConfig default config of the container sent by the API
* @returns {IContainerProperties} Default properties of a newly created container
*/
export function GetDefaultContainerProps(type: string,
export function GetDefaultContainerProps(
type: string,
typeCount: number,
parent: IContainerModel | undefined | null,
x: number,
y: number,
width: number,
height: number,
containerConfig: IAvailableContainer): IContainerProperties {
containerConfig: IAvailableContainer
): IContainerProperties {
const orientation = containerConfig.Orientation ?? Orientation.Horizontal;
return ({
id: `${type}-${typeCount}`,
@ -299,10 +303,12 @@ export function GetDefaultContainerProps(type: string,
});
}
export function GetDefaultSymbolModel(name: string,
export function GetDefaultSymbolModel(
name: string,
newCounters: Record<string, number>,
type: string,
symbolConfig: IAvailableSymbol): ISymbolModel {
symbolConfig: IAvailableSymbol
): ISymbolModel {
const id = `${name}-${newCounters[type]}`;
return {
id,

View file

@ -1,6 +1,9 @@
import { IContainerModel } from '../Interfaces/IContainerModel';
import { type IContainerModel } from '../Interfaces/IContainerModel';
export function * MakeChildrenIterator(containers: Map<string, IContainerModel>, childrenIds: string[]): Generator<IContainerModel, void, unknown> {
export function * MakeChildrenIterator(
containers: Map<string, IContainerModel>,
childrenIds: string[]
): Generator<IContainerModel, void, unknown> {
for (const childId of childrenIds) {
const child = FindContainerById(containers, childId);
@ -15,7 +18,11 @@ export function * MakeChildrenIterator(containers: Map<string, IContainerModel>,
/**
* Returns a Generator iterating of over the children depth-first
*/
export function * MakeDFSIterator(root: IContainerModel, containers: Map<string, IContainerModel>, enableHideChildrenInTreeview = false): Generator<IContainerModel, void, unknown> {
export function * MakeDFSIterator(
root: IContainerModel,
containers: Map<string, IContainerModel>,
enableHideChildrenInTreeview = false
): Generator<IContainerModel, void, unknown> {
const queue: IContainerModel[] = [root];
const visited = new Set<IContainerModel>(queue);
while (queue.length > 0) {
@ -51,7 +58,10 @@ export interface ContainerAndDepthAndTransform extends ContainerAndDepth {
/**
* Returns a Generator iterating of over the children depth-first
*/
export function * MakeBFSIterator(root: IContainerModel, containers: Map<string, IContainerModel>): Generator<ContainerAndDepth, void, unknown> {
export function * MakeBFSIterator(
root: IContainerModel,
containers: Map<string, IContainerModel>
): Generator<ContainerAndDepth, void, unknown> {
const queue: IContainerModel[] = [root];
let depth = 0;
while (queue.length > 0) {
@ -141,7 +151,10 @@ export function GetDepth(containers: Map<string, IContainerModel>, parent: ICont
* Returns the absolute position by iterating to the parent
* @returns The absolute position of the container
*/
export function GetAbsolutePosition(containers: Map<string, IContainerModel>, container: IContainerModel): [number, number] {
export function GetAbsolutePosition(
containers: Map<string, IContainerModel>,
container: IContainerModel
): [number, number] {
const x = container.properties.x;
const y = container.properties.y;
const parent = FindContainerById(containers, container.properties.parentId) ?? null;
@ -230,7 +243,11 @@ export function ApplyParentTransform(
* @param id Id of the container to find
* @returns The container found or undefined if not found
*/
export function FindContainerByIdDFS(root: IContainerModel, containers: Map<string, IContainerModel>, id: string): IContainerModel | undefined {
export function FindContainerByIdDFS(
root: IContainerModel,
containers: Map<string, IContainerModel>,
id: string
): IContainerModel | undefined {
const it = MakeDFSIterator(root, containers);
for (const container of it) {
if (container.properties.id === id) {

View file

@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { IEditorState } from '../Interfaces/IEditorState';
import { IHistoryState } from '../Interfaces/IHistoryState';
import { IContainerModel } from '../Interfaces/IContainerModel';
import { ISymbolModel } from '../Interfaces/ISymbolModel';
import { type IEditorState } from '../Interfaces/IEditorState';
import { type IHistoryState } from '../Interfaces/IHistoryState';
import { type IContainerModel } from '../Interfaces/IContainerModel';
import { type ISymbolModel } from '../Interfaces/ISymbolModel';
/**
* Revive the Editor state
@ -37,7 +37,10 @@ export function ReviveState(state: IHistoryState): void {
state.containers = new Map(containers.map(({ Key, Value }) => [Key, Value]));
}
export function GetCircularReplacer(): (key: any, value: object | Map<string, any> | null) => object | null | undefined {
export function GetCircularReplacer(): (
key: any,
value: object | Map<string, any> | null
) => object | null | undefined {
return (key: any, value: object | null) => {
if (key === 'containers') {
return [...(value as Map<string, any>).entries()]

View file

@ -112,7 +112,8 @@ function GetAllIndexes(arr: number[], val: number): number[] {
* - 4) the selected column must have 1 in the pivot and zeroes in the other rows
* - 5) in the selected rows other columns (other than the selected column)
* must be divided by that pivot: coef / pivot
* - 6) for the others cells, apply the pivot: new value = (-coefficient in the old col) * (coefficient in the new row) + old value
* - 6) for the others cells, apply the pivot:
* new value = (-coefficient in the old col) * (coefficient in the new row) + old value
* - 7) if in the new matrix there are still negative values in the last row,
* redo the algorithm with the new matrix as the base matrix
* - 8) otherwise returns the basic variable such as
@ -135,7 +136,9 @@ function ApplyMainLoop(oldMatrix: number[][], rowlength: number): number[][] {
// to avoid infinite loop try to select the least used selected index
const pivotColIndex = GetLeastUsedIndex(indexes, indexesTried);
// record the usage of index by incrementing
indexesTried[pivotColIndex] = indexesTried[pivotColIndex] !== undefined ? indexesTried[pivotColIndex] + 1 : 1;
indexesTried[pivotColIndex] = indexesTried[pivotColIndex] !== undefined
? indexesTried[pivotColIndex] + 1
: 1;
// 2) find the smallest non negative non null ratio bi/xij (O(m))
const ratios = [];
@ -210,7 +213,9 @@ function GetSolutions(nCols: number, finalMatrix: number[][]): number[] {
const col: number[] = [];
for (let j = 0; j < finalMatrix.length; j++) {
const row = finalMatrix[j];
counts[row[i]] = counts[row[i]] !== undefined ? counts[row[i]] + 1 : 1;
counts[row[i]] = counts[row[i]] !== undefined
? counts[row[i]] + 1
: 1;
col.push(row[i]);
}

View file

@ -6,5 +6,7 @@ export function TruncateString(str: string, num: number): string {
}
export function Camelize(str: string): any {
return str.split('-').map((word, index) => index > 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word).join('');
return str.split('-').map((word, index) => index > 0
? word.charAt(0).toUpperCase() + word.slice(1)
: word).join('');
}

View file

@ -1,6 +1,6 @@
/* eslint-disable import/export */
import * as React from 'react';
import { cleanup, render, RenderResult } from '@testing-library/react';
import type * as React from 'react';
import { cleanup, render, type RenderResult } from '@testing-library/react';
import { afterEach } from 'vitest';
afterEach(() => {