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:
@@ -1,35 +1,43 @@
|
||||
import { ExpressionPosition } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionPosition';
|
||||
import { IExpression } from '@/application/Parser/Script/Compiler/Expressions/Expression/IExpression';
|
||||
import { IReadOnlyFunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/IFunctionParameterCollection';
|
||||
import { FunctionParameterCollectionStub } from './FunctionParameterCollectionStub';
|
||||
import { IExpressionEvaluationContext } from '@/application/Parser/Script/Compiler/Expressions/Expression/ExpressionEvaluationContext';
|
||||
import { FunctionParameterCollectionStub } from './FunctionParameterCollectionStub';
|
||||
|
||||
export class ExpressionStub implements IExpression {
|
||||
public callHistory = new Array<IExpressionEvaluationContext>();
|
||||
public position = new ExpressionPosition(0, 5);
|
||||
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub();
|
||||
private result: string;
|
||||
public withParameters(parameters: IReadOnlyFunctionParameterCollection) {
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
}
|
||||
public withParameterNames(parameterNames: readonly string[], isOptional = false) {
|
||||
const collection = new FunctionParameterCollectionStub()
|
||||
.withParameterNames(parameterNames, isOptional);
|
||||
return this.withParameters(collection);
|
||||
}
|
||||
public withPosition(start: number, end: number) {
|
||||
this.position = new ExpressionPosition(start, end);
|
||||
return this;
|
||||
}
|
||||
public withEvaluatedResult(result: string) {
|
||||
this.result = result;
|
||||
return this;
|
||||
}
|
||||
public evaluate(context: IExpressionEvaluationContext): string {
|
||||
const args = context.args;
|
||||
this.callHistory.push(context);
|
||||
const result = this.result || `[expression-stub] args: ${args ? Object.keys(args).map((key) => `${key}: ${args[key]}`).join('", "') : 'none'}`;
|
||||
return result;
|
||||
}
|
||||
public callHistory = new Array<IExpressionEvaluationContext>();
|
||||
|
||||
public position = new ExpressionPosition(0, 5);
|
||||
|
||||
public parameters: IReadOnlyFunctionParameterCollection = new FunctionParameterCollectionStub();
|
||||
|
||||
private result: string;
|
||||
|
||||
public withParameters(parameters: IReadOnlyFunctionParameterCollection) {
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withParameterNames(parameterNames: readonly string[], isOptional = false) {
|
||||
const collection = new FunctionParameterCollectionStub()
|
||||
.withParameterNames(parameterNames, isOptional);
|
||||
return this.withParameters(collection);
|
||||
}
|
||||
|
||||
public withPosition(start: number, end: number) {
|
||||
this.position = new ExpressionPosition(start, end);
|
||||
return this;
|
||||
}
|
||||
|
||||
public withEvaluatedResult(result: string) {
|
||||
this.result = result;
|
||||
return this;
|
||||
}
|
||||
|
||||
public evaluate(context: IExpressionEvaluationContext): string {
|
||||
const { args } = context;
|
||||
this.callHistory.push(context);
|
||||
const result = this.result || `[expression-stub] args: ${args ? Object.keys(args).map((key) => `${key}: ${args[key]}`).join('", "') : 'none'}`;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user