Major refactoring using ESLint with rules from AirBnb and Vue. Enable most of the ESLint rules and do necessary linting in the code. Also add more information for rules that are disabled to describe what they are and why they are disabled. Allow logging (`console.log`) in test files, and in development mode (e.g. when working with `npm run serve`), but disable it when environment is production (as pre-configured by Vue). Also add flag (`--mode production`) in `lint:eslint` command so production linting is executed earlier in lifecycle. Disable rules that requires a separate work. Such as ESLint rules that are broken in TypeScript: no-useless-constructor (eslint/eslint#14118) and no-shadow (eslint/eslint#13014).
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
|
import { ICategory, IScript } from '@/domain/ICategory';
|
|
import { ScriptStub } from './ScriptStub';
|
|
|
|
export class CategoryStub extends BaseEntity<number> implements ICategory {
|
|
public name = `category-with-id-${this.id}`;
|
|
|
|
public readonly subCategories = new Array<ICategory>();
|
|
|
|
public readonly scripts = new Array<IScript>();
|
|
|
|
public readonly documentationUrls = new Array<string>();
|
|
|
|
public constructor(id: number) {
|
|
super(id);
|
|
}
|
|
|
|
public includes(script: IScript): boolean {
|
|
return this.getAllScriptsRecursively().some((s) => s.id === script.id);
|
|
}
|
|
|
|
public getAllScriptsRecursively(): readonly IScript[] {
|
|
return [
|
|
...this.scripts,
|
|
...this.subCategories.flatMap((c) => c.getAllScriptsRecursively()),
|
|
];
|
|
}
|
|
|
|
public withScriptIds(...scriptIds: string[]): CategoryStub {
|
|
for (const scriptId of scriptIds) {
|
|
this.withScript(new ScriptStub(scriptId));
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public withScripts(...scripts: IScript[]): CategoryStub {
|
|
for (const script of scripts) {
|
|
this.withScript(script);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public withCategories(...categories: ICategory[]): CategoryStub {
|
|
for (const category of categories) {
|
|
this.withCategory(category);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public withCategory(category: ICategory): CategoryStub {
|
|
this.subCategories.push(category);
|
|
return this;
|
|
}
|
|
|
|
public withScript(script: IScript): CategoryStub {
|
|
this.scripts.push(script);
|
|
return this;
|
|
}
|
|
|
|
public withName(categoryName: string) {
|
|
this.name = categoryName;
|
|
return this;
|
|
}
|
|
}
|