Skip to content

Commit

Permalink
Added eslint-plugin-eslint-comments. (#333)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Jun 11, 2024
1 parent 9ece89b commit ababab0
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 79 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added a YAML linter ([#312](https://github.com/opensearch-project/opensearch-api-specification/pull/312))
- Added linter to validate order of spec operations ([#325](https://github.com/opensearch-project/opensearch-api-specification/pull/326)) ([#326](https://github.com/opensearch-project/opensearch-api-specification/pull/326))
- Added support to read outputs from requests in tests([#324](https://github.com/opensearch-project/opensearch-api-specification/pull/324))

- Added `eslint-plugin-eslint-comments` ([#333](https://github.com/opensearch-project/opensearch-api-specification/pull/333))

### Changed

- Replaced Smithy with a native OpenAPI spec ([#189](https://github.com/opensearch-project/opensearch-api-specification/issues/189))
Expand Down
21 changes: 12 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pluginJs from '@eslint/js'
import pluginTs from '@typescript-eslint/eslint-plugin'
import globals from 'globals'
import parserTs from '@typescript-eslint/parser'
import eslintPluginYml from 'eslint-plugin-yml'
import parserYml from "yaml-eslint-parser"
import globals from 'globals'
import licenseHeader from 'eslint-plugin-license-header'
import pluginComments from 'eslint-plugin-eslint-comments'
import pluginJs from '@eslint/js'
import pluginLicenseHeader from 'eslint-plugin-license-header'
import pluginTs from '@typescript-eslint/eslint-plugin'
import pluginYml from 'eslint-plugin-yml'

export default [
pluginJs.configs.recommended,
Expand All @@ -22,10 +23,12 @@ export default [
},
plugins: {
'@typescript-eslint': pluginTs,
'license-header': licenseHeader
'license-header': pluginLicenseHeader,
'eslint-comments': pluginComments
},
rules: {
...pluginJs.configs.recommended.rules,
...pluginComments.configs.recommended.rules,
...pluginTs.configs["recommended-type-checked"].rules,
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-explicit-any': 'off',
Expand Down Expand Up @@ -85,17 +88,17 @@ export default [
'* compatible open source license.',
'*/'
]
]
],
}
},
...eslintPluginYml.configs['flat/standard'],
...pluginYml.configs['flat/standard'],
{
files: ["**/*.yaml", "**/*.yml"],
languageOptions: {
parser: parserYml
},
plugins: {
yml: eslintPluginYml
yml: pluginYml
},
rules: {
'yml/no-empty-document': 'off',
Expand Down
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"coverage:spec": "ts-node tools/src/coverage/coverage.ts",
"dump-cluster-spec": "ts-node tools/src/dump-cluster-spec/dump-cluster-spec.ts",
"lint:spec": "ts-node tools/src/linter/lint.ts",
"lint": "eslint .",
"lint--fix": "eslint . --fix",
"lint": "eslint . --report-unused-disable-directives",
"lint--fix": "eslint . --fix --report-unused-disable-directives",
"merge": "ts-node tools/src/merger/merge.ts",
"test": "npm run test:unit && npm run test:integ",
"jest": "jest",
Expand Down Expand Up @@ -38,6 +38,7 @@
"@typescript-eslint/eslint-plugin": "^6.21.0",
"eslint": "^8.57.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-license-header": "^0.6.1",
"eslint-plugin-n": "^16.6.2",
Expand Down
1 change: 0 additions & 1 deletion tools/src/tester/OperationLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default class OperationLocator {
if (operation == null) return undefined
this.#deref(operation)
const parameters = _.keyBy(operation.parameters ?? [], 'name')
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
this.cached_operations[cache_key] = { ...operation, parameters } as ParsedOperation
return this.cached_operations[cache_key]
}
Expand Down
2 changes: 1 addition & 1 deletion tools/src/tester/StoryOutputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* compatible open source license.
*/

import { type ChapterOutput } from './ChapterOutput'
import { ChapterOutput } from './ChapterOutput'
import { OutputReference } from './types/eval.types'
import { type Parameter } from './types/story.types'

Expand Down
35 changes: 25 additions & 10 deletions tools/src/tester/_generate_story_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,30 @@ void js2ts.compile(schema, 'Story',
singleQuote: true,
singleAttributePerLine: true
},
// multiline comment
bannerComment: `/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file by running:
* "npx ts-node tools/src/tester/_generate_story_types.ts" in a terminal.
*/`
bannerComment: `/*
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file by running:
* "npx ts-node tools/src/tester/_generate_story_types.ts" in a terminal.
*/
`
})
.then(ts => {
fs.writeFileSync('tools/src/tester/types/story.types.ts', `/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
`
+ ts + `
/* eslint-enable @typescript-eslint/ban-types */
/* eslint-enable @typescript-eslint/consistent-indexed-object-style */
`)
})
.then(ts => { fs.writeFileSync('tools/src/tester/types/story.types.ts', ts) })
17 changes: 15 additions & 2 deletions tools/src/tester/types/story.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/* eslint-disable */
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/**
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */

/*
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file by running:
Expand Down Expand Up @@ -129,3 +139,6 @@ export interface ActualResponse {
*/
error?: {};
}

/* eslint-enable @typescript-eslint/ban-types */
/* eslint-enable @typescript-eslint/consistent-indexed-object-style */
2 changes: 1 addition & 1 deletion tools/tests/linter/factories/namespace_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function mocked_namespace_file (ops: { returned_values?: MockedReturnedVa

// eslint-disable-next-line @typescript-eslint/dot-notation
if (ops.groups_errors) ns_file['_operation_groups'] = ops.groups_errors.map((errors) => mocked_operation_group({ validate: errors }))
// eslint-disable-next-line @typescript-eslint/dot-notation,@typescript-eslint/consistent-type-assertions
// eslint-disable-next-line @typescript-eslint/dot-notation
if (ops.spec) ns_file['_spec'] = { paths: {}, components: {}, ...ops.spec } as OpenAPIV3.Document

if (ops.returned_values) {
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 {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const op: Operation = new Operation('', '', '', {} as OperationSpec)

if (returned_values.validate) {
Expand Down
4 changes: 2 additions & 2 deletions tools/tests/tester/start.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 {
}
}

/* eslint-disable no-template-curly-in-string */
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)
})
/* eslint-enable no-template-curly-in-string */

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

Expand Down
92 changes: 43 additions & 49 deletions tools/tests/tester/story_outputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,55 @@ import { ChapterOutput } from 'tester/ChapterOutput'
import { StoryOutputs } from 'tester/StoryOutputs'

const story_outputs = new StoryOutputs({
chapter_id: new ChapterOutput({
x: 1,
y: 2
})
chapter_id: new ChapterOutput({
x: 1,
y: 2
})

/* eslint-disable no-template-curly-in-string */
test('resolve_string', () => {
expect(story_outputs.resolve_string('${chapter_id.x}')).toEqual(1)
expect(story_outputs.resolve_string('some_str')).toEqual('some_str')
})
/* eslint-enable no-template-curly-in-string */

test('resolve_value', () => {
/* eslint-disable no-template-curly-in-string */
const value = {
a: '${chapter_id.x}',
b: ['${chapter_id.x}', '${chapter_id.y}', 3],
})

test('resolve_string', () => {
expect(story_outputs.resolve_string('${chapter_id.x}')).toEqual(1)
expect(story_outputs.resolve_string('some_str')).toEqual('some_str')
})

test('resolve_value', () => {
const value = {
a: '${chapter_id.x}',
b: ['${chapter_id.x}', '${chapter_id.y}', 3],
c: {
d: '${chapter_id.x}',
e: 'str',
f: true
},
g: 123
}
expect(story_outputs.resolve_value(value)).toEqual(
{
a: 1,
b: [1, 2, 3],
c: {
d: '${chapter_id.x}',
d: 1,
e: 'str',
f: true
},
g: 123
}
/* eslint-enable no-template-curly-in-string */
expect(story_outputs.resolve_value(value)).toEqual(
{
a: 1,
b: [1, 2, 3],
c: {
d: 1,
e: 'str',
f: true
},
g: 123
}
)
})

test('resolve_params', () => {
/* eslint-disable no-template-curly-in-string */
const parameters = {
a: '${chapter_id.x}',
b: '${chapter_id.y}',
c: 3,
d: 'str'
}
/* eslint-enable no-template-curly-in-string */
)
})

test('resolve_params', () => {
const parameters = {
a: '${chapter_id.x}',
b: '${chapter_id.y}',
c: 3,
d: 'str'
}
expect(story_outputs.resolve_params(parameters)).toEqual({
a: 1,
b: 2,
c: 3,
d: 'str'
})
a: 1,
b: 2,
c: 3,
d: 'str'
})


})


0 comments on commit ababab0

Please sign in to comment.