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).
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { ISharedFunction, ISharedFunctionBody, FunctionBodyType } from '@/application/Parser/Script/Compiler/Function/ISharedFunction';
|
|
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
|
import { IFunctionCall } from '@/application/Parser/Script/Compiler/Function/Call/IFunctionCall';
|
|
import { FunctionParameterCollectionStub } from './FunctionParameterCollectionStub';
|
|
import { FunctionCallStub } from './FunctionCallStub';
|
|
|
|
export class SharedFunctionStub implements ISharedFunction {
|
|
public name = 'shared-function-stub-name';
|
|
|
|
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub()
|
|
.withParameterName('shared-function-stub-parameter-name');
|
|
|
|
private code = 'shared-function-stub-code';
|
|
|
|
private revertCode = 'shared-function-stub-revert-code';
|
|
|
|
private bodyType: FunctionBodyType = FunctionBodyType.Code;
|
|
|
|
private calls: IFunctionCall[] = [new FunctionCallStub()];
|
|
|
|
constructor(type: FunctionBodyType) {
|
|
this.bodyType = type;
|
|
}
|
|
|
|
public get body(): ISharedFunctionBody {
|
|
return {
|
|
type: this.bodyType,
|
|
code: this.bodyType === FunctionBodyType.Code ? {
|
|
do: this.code,
|
|
revert: this.revertCode,
|
|
} : undefined,
|
|
calls: this.bodyType === FunctionBodyType.Calls ? this.calls : undefined,
|
|
};
|
|
}
|
|
|
|
public withName(name: string) {
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
|
|
public withCode(code: string) {
|
|
this.code = code;
|
|
return this;
|
|
}
|
|
|
|
public withRevertCode(revertCode: string) {
|
|
this.revertCode = revertCode;
|
|
return this;
|
|
}
|
|
|
|
public withParameters(parameters: IReadOnlyFunctionParameterCollection) {
|
|
this.parameters = parameters;
|
|
return this;
|
|
}
|
|
|
|
public withCalls(...calls: readonly IFunctionCall[]) {
|
|
this.calls = [...calls];
|
|
return this;
|
|
}
|
|
|
|
public withParameterNames(...parameterNames: readonly string[]) {
|
|
let collection = new FunctionParameterCollectionStub();
|
|
for (const name of parameterNames) {
|
|
collection = collection.withParameterName(name);
|
|
}
|
|
return this.withParameters(collection);
|
|
}
|
|
}
|