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

@@ -1,65 +1,79 @@
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { FunctionCallData, ScriptData } from 'js-yaml-loader!@/*';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { FunctionCallDataStub } from '@tests/unit/stubs/FunctionCallDataStub';
export class ScriptDataStub implements ScriptData {
public static createWithCode(): ScriptDataStub {
return new ScriptDataStub()
.withCode('stub-code')
.withRevertCode('stub-revert-code');
}
public static createWithCall(call?: FunctionCallData): ScriptDataStub {
let instance = new ScriptDataStub();
if (call) {
instance = instance.withCall(call);
} else {
instance = instance.withMockCall();
}
return instance;
}
public static createWithoutCallOrCodes(): ScriptDataStub {
return new ScriptDataStub();
}
public static createWithCode(): ScriptDataStub {
return new ScriptDataStub()
.withCode('stub-code')
.withRevertCode('stub-revert-code');
}
public name = 'valid-name';
public code = undefined;
public revertCode = undefined;
public call = undefined;
public recommend = RecommendationLevel[RecommendationLevel.Standard].toLowerCase();
public docs = ['hello.com'];
public static createWithCall(call?: FunctionCallData): ScriptDataStub {
let instance = new ScriptDataStub();
if (call) {
instance = instance.withCall(call);
} else {
instance = instance.withMockCall();
}
return instance;
}
private constructor() { /* use static methods for constructing */ }
public static createWithoutCallOrCodes(): ScriptDataStub {
return new ScriptDataStub();
}
public withName(name: string): ScriptDataStub {
this.name = name;
return this;
}
public withDocs(docs: string[]): ScriptDataStub {
this.docs = docs;
return this;
}
public withCode(code: string): ScriptDataStub {
this.code = code;
return this;
}
public withRevertCode(revertCode: string): ScriptDataStub {
this.revertCode = revertCode;
return this;
}
public withMockCall(): ScriptDataStub {
this.call = new FunctionCallDataStub();
return this;
}
public withCall(call: FunctionCallData): ScriptDataStub {
this.call = call;
return this;
}
public withRecommend(recommend: string): ScriptDataStub {
this.recommend = recommend;
return this;
}
public withRecommendationLevel(level: RecommendationLevel): ScriptDataStub {
this.recommend = RecommendationLevel[level].toLowerCase();
return this;
}
public name = 'valid-name';
public code = undefined;
public revertCode = undefined;
public call = undefined;
public recommend = RecommendationLevel[RecommendationLevel.Standard].toLowerCase();
public docs = ['hello.com'];
private constructor() { /* use static methods for constructing */ }
public withName(name: string): ScriptDataStub {
this.name = name;
return this;
}
public withDocs(docs: string[]): ScriptDataStub {
this.docs = docs;
return this;
}
public withCode(code: string): ScriptDataStub {
this.code = code;
return this;
}
public withRevertCode(revertCode: string): ScriptDataStub {
this.revertCode = revertCode;
return this;
}
public withMockCall(): ScriptDataStub {
this.call = new FunctionCallDataStub();
return this;
}
public withCall(call: FunctionCallData): ScriptDataStub {
this.call = call;
return this;
}
public withRecommend(recommend: string): ScriptDataStub {
this.recommend = recommend;
return this;
}
public withRecommendationLevel(level: RecommendationLevel): ScriptDataStub {
this.recommend = RecommendationLevel[level].toLowerCase();
return this;
}
}