Skip to content

Commit

Permalink
Merge pull request askui#733 from askui/add_eslint_rule_sort-keys
Browse files Browse the repository at this point in the history
refactor: introduce sort-keys ESLint rule
  • Loading branch information
JohannesDienst-askui authored Mar 20, 2024
2 parents 5035f42 + 8ee026f commit abd3087
Show file tree
Hide file tree
Showing 26 changed files with 232 additions and 265 deletions.
35 changes: 18 additions & 17 deletions packages/askui-nodejs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
module.exports = {
root: true,
env: {
node: true,
es2021: true,
node: true,
},
extends: [
'airbnb-base',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
curly: 'error',
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
'key-spacing': ['error', { beforeColon: false, afterColon: true }],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
extends: [
'plugin:@typescript-eslint/recommended',
'airbnb-typescript/base',
],
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['./tsconfig.json'],
createDefaultProgram: true,
project: ['./tsconfig.json'],
},
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
Expand All @@ -38,4 +24,19 @@ module.exports = {
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
root: true,
rules: {
curly: 'error',
'import/no-default-export': 'error',
'import/prefer-default-export': 'off',
'key-spacing': ['error', { afterColon: true, beforeColon: false }],
'no-underscore-dangle': ['error', { allowAfterThis: true }],
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: 3, natural: false }],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: '@askui/jest-allure-circus',
setupFilesAfterEnv: ['./helpers/askui-helper.ts'],
sandboxInjectedGlobals: [
'Math',
],
setupFilesAfterEnv: ['./helpers/askui-helper.ts'],
testEnvironment: '@askui/jest-allure-circus',
};

// eslint-disable-next-line import/no-default-export
Expand Down
8 changes: 4 additions & 4 deletions packages/askui-nodejs/src/core/model/custom-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ describe('CustomElement', () => {
);
const actual = await CustomElement.fromJsonWithImagePathOrImage({
customImage: base64ImageString,
name: 'Dummy_element',
threshold: 0.7,
rotationDegreePerStep: 10,
imageCompareFormat: 'RGB',
mask: [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 3, y: 4 }],
name: 'Dummy_element',
rotationDegreePerStep: 10,
threshold: 0.7,
});
expect(actual).toStrictEqual(expected);
});
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('CustomElement', () => {
[{ x: 0, y: 1 }, { x: 1, y: 2 }],
);
customElement.validate();
}).toThrow('threshold must be less than or equal to 1, mask must contain at least 3 points');
}).toThrow('mask must contain at least 3 points, threshold must be less than or equal to 1');
});
});
});
4 changes: 2 additions & 2 deletions packages/askui-nodejs/src/core/model/custom-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { CustomElementJson } from './custom-element-json';

export class CustomElement implements CustomElementJson {
private static schema = object({
threshold: number().optional().min(0).max(1),
rotationDegreePerStep: number().optional().min(0).lessThan(360),
mask: array().optional().min(3, 'mask must contain at least 3 points'),
rotationDegreePerStep: number().optional().min(0).lessThan(360),
threshold: number().optional().min(0).max(1),
});

constructor(
Expand Down
6 changes: 3 additions & 3 deletions packages/askui-nodejs/src/core/reporting/default-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export class DefaultStep implements Step {
onEnd(snapshot: Snapshot, error?: Error): DefaultStep {
this.runs = [...this.runs.slice(0, -1), {
...this.lastRun,
status: DefaultStep.determineLastRunStatus(error),
end: snapshot,
error,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
duration: snapshot.createdAt.getTime() - this.lastRun!.begin!.createdAt.getTime(),
end: snapshot,
error,
status: DefaultStep.determineLastRunStatus(error),
}];
return cloneDeep(this);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/askui-nodejs/src/core/reporting/step-reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ describe('StepReporter', () => {
};

reporter0 = {
config: {},
onStepBegin: jest.fn(),
onStepEnd: jest.fn(),
config: {},
};

reporter1 = {
onStepBegin: jest.fn((_currentStep: Step) => {
throw error;
}),
onStepEnd: jest.fn(),
config: {
withScreenshots: 'required',
withDetectedElements: 'begin',
},
onStepBegin: jest.fn((_currentStep: Step) => {
throw error;
}),
onStepEnd: jest.fn(),
};

reporter2 = {
onStepBegin: jest.fn(),
onStepEnd: jest.fn(),
config: {
withScreenshots: 'always',
withDetectedElements: 'always',
},
onStepBegin: jest.fn(),
onStepEnd: jest.fn(),
};
});

Expand Down
2 changes: 1 addition & 1 deletion packages/askui-nodejs/src/execution/execution-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ export class ExecutionRuntime {
const annotation = this.isAnnotationRequired() ? await this.annotateImage() : undefined;
return {
createdAt,
screenshot,
detectedElements: annotation?.detected_elements,
screenshot,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/askui-nodejs/src/execution/inference-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ export class InferenceClient {
const response = await this.httpClient.post<InferenceResponseBody>(
this.urls.inference,
{
customElements,
image: resizedImage.base64Image,
instruction,
customElements,
modelComposition: this.modelComposition,
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export class UiControlClientDependencyBuilder {
): Promise<ClientArgsWithDefaults> {
return {
...clientArgs,
uiControllerUrl: clientArgs.uiControllerUrl ?? 'http://127.0.0.1:6769',
credentials: readCredentials(clientArgs),
inferenceServerUrl:
clientArgs.inferenceServerUrl ?? 'https://inference.askui.com',
credentials: readCredentials(clientArgs),
proxyAgents: clientArgs.proxyAgents ?? (await envProxyAgents()),
uiControllerUrl: clientArgs.uiControllerUrl ?? 'http://127.0.0.1:6769',
};
}
}
2 changes: 1 addition & 1 deletion packages/askui-nodejs/src/execution/ui-control-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export class UiControlClient extends ApiCommands {
): Promise<Instruction> {
return {
customElements: await CustomElement.fromJsonListWithImagePathOrImage(customElementJson),
value: instructionString,
secretText: this.getAndResetSecretText(),
value: instructionString,
valueHumanReadable: this.escapeSeparatorString(instructionString),
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/askui-nodejs/src/lib/download-binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { getPathToNodeModulesRoot } from '../utils/path';
import { logger } from './logger';

enum SupportedPlatform {
LINUX = 'linux',
DARWIN = 'darwin',
LINUX = 'linux',
WIN32 = 'win32',
}

const binarySubPathsByPlatform = {
linux: ['linux', 'askui-ui-controller.AppImage'],
darwin: ['darwin', 'askui-ui-controller.dmg'],
linux: ['linux', 'askui-ui-controller.AppImage'],
win32: ['windows', 'askui-ui-controller.exe'],
} as const;

Expand Down
16 changes: 9 additions & 7 deletions packages/askui-nodejs/src/lib/interactive_cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CliOptions } from './cli-options-interface';

const nonEmpty = (subject: string) => (input: string) => input.trim().length > 0 || `${subject} is required.`;

/* eslint-disable sort-keys */
const questions = [
{
type: 'list',
Expand Down Expand Up @@ -36,34 +37,35 @@ const questions = [
when: (_answers: CliOptions) => fs.existsSync('tsconfig.json'),
},
];
/* eslint-enable */

const options = [
{
option: '-f, --test-framework <value>',
choices: ['jest'],
description: 'the test framework to use.',
default: 'jest',
description: 'the test framework to use.',
option: '-f, --test-framework <value>',
},
{
option: '-sc, --skip-credentials',
choices: [],
description: 'skip the credentials setup.',
default: false,
description: 'skip the credentials setup.',
option: '-sc, --skip-credentials',
},
{
option: '-w, --workspace-id <value>',
choices: [],
description: 'a workspace id.',
option: '-w, --workspace-id <value>',
},
{
option: '-a, --access-token <value>',
choices: [],
description: 'an access token for the workspace with the id.',
option: '-a, --access-token <value>',
},
{
option: '-t, --typescript-config',
choices: [],
description: 'overwrite tsconfig.json flag',
option: '-t, --typescript-config',
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class CreateExampleProject {
private async addUserCredentials() {
return [
{
/* eslint-disable sort-keys */
title: 'Add user credentials',
enabled: () => !this.cliOptions.skipCredentials,
task: async () => {
Expand All @@ -209,6 +210,7 @@ export class CreateExampleProject {
},`;
},
},
/* eslint-enable */
];
}

Expand Down Expand Up @@ -245,6 +247,7 @@ export class CreateExampleProject {
'tsconfig.json',
);
const tsConfigTargetFilePath = path.join(this.baseDirPath, 'tsconfig.json');
/* eslint-disable sort-keys */
return [
{
title: 'Copy ts config file',
Expand All @@ -256,6 +259,7 @@ export class CreateExampleProject {
},
];
}
/* eslint-enable */

public async createExampleProject(): Promise<void> {
const tasks = new Listr();
Expand Down
6 changes: 3 additions & 3 deletions packages/askui-nodejs/src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ function isProcessEnvLogLevelValid(): boolean {
}
const stream = pretty({
colorize: true,
translateTime: 'SYS:standard',
ignore: 'pid,hostname,filename',
translateTime: 'SYS:standard',
});
const defaultLogLevel = 'info';
const pinoLevel: string = isProcessEnvLogLevelValid() ? process.env['LOG_LEVEL'] as string : defaultLogLevel;
const logger = pino(
{
name: 'askuiUiControlClient',
level: pinoLevel,
customLevels: {
verbose: 5,
},
level: pinoLevel,
name: 'askuiUiControlClient',
},
stream,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/askui-nodejs/src/lib/ui-controller-args.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('createCliFlagsFromArgs()', () => {

test('test createCliFlagsFromArgs output should include the display that was selected ', () => {
const expected = ['-d 99', '-p 6777', '--action_wait_time 1000', '--host 0.0.0.0', '-m ', '--log-level debug'];
const argsWithDefaults = createArgsWithDefaults({ port: 6777, host: '0.0.0.0', display: 99 });
const argsWithDefaults = createArgsWithDefaults({ display: 99, host: '0.0.0.0', port: 6777 });
const actual = createCliFlagsFromArgs(argsWithDefaults);
expect(actual).toStrictEqual(expected);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/askui-nodejs/src/lib/ui-controller-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import { LogLevels } from '../shared/log-levels';
*/

export interface UiControllerArgs {
readonly display?: number;
readonly actionDelayInMs?: number;
readonly binaryVersion?: string,
readonly port?: number;
readonly display?: number;
readonly host?: string;
readonly port?: number;
readonly minimize?: boolean;
readonly overWriteBinary?: boolean;
readonly logLevel?: LogLevels;
Expand All @@ -46,9 +46,9 @@ export interface UiControllerArgs {
}

export interface UiControllerArgsWithDefaults extends UiControllerArgs {
readonly display: number;
readonly actionDelayInMs: number;
readonly binaryVersion: string;
readonly display: number;
readonly overWriteBinary: boolean;
readonly port: number;
readonly host: string;
Expand All @@ -59,14 +59,14 @@ export function createArgsWithDefaults(
args?: UiControllerArgs,
): UiControllerArgsWithDefaults {
const defaults = {
actionDelayInMs: 1000,
binaryVersion: 'latest',
display: 0,
actionDelayInMs: 1000,
overWriteBinary: false,
minimize: true,
port: 6769,
host: '127.0.0.1',
logLevel: 'debug',
minimize: true,
overWriteBinary: false,
port: 6769,
};
return Object.assign(defaults, args);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/askui-nodejs/src/lib/ui-controller-facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export abstract class UiControllerFacade {
? maxWaitingForStartingInSeconds * 1000 : this.DefaultmaxWaitingForStartingInMs;
waitPort({
host: args.host,
output: process?.env['LOG_LEVEL'] === 'verbose' ? 'dots' : 'silent',
port: args.port,
timeout: timeoutInMs,
output: process?.env['LOG_LEVEL'] === 'verbose' ? 'dots' : 'silent',
}).then((open: boolean) => {
if (open) {
logger.info('The Control UI Server has been started.');
Expand Down
Loading

0 comments on commit abd3087

Please sign in to comment.