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

Adds a YAML eslint linter. #312

Merged
merged 6 commits into from
Jun 7, 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
2 changes: 1 addition & 1 deletion .github/opensearch-cluster/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ services:
- "9200:9200"
- "9600:9600"
environment:
- "discovery.type=single-node"
- discovery.type=single-node
- "OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD:-myStrongPassword123!}"
4 changes: 1 addition & 3 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Check Links

on:
push:
pull_request:
on: [push, pull_request]

jobs:
check:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

concurrency:
group: "pages"
group: pages
cancel-in-progress: false

permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
COMMENT_IDENTIFIER=$(jq -r '.comment_identifier' ./pr-comment.json)
TEMPLATE_NAME=$(jq -r '.template_name' ./pr-comment.json)
TEMPLATE_DATA=$(jq -c '.template_data' ./pr-comment.json)

vars=(
PR_NUMBER
COMMENT_IDENTIFIER
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: Test Spec

on:
push:
branches: [ '**' ]
paths:
- 'package*.json'
- 'tsconfig.json'
- 'tools/src/tester/**'
- 'spec/**'
branches: ['**']
paths:
- 'package*.json'
- tsconfig.json
- 'tools/src/tester/**'
- 'spec/**'
pull_request:
branches: [ '**' ]
paths:
- 'package*.json'
- 'tsconfig.json'
- 'tools/src/tester/**'
- 'spec/**'
branches: ['**']
paths:
- 'package*.json'
- tsconfig.json
- 'tools/src/tester/**'
- 'spec/**'

jobs:
test-opensearch-spec:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/test-tools-integ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ on:
branches: ['**']
paths:
- 'package*.json'
- 'eslint.config.mjs'
- 'jest.config.js'
- 'tsconfig.json'
- eslint.config.mjs
- jest.config.js
- tsconfig.json
- 'tools/**'
- '.github/workflows/test-tools*.yml'
pull_request:
branches: ['**']
paths:
- 'package*.json'
- 'eslint.config.mjs'
- 'jest.config.js'
- 'tsconfig.json'
- eslint.config.mjs
- jest.config.js
- tsconfig.json
- 'tools/**'
- '.github/workflows/test-tools*.yml'

Expand Down Expand Up @@ -52,4 +52,4 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added `npm run test:spec -- --dry-run --verbose` ([#303](https://github.com/opensearch-project/opensearch-api-specification/pull/303))
- Added `npm run test:unit` and `test:integ` ([#320](https://github.com/opensearch-project/opensearch-api-specification/pull/320))
- Added code coverage to tools' tests ([#323](https://github.com/opensearch-project/opensearch-api-specification/pull/323))

- Added a YAML linter ([#312](https://github.com/opensearch-project/opensearch-api-specification/pull/312))

### Changed

- Replaced Smithy with a native OpenAPI spec ([#189](https://github.com/opensearch-project/opensearch-api-specification/issues/189))
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ The test suite contains unit tests and integration tests. Integration tests, suc

#### Lints

All code is linted using [ESLint](https://eslint.org/) in combination with [typescript-eslint](https://typescript-eslint.io/). Linting can be run via:
All TypeScript code and YAML files are linted using [ESLint](https://eslint.org/), [typescript-eslint](https://typescript-eslint.io/), and [eslint-plugin-yml](https://ota-meshi.github.io/eslint-plugin-yml/). Linting can be run via:
```bash
npm run lint
```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ See [CLIENT_GENERATOR_GUIDE](CLIENT_GENERATOR_GUIDE.md).

OpenSearch API Specs are hosted at https://opensearch-project.github.io/opensearch-api-specification/. See [PUBLISHING_SPECS](PUBLISHING_SPECS.md) for more information.

Click [here](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main/opensearch-openapi.yaml) to download the latest OpenSearch OpenAPI yaml file.
Click [here](https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml) to download the latest OpenSearch OpenAPI yaml file.


## Security
Expand Down
48 changes: 39 additions & 9 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import path from 'path'
import { fileURLToPath } from 'url'
import { FlatCompat } from '@eslint/eslintrc'
import pluginJs from '@eslint/js'
import pluginTs from '@typescript-eslint/eslint-plugin'
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'

// mimic CommonJS variables -- not needed if using CommonJS
const _filename = fileURLToPath(import.meta.url)
const _dirname = path.dirname(_filename)
const compat = new FlatCompat({ baseDirectory: _dirname, recommendedConfig: pluginJs.configs.recommended })

export default [
pluginJs.configs.recommended,
...compat.extends('standard-with-typescript'),
{
files: ['**/*.{js,ts}'],
languageOptions: {
parser: parserTs,
parserOptions: {
project: './tsconfig.json'
},
globals: {
...globals.jest,
...globals.node,
},
},
plugins: {
'@typescript-eslint': pluginTs,
'license-header': licenseHeader
},
rules: {
...pluginJs.configs.recommended.rules,
...pluginTs.configs["recommended-type-checked"].rules,
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
Expand Down Expand Up @@ -58,6 +72,7 @@ export default [
'new-cap': 'off',
'no-return-assign': 'error',
'object-shorthand': 'error',
'no-constant-condition': 'off',
'license-header/header': [
'error',
[
Expand All @@ -72,5 +87,20 @@ export default [
]
]
}
},
...eslintPluginYml.configs['flat/standard'],
{
files: ["**/*.yaml", "**/*.yml"],
languageOptions: {
parser: parserYml
},
plugins: {
yml: eslintPluginYml
},
rules: {
'yml/no-empty-document': 'off',
'yml/quotes': 'off',
'yml/plain-scalar': 'off'
}
}
]
16 changes: 8 additions & 8 deletions json_schemas/test_story.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ properties:
items:
$ref: '#/definitions/Chapter'
minItems: 1
required: [ description, chapters]
required: [description, chapters]
additionalProperties: false

definitions:
Expand All @@ -37,7 +37,7 @@ definitions:
description: A brief description of the chapter.
response:
$ref: '#/definitions/ExpectedResponse'
required: [ synopsis ]
required: [synopsis]
additionalProperties: false

ReadChapter:
Expand All @@ -47,7 +47,7 @@ definitions:
properties:
response:
$ref: '#/definitions/ActualResponse'
required: [ response ]
required: [response]
additionalProperties: false

SupplementalChapter:
Expand All @@ -70,14 +70,14 @@ definitions:
type: string
method:
type: string
enum: [ GET, PUT, POST, DELETE, PATCH, HEAD, OPTIONS ]
enum: [GET, PUT, POST, DELETE, PATCH, HEAD, OPTIONS]
parameters:
type: object
additionalProperties:
$ref: '#/definitions/Parameter'
request_body:
$ref: '#/definitions/RequestBody'
required: [ path, method ]
required: [path, method]
additionalProperties: false


Expand All @@ -89,7 +89,7 @@ definitions:
default: application/json
payload:
$ref: '#/definitions/Payload'
required: [ payload ]
required: [payload]
additionalProperties: false

ExpectedResponse:
Expand All @@ -104,7 +104,7 @@ definitions:
default: application/json
payload:
$ref: '#/definitions/Payload'
required: [ status ]
required: [status]
additionalProperties: false

ActualResponse:
Expand All @@ -122,7 +122,7 @@ definitions:
error:
type: object
description: Error object.
required: [ status, content_type, payload ]
required: [status, content_type, payload]
additionalProperties: false

Payload:
Expand Down
40 changes: 40 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint-plugin-license-header": "^0.6.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-yml": "^1.14.0",
"globals": "^15.0.0",
"jest": "^29.7.0",
"json-schema-to-typescript": "^14.0.4",
Expand Down
Loading
Loading