Skip to content

Commit

Permalink
WIP: Added YAML linter.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Jun 4, 2024
1 parent 0fcf9f7 commit cbb7186
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 16 deletions.
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
53 changes: 43 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import path from 'path'
import { fileURLToPath } from 'url'
import { FlatCompat } from '@eslint/eslintrc'
import pluginJs from '@eslint/js'

// 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 })
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'

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
},
rules: {
...pluginJs.configs.recommended.rules,
...pluginTs.configs["recommended-type-checked"].rules,
'@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/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unused-vars': ['error', { "argsIgnorePattern": "^_" }],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/dot-notation': 'error',
Expand Down Expand Up @@ -51,7 +69,22 @@ export default [
'array-callback-return': 'off',
'new-cap': 'off',
'no-return-assign': 'error',
'object-shorthand': 'error'
'object-shorthand': 'error',
'no-constant-condition': 'off'
},
},
...eslintPluginYml.configs['flat/recommended'],
{
files: ["**/*.yaml", "**/*.yml"],
ignores: ['*invalid*'],
languageOptions: {
parser: parserYml
},
plugins: {
yml: eslintPluginYml
},
rules: {
'yml/no-empty-document': 'off'
}
}
]
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 @@ -38,6 +38,7 @@
"eslint-plugin-import": "^2.29.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
4 changes: 2 additions & 2 deletions tools/src/merger/GlobalParamsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class GlobalParamsGenerator {
spec.components.parameters = { ...this.global_params, ...spec.components.parameters }

const global_param_refs = Object.keys(this.global_params).map(param => ({ $ref: `#/components/parameters/${param}` }))
Object.entries(spec.paths as Document).forEach(([path, path_item]) => {
Object.entries(path_item as Document).forEach(([method, operation]) => {
Object.entries(spec.paths as Document).forEach(([_path, path_item]) => {
Object.entries(path_item as Document).forEach(([_method, operation]) => {
const params = operation.parameters ?? []
operation.parameters = [...params, ...Object.values(global_param_refs)]
})
Expand Down
2 changes: 1 addition & 1 deletion tools/tests/linter/NamespacesFolder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('validate() - When there invalid files', () => {
message: "The 200 response must be a reference object to '#/components/responses/invalid_spec.fetch@200'."
},
{
file: 'invalid_files/invalid_yaml.yaml',
file: 'invalid_files/invalid_yaml.invalidyaml',
location: 'File Content',
message: 'Unable to read or parse YAML.'
}
Expand Down

0 comments on commit cbb7186

Please sign in to comment.