Skip to content

Commit 61a10f4

Browse files
authored
Adds tools linter. (#260)
Signed-off-by: dblock <[email protected]>
1 parent 9d99398 commit 61a10f4

File tree

8 files changed

+3426
-477
lines changed

8 files changed

+3426
-477
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ jobs:
2424
with:
2525
node-version: 20.10.0
2626
- run: npm install
27-
- run: npm run lint -- ../spec
27+
- run: |
28+
npm run lint:spec -- ../spec

.github/workflows/tools.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jobs:
2323
node-version: 20.10.0
2424
- run: npm install
2525
- run: npm run test
26+
- run: npm run lint

DEVELOPER_GUIDE.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ spec
4545
4646
└── opensearch-openapi.yaml
4747
```
48+
4849
Every `.yaml` file is a valid OpenAPI 3 document. This means that you can use any OpenAPI 3 compatible tool to view and edit the files, and IDEs with OpenAPI support will provide you with autocompletion and validation in real-time.
4950

5051
## Grouping Operations
@@ -84,6 +85,14 @@ This repository includes several penAPI Specification Extensions to fill in any
8485
- `x-global`: Denotes that the parameter is a global parameter that is included in every operation. These parameters are listed in the [root file](spec/opensearch-openapi.yaml).
8586
- `x-default`: Contains the default value of a parameter. This is often used to override the default value specified in the schema, or to avoid accidentally changing the default value when updating a shared schema.
8687

87-
## Linting
88-
We have a linter that validates every `yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter](tools/README.md#linter) tool for more information on how to run it locally. Make sure to run the linter before submitting a PR.
88+
## Tools
89+
90+
We authored a number of tools to merge and lint specs that live in [tools](tools/). All tools have tests (run with `npm run test`) and a linter (run with `npm run lint`).
91+
92+
### Merger
93+
94+
The spec merger "builds", aka combines various `.yaml` files into a complete OpenAPI spec. A [workflow](./.github/workflows/build.yml) publishes the output into [releases](https://github.com/opensearch-project/opensearch-api-specification/releases).
95+
96+
### Linter
8997

98+
The spec linter that validates every `.yaml` file in the `./spec` folder to assure that they follow the guidelines we have set. Check out the [Linter README](tools/README.md#linter) for more information on how to run it locally. Make sure to run the linter before submitting a PR.

tools/README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
# OpenSearch OpenAPI Tools
2+
23
This folder contains tools for the repo:
3-
- Merger: merges multiple OpenAPI files into one
4-
- Linter: validates files in the spec folder
4+
5+
- [Merger](./merger/): merges multiple OpenAPI files into one
6+
- [Linter](./linter/): validates files in the spec folder
57

68
## Setup
9+
710
1. Install [Node.js](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs)
811
2. Run `npm install` in the `tools` folder
912

1013
## Merger
14+
1115
The merger tool merges the multi-file OpenSearch spec into a single file for programmatic use. It takes 2 parameters:
12-
- The path to the root folder of the multi-file spec
13-
- The path to the output file
16+
17+
- the path to the root folder of the multi-file spec
18+
- the path to the output file
19+
1420
Example:
21+
1522
```bash
1623
npm run merge -- ../spec ../build/opensearch-openapi.latest.yaml
1724
```
1825

1926
## Linter
27+
2028
The linter tool validates the OpenSearch spec files in the `spec` folder:
29+
2130
```bash
22-
npm run lint
31+
npm run lint:spec
2332
```
33+
2434
It will print out all the errors and warnings in the spec files. This tool in still in development, and it will be integrated into the CI/CD pipeline and run automatically with every PR.
25-
```

tools/eslint.config.mjs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import path from 'path'
2+
import { fileURLToPath } from 'url'
3+
import { FlatCompat } from '@eslint/eslintrc'
4+
import pluginJs from '@eslint/js'
5+
6+
// mimic CommonJS variables -- not needed if using CommonJS
7+
const _filename = fileURLToPath(import.meta.url)
8+
const _dirname = path.dirname(_filename)
9+
const compat = new FlatCompat({ baseDirectory: _dirname, recommendedConfig: pluginJs.configs.recommended })
10+
11+
export default [
12+
pluginJs.configs.recommended,
13+
...compat.extends('standard-with-typescript'),
14+
{
15+
files: ['**/*.{js,ts}'],
16+
ignores: [
17+
'**/eslint.config.mjs'
18+
],
19+
rules: {
20+
'@typescript-eslint/array-type': 'warn',
21+
'@typescript-eslint/block-spacing': 'warn',
22+
'@typescript-eslint/comma-dangle': 'warn',
23+
'@typescript-eslint/comma-spacing': 'warn',
24+
'@typescript-eslint/consistent-indexed-object-style': 'warn',
25+
'@typescript-eslint/consistent-type-assertions': 'warn',
26+
'@typescript-eslint/consistent-type-imports': 'warn',
27+
'@typescript-eslint/dot-notation': 'warn',
28+
'@typescript-eslint/explicit-function-return-type': 'warn',
29+
'@typescript-eslint/indent': 'warn',
30+
'@typescript-eslint/keyword-spacing': 'warn',
31+
'@typescript-eslint/lines-between-class-members': 'warn',
32+
'@typescript-eslint/member-delimiter-style': 'warn',
33+
'@typescript-eslint/naming-convention': 'warn',
34+
'@typescript-eslint/no-confusing-void-expression': 'warn',
35+
'@typescript-eslint/no-dynamic-delete': 'warn',
36+
'@typescript-eslint/no-invalid-void-type': 'warn',
37+
'@typescript-eslint/no-non-null-assertion': 'warn',
38+
'@typescript-eslint/no-unnecessary-type-assertion': 'warn',
39+
'@typescript-eslint/no-unsafe-argument': 'warn',
40+
'@typescript-eslint/no-unused-vars': 'warn',
41+
'@typescript-eslint/object-curly-spacing': 'warn',
42+
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
43+
'@typescript-eslint/quotes': 'warn',
44+
'@typescript-eslint/require-array-sort-compare': 'warn',
45+
'@typescript-eslint/semi': 'warn',
46+
'@typescript-eslint/space-before-blocks': 'warn',
47+
'@typescript-eslint/space-before-function-paren': 'warn',
48+
'@typescript-eslint/space-infix-ops': 'warn',
49+
'@typescript-eslint/strict-boolean-expressions': 'warn',
50+
'@typescript-eslint/type-annotation-spacing': 'warn',
51+
'array-bracket-spacing': 'warn',
52+
'array-callback-return': 'warn',
53+
curly: 'warn',
54+
'eol-last': 'warn',
55+
eqeqeq: 'warn',
56+
'new-cap': 'warn',
57+
'no-multi-spaces': 'warn',
58+
'no-multiple-empty-lines': 'warn',
59+
'no-return-assign': 'warn',
60+
'no-useless-return': 'warn',
61+
'object-curly-newline': 'warn',
62+
'object-property-newline': 'warn',
63+
'object-shorthand': 'warn',
64+
'quote-props': 'warn',
65+
'space-in-parens': 'warn'
66+
}
67+
}
68+
]

tools/jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
33
preset: 'ts-jest',
4-
testEnvironment: 'node',
5-
};
4+
testEnvironment: 'node'
5+
}

0 commit comments

Comments
 (0)