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,56 +1,67 @@
|
||||
import {
|
||||
CategoryData, ScriptData, CollectionData, ScriptingDefinitionData, FunctionData,
|
||||
} from 'js-yaml-loader!@/*';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { CategoryData, ScriptData, CollectionData, ScriptingDefinitionData, FunctionData } from 'js-yaml-loader!@/*';
|
||||
|
||||
export class CollectionDataStub implements CollectionData {
|
||||
public os = 'windows';
|
||||
public actions: readonly CategoryData[] = [ getCategoryStub() ];
|
||||
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
|
||||
public functions?: ReadonlyArray<FunctionData>;
|
||||
public os = 'windows';
|
||||
|
||||
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
public withOs(os: string): CollectionDataStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
public withFunctions(functions: ReadonlyArray<FunctionData>) {
|
||||
this.functions = functions;
|
||||
return this;
|
||||
}
|
||||
public actions: readonly CategoryData[] = [getCategoryStub()];
|
||||
|
||||
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
|
||||
|
||||
public functions?: ReadonlyArray<FunctionData>;
|
||||
|
||||
public withActions(actions: readonly CategoryData[]): CollectionDataStub {
|
||||
this.actions = actions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withOs(os: string): CollectionDataStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withScripting(scripting: ScriptingDefinitionData): CollectionDataStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
|
||||
public withFunctions(functions: ReadonlyArray<FunctionData>) {
|
||||
this.functions = functions;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export function getCategoryStub(scriptPrefix = 'testScript'): CategoryData {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [
|
||||
getScriptStub(`${scriptPrefix}-standard`, RecommendationLevel.Standard),
|
||||
getScriptStub(`${scriptPrefix}-strict`, RecommendationLevel.Strict),
|
||||
],
|
||||
};
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [
|
||||
getScriptStub(`${scriptPrefix}-standard`, RecommendationLevel.Standard),
|
||||
getScriptStub(`${scriptPrefix}-strict`, RecommendationLevel.Strict),
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function getTestDefinitionStub(): ScriptingDefinitionData {
|
||||
return {
|
||||
fileExtension: '.bat',
|
||||
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
||||
startCode: 'start',
|
||||
endCode: 'end',
|
||||
};
|
||||
return {
|
||||
fileExtension: '.bat',
|
||||
language: ScriptingLanguage[ScriptingLanguage.batchfile],
|
||||
startCode: 'start',
|
||||
endCode: 'end',
|
||||
};
|
||||
}
|
||||
|
||||
function getScriptStub(scriptName: string, level: RecommendationLevel = RecommendationLevel.Standard): ScriptData {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: RecommendationLevel[level].toLowerCase(),
|
||||
call: undefined,
|
||||
};
|
||||
function getScriptStub(
|
||||
scriptName: string,
|
||||
level: RecommendationLevel = RecommendationLevel.Standard,
|
||||
): ScriptData {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: RecommendationLevel[level].toLowerCase(),
|
||||
call: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user