Refactor code to comply with ESLint rules

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).
This commit is contained in:
undergroundwires
2022-01-02 18:20:14 +01:00
parent 96265b75de
commit 5b1fbe1e2f
341 changed files with 16126 additions and 15101 deletions

View File

@@ -4,44 +4,47 @@ import { IProjectInformation } from './IProjectInformation';
import { OperatingSystem } from './OperatingSystem';
export class Application implements IApplication {
constructor(public info: IProjectInformation, public collections: readonly ICategoryCollection[]) {
validateInformation(info);
validateCollections(collections);
}
constructor(
public info: IProjectInformation,
public collections: readonly ICategoryCollection[],
) {
validateInformation(info);
validateCollections(collections);
}
public getSupportedOsList(): OperatingSystem[] {
return this.collections.map((collection) => collection.os);
}
public getSupportedOsList(): OperatingSystem[] {
return this.collections.map((collection) => collection.os);
}
public getCollection(operatingSystem: OperatingSystem): ICategoryCollection | undefined {
return this.collections.find((collection) => collection.os === operatingSystem);
}
public getCollection(operatingSystem: OperatingSystem): ICategoryCollection | undefined {
return this.collections.find((collection) => collection.os === operatingSystem);
}
}
function validateInformation(info: IProjectInformation) {
if (!info) {
throw new Error('undefined project information');
}
if (!info) {
throw new Error('undefined project information');
}
}
function validateCollections(collections: readonly ICategoryCollection[]) {
if (!collections) {
throw new Error('undefined collections');
}
if (collections.length === 0) {
throw new Error('no collection in the list');
}
if (collections.filter((c) => !c).length > 0) {
throw new Error('undefined collection in the list');
}
const osList = collections.map((c) => c.os);
const duplicates = getDuplicates(osList);
if (duplicates.length > 0) {
throw new Error('multiple collections with same os: ' +
duplicates.map((os) => OperatingSystem[os].toLowerCase()).join('", "'));
}
if (!collections) {
throw new Error('undefined collections');
}
if (collections.length === 0) {
throw new Error('no collection in the list');
}
if (collections.filter((c) => !c).length > 0) {
throw new Error('undefined collection in the list');
}
const osList = collections.map((c) => c.os);
const duplicates = getDuplicates(osList);
if (duplicates.length > 0) {
throw new Error(`multiple collections with same os: ${
duplicates.map((os) => OperatingSystem[os].toLowerCase()).join('", "')}`);
}
}
function getDuplicates(list: readonly OperatingSystem[]): OperatingSystem[] {
return list.filter((os, index) => list.indexOf(os) !== index);
return list.filter((os, index) => list.indexOf(os) !== index);
}