Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added eslint indent rules. #344

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ export default [
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'array-callback-return': 'off',
'indent': ['error', 2, { 'SwitchCase': 1 }],
'new-cap': 'off',
'no-constant-condition': 'off',
'no-return-assign': 'error',
'no-trailing-spaces': 'error',
'object-shorthand': 'error',
'no-constant-condition': 'off',
'space-in-parens': 'error',
'license-header/header': [
'error',
[
Expand Down
6 changes: 3 additions & 3 deletions tools/src/OpenSearchHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export class OpenSearchHttpClient {
baseURL: opts?.url ?? DEFAULT_URL,
auth: opts?.username !== undefined && opts.password !== undefined
? {
username: opts.username,
password: opts.password
}
username: opts.username,
password: opts.password
}
: undefined,
httpsAgent: new https.Agent({ rejectUnauthorized: !(opts?.insecure ?? DEFAULT_INSECURE) })
})
Expand Down
32 changes: 16 additions & 16 deletions tools/src/tester/StoryEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class StoryEvaluator {
chapters: []
}
}
const variables_error = StoryEvaluator.check_story_variables(story, display_path, full_path )
const variables_error = StoryEvaluator.check_story_variables(story, display_path, full_path)
if (variables_error !== undefined) {
return variables_error
}
Expand Down Expand Up @@ -96,7 +96,7 @@ export default class StoryEvaluator {
return { evaluations, has_errors }
}

static check_story_variables(story: Story, display_path: string, full_path: string ): StoryEvaluation | undefined {
static check_story_variables(story: Story, display_path: string, full_path: string): StoryEvaluation | undefined {
const story_outputs = new StoryOutputs()
const prologues = (story.prologues ?? []).map((prologue) => {
return StoryEvaluator.#check_episode_variables(prologue, story_outputs)
Expand Down Expand Up @@ -124,26 +124,26 @@ export default class StoryEvaluator {

static #check_episode_variables(episode: ChapterRequest, story_outputs: StoryOutputs): ChapterEvaluation {
const title = `${episode.method} ${episode.path}`
const error = StoryEvaluator.#check_used_variables(episode, story_outputs)
if (error !== undefined) {
return error
}
if (episode.id === undefined && episode.output !== undefined) {
return this.#failed_evaluation(title, 'An episode must have an id to store its output')
}
if (episode.id !== undefined && episode.output !== undefined) {
story_outputs.set_chapter_output(episode.id, new ChapterOutput(episode.output))
}
return { title, overall: { result: Result.PASSED } }
const error = StoryEvaluator.#check_used_variables(episode, story_outputs)
if (error !== undefined) {
return error
}
if (episode.id === undefined && episode.output !== undefined) {
return this.#failed_evaluation(title, 'An episode must have an id to store its output')
}
if (episode.id !== undefined && episode.output !== undefined) {
story_outputs.set_chapter_output(episode.id, new ChapterOutput(episode.output))
}
return { title, overall: { result: Result.PASSED } }
}

/**
*
*
* @param chapter ChapterEvaluation {
title: string
overall: Evaluation
* @param story_outputs
* @returns
* @param story_outputs
* @returns
*/
static #check_used_variables(chapter: ChapterRequest, story_outputs: StoryOutputs): ChapterEvaluation | undefined {
const variables = new Set<OutputReference>()
Expand Down
76 changes: 38 additions & 38 deletions tools/src/tester/SupplementalChapterEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ import { ChapterEvaluation, Result } from "./types/eval.types";
import { SupplementalChapter } from "./types/story.types";

export default class SupplementalChapterEvaluator {
private readonly _chapter_reader: ChapterReader;
private readonly _chapter_reader: ChapterReader;

constructor(chapter_reader: ChapterReader) {
this._chapter_reader = chapter_reader;
}
constructor(chapter_reader: ChapterReader) {
this._chapter_reader = chapter_reader;
}

async evaluate(chapter: SupplementalChapter, story_outputs: StoryOutputs): Promise<{ evaluation: ChapterEvaluation, evaluation_error: boolean }> {
const title = `${chapter.method} ${chapter.path}`
const response = await this._chapter_reader.read(chapter, story_outputs)
const status = chapter.status ?? [200, 201]
const output_values = ChapterOutput.extract_output_values(response, chapter.output)
let response_evaluation: ChapterEvaluation
const passed_evaluation = { title, overall: { result: Result.PASSED } }
if (status.includes(response.status)) {
response_evaluation = passed_evaluation
} else {
response_evaluation = { title, overall: { result: Result.ERROR, message: response.message, error: response.error as Error }, output_values }
}
if (output_values) {
response_evaluation.output_values = output_values
}
const result = overall_result([response_evaluation.overall].concat(output_values ? [output_values] : []))
if (result === Result.PASSED) {
return { evaluation: passed_evaluation, evaluation_error: false }
} else {
const message_segments = []
if (response_evaluation.overall.result === Result.ERROR) {
message_segments.push(`${response_evaluation.overall.message}`)
}
if (output_values !== undefined && output_values.result === Result.ERROR) {
message_segments.push(`${output_values.message}`)
}
const message = message_segments.join('\n')
const evaluation = {
title,
overall: { result: Result.ERROR, message, error: response.error as Error },
...(output_values ? { output_values } : {})
}
return { evaluation, evaluation_error: true }
}
async evaluate(chapter: SupplementalChapter, story_outputs: StoryOutputs): Promise<{ evaluation: ChapterEvaluation, evaluation_error: boolean }> {
const title = `${chapter.method} ${chapter.path}`
const response = await this._chapter_reader.read(chapter, story_outputs)
const status = chapter.status ?? [200, 201]
const output_values = ChapterOutput.extract_output_values(response, chapter.output)
let response_evaluation: ChapterEvaluation
const passed_evaluation = { title, overall: { result: Result.PASSED } }
if (status.includes(response.status)) {
response_evaluation = passed_evaluation
} else {
response_evaluation = { title, overall: { result: Result.ERROR, message: response.message, error: response.error as Error }, output_values }
}
if (output_values) {
response_evaluation.output_values = output_values
}
const result = overall_result([response_evaluation.overall].concat(output_values ? [output_values] : []))
if (result === Result.PASSED) {
return { evaluation: passed_evaluation, evaluation_error: false }
} else {
const message_segments = []
if (response_evaluation.overall.result === Result.ERROR) {
message_segments.push(`${response_evaluation.overall.message}`)
}
if (output_values !== undefined && output_values.result === Result.ERROR) {
message_segments.push(`${output_values.message}`)
}
const message = message_segments.join('\n')
const evaluation = {
title,
overall: { result: Result.ERROR, message, error: response.error as Error },
...(output_values ? { output_values } : {})
}
return { evaluation, evaluation_error: true }
}
}
}
24 changes: 12 additions & 12 deletions tools/tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import { sort_array_by_keys } from '../src/helpers'
describe('helpers', () => {
describe('sort_array_by_keys', () => {
test('sorts arrays of string', () => {
expect(sort_array_by_keys([])).toEqual([])
expect(sort_array_by_keys(['GET', 'POST'], ['GET', 'POST'])).toEqual(['GET', 'POST'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['DELETE', 'POST', 'GET'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET', 'DELETE'])
})
test('does not modify the original object', () => {
const arr = ['GET', 'POST']
expect(sort_array_by_keys(arr, ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(arr).toEqual(['GET', 'POST'] )
})
expect(sort_array_by_keys([])).toEqual([])
expect(sort_array_by_keys(['GET', 'POST'], ['GET', 'POST'])).toEqual(['GET', 'POST'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['GET', 'POST'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET'])
expect(sort_array_by_keys(['DELETE', 'POST', 'GET'], ['POST', 'GET', 'DELETE'])).toEqual(['POST', 'GET', 'DELETE'])
})

test('does not modify the original object', () => {
const arr = ['GET', 'POST']
expect(sort_array_by_keys(arr, ['POST', 'GET'])).toEqual(['POST', 'GET'])
expect(arr).toEqual(['GET', 'POST'])
})
})
})
36 changes: 18 additions & 18 deletions tools/tests/linter/SupersededOperationsFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ describe('validate()', () => {
file: 'superseded_operations/invalid_schema.yaml',
message: "File content does not match JSON schema found in './json_schemas/_superseded_operations.schema.yaml':\n " +
JSON.stringify([
{
"instancePath": "/~1hello~1world/operations/1",
"schemaPath": "#/patternProperties/%5E~1/properties/operations/items/enum",
"keyword": "enum",
"params": {
"allowedValues": [
"GET",
"POST",
"PUT",
"DELETE",
"HEAD",
"OPTIONS",
"PATCH"
]
},
"message": "must be equal to one of the allowed values"
}
], null, 2),
{
"instancePath": "/~1hello~1world/operations/1",
"schemaPath": "#/patternProperties/%5E~1/properties/operations/items/enum",
"keyword": "enum",
"params": {
"allowedValues": [
"GET",
"POST",
"PUT",
"DELETE",
"HEAD",
"OPTIONS",
"PATCH"
]
},
"message": "must be equal to one of the allowed values"
}
], null, 2),
},
])
})
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/linter/factories/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface MockedReturnedValues {
}

export function mocked_operation (returned_values: MockedReturnedValues): Operation {

const op: Operation = new Operation('', '', '', {} as OperationSpec)

if (returned_values.validate) {
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/linter/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const spec = (args: string[]): any => {
}

test('--help', () => {
const output = spec(['--help'])
const output = spec(['--help'])
expect(output.stderr).toEqual('')
expect(output.stdout).toContain('Usage: lint [options]')
})
22 changes: 11 additions & 11 deletions tools/tests/tester/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export function print_yaml (obj: any): void {
export function flatten_errors (evaluation: StoryEvaluation): StoryEvaluation {
const flatten = <T extends Evaluation | undefined>(e: T): T => (e !== undefined
? {
...e,
error: typeof e.error === 'object' ? e.error.message : e.error
}
...e,
error: typeof e.error === 'object' ? e.error.message : e.error
}
: undefined as T)

const flatten_chapters = <T extends ChapterEvaluation[] | undefined> (chapters: T): T => {
Expand All @@ -79,17 +79,17 @@ export function flatten_errors (evaluation: StoryEvaluation): StoryEvaluation {
overall: flatten(c.overall),
request: c.request !== undefined
? {
parameters: c.request.parameters !== undefined
? Object.fromEntries(Object.entries(c.request.parameters).map(([k, v]) => [k, flatten(v)]))
: undefined,
request_body: flatten(c.request.request_body)
}
parameters: c.request.parameters !== undefined
? Object.fromEntries(Object.entries(c.request.parameters).map(([k, v]) => [k, flatten(v)]))
: undefined,
request_body: flatten(c.request.request_body)
}
: undefined,
response: c.response !== undefined
? {
status: flatten(c.response.status),
payload: flatten(c.response.payload)
}
status: flatten(c.response.status),
payload: flatten(c.response.payload)
}
: undefined
})) as T
}
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/tester/story_outputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('resolve_value', () => {
},
g: 123
}
expect(story_outputs.resolve_value(value)).toEqual(
expect(story_outputs.resolve_value(value)).toEqual(
{
a: 1,
b: [1, 2, 3],
Expand All @@ -55,7 +55,7 @@ test('resolve_params', () => {
c: 3,
d: 'str'
}
expect(story_outputs.resolve_params(parameters)).toEqual({
expect(story_outputs.resolve_params(parameters)).toEqual({
a: 1,
b: 2,
c: 3,
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/tester/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function chapter(synopsis: string, request: ChapterRequest): Chapter {
}
}


test('check_story_variables', () => {
const check_story_variables = (s: Story): StoryEvaluation | undefined => StoryEvaluator.check_story_variables(s, 'display_path', 'full_path')
const failed = (prologues: ChapterEvaluation[] = [], chapters: ChapterEvaluation[] = []): StoryEvaluation => ({
Expand Down Expand Up @@ -193,7 +193,7 @@ test('check_story_variables', () => {
]
})).toStrictEqual(undefined)
})


test.todo('--tab-width')

Expand Down
Loading