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

feat(cli): parser arg for CLI #2721

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
adddcd9
Suggested implementation of parser arg
rudfoss-rr Nov 6, 2024
13d28d5
Updated docs
rudfoss-rr Nov 6, 2024
29d31cb
chore(deps): update simple-eval usage (#2724)
mnaumanali94 Nov 12, 2024
d662832
chore(release): 1.8.0 [skip ci]
StoplightSupport Nov 12, 2024
3aae7f0
chore(release): 1.11.0 [skip ci]
StoplightSupport Nov 12, 2024
d998609
chore(release): 1.21.0 [skip ci]
StoplightSupport Nov 12, 2024
0a9890f
chore(repo): make windows resource class large
mnaumanali94 Nov 12, 2024
8376bfd
chore(repo): fix circle ci config
mnaumanali94 Nov 12, 2024
77219d4
chore(repo): fix circle ci config
mnaumanali94 Nov 12, 2024
049d0e0
chore(repo): fix circle ci config
mnaumanali94 Nov 12, 2024
0a5377f
fix(core): require new formats version (#2725)
mnaumanali94 Nov 12, 2024
7a22964
chore(deps): fix lock file
mnaumanali94 Nov 12, 2024
d7b2f11
chore(release): 1.19.2 [skip ci]
StoplightSupport Nov 12, 2024
439d0a7
feat(cli): require new stoplight dependencies (#2726)
mnaumanali94 Nov 12, 2024
b57a221
chore(release): 6.14.0 [skip ci]
StoplightSupport Nov 12, 2024
6c5cd66
chore(repo): change go get to go install
mnaumanali94 Nov 12, 2024
45800fe
chore(repo): change go image [skip ci]
mnaumanali94 Nov 12, 2024
df513ee
fix(formats): update spectral core version
mnaumanali94 Nov 12, 2024
028753b
fix(formatters): update spectral core to latest version
mnaumanali94 Nov 12, 2024
9f547d1
fix(functions): update spectral core to latest
mnaumanali94 Nov 12, 2024
bf145ef
fix(rulesets): update spectral core to latest
mnaumanali94 Nov 12, 2024
726fb09
fix(repo): update yarn lock
mnaumanali94 Nov 12, 2024
2c36b6d
chore(release): 1.8.1 [skip ci]
StoplightSupport Nov 12, 2024
dc46473
chore(release): 1.4.1 [skip ci]
StoplightSupport Nov 12, 2024
27f7fca
chore(release): 1.9.1 [skip ci]
StoplightSupport Nov 12, 2024
0a9a419
chore(release): 1.21.1 [skip ci]
StoplightSupport Nov 12, 2024
845d1b0
chore(deps): fix dependabot alerts
mnaumanali94 Nov 13, 2024
e75daa1
chore(deps): update spectral deps
mnaumanali94 Nov 13, 2024
64fa439
chore(core): update core deps
mnaumanali94 Nov 13, 2024
af14665
chore(cli): update dependencies in cli
mnaumanali94 Nov 13, 2024
3b47de5
fix(cli): update dependencies and trigger docker release
mnaumanali94 Nov 13, 2024
2198d59
chore(release): 1.8.2 [skip ci]
StoplightSupport Nov 13, 2024
aa54a5d
chore(release): 6.14.1 [skip ci]
StoplightSupport Nov 13, 2024
5c4bbea
chore(release): 1.19.3 [skip ci]
StoplightSupport Nov 13, 2024
b5cbdd3
chore(release): 1.4.2 [skip ci]
StoplightSupport Nov 13, 2024
ecfc60d
chore(release): 1.9.2 [skip ci]
StoplightSupport Nov 13, 2024
88d45a9
chore(release): 1.0.5 [skip ci]
StoplightSupport Nov 13, 2024
023fc6b
chore(release): 1.0.5 [skip ci]
StoplightSupport Nov 13, 2024
6603358
chore(release): 1.6.1 [skip ci]
StoplightSupport Nov 13, 2024
c7a33cd
chore(release): 1.11.1 [skip ci]
StoplightSupport Nov 13, 2024
51cb8ad
chore(release): 1.21.2 [skip ci]
StoplightSupport Nov 13, 2024
5526ea1
chore(release): 1.1.3 [skip ci]
StoplightSupport Nov 13, 2024
1c9c719
chore(cli): fix type issues
rudfoss-rr Nov 15, 2024
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defaults:
only: /^v.*/
node-versions: &node-versions
- &node-maintenance-lts "16.20"
- &node-active-lts "18.20"
- &node-active-lts "18.18"
- &node-current "20.17"
pkg-cache-path: &pkg-cache-path /tmp/pkg-node-binaries
ldid-version: &ldid-version 2.1.5-procursus7 # https://github.com/ProcursusTeam/ldid
Expand Down Expand Up @@ -290,6 +290,7 @@ jobs:
test-windows:
executor:
name: windows/default
size: large
steps:
- checkout
- cached-dependencies:
Expand Down Expand Up @@ -340,7 +341,6 @@ jobs:
steps:
- checkout
- setup_remote_docker:
version: 20.10.2
docker_layer_caching: true
- run:
name: set version in package.json
Expand Down Expand Up @@ -406,13 +406,13 @@ jobs:

upload-artifacts:
docker:
- image: circleci/golang:1-stretch
- image: cimg/go:1.23
steps:
- attach_workspace:
at: /tmp/
- run:
name: "Download GitHub Release Utility"
command: go get github.com/tcnksm/ghr
command: go install github.com/tcnksm/ghr@latest
- run:
name: "Publish Release artifacts on GitHub"
command: ghr -t ${GH_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} /tmp/binaries
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/2-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ Other options include:
--fail-on-unmatched-globs fail on unmatched glob patterns [boolean] [default: false]
-v, --verbose increase verbosity [boolean]
-q, --quiet no logging - output only [boolean]
-p, --parser specify the parser used to read the file ["Json", "Yaml"]
```

The Spectral CLI supports loading documents as YAML or JSON, and validation of OpenAPI v2/v3 documents via the built-in ruleset.
The Spectral CLI supports loading documents as YAML or JSON, and validation of OpenAPI v2/v3 documents via the built-in ruleset. The default parser reads YAML files, when loading JSON documents you should specify `--parser Json`.

## Using a Ruleset File

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"license": "Apache-2.0",
"engines": {
"node": "^12.20 || >= 14.13"
"node": "^16.20 || ^18.18 || >= 20.17"
},
"scripts": {
"preclean": "yarn workspaces foreach run preclean",
Expand Down Expand Up @@ -78,6 +78,9 @@
"@semantic-release/git"
]
},
"resolutions": {
"jsep": "1.4.0"
},
"devDependencies": {
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^12.1.4",
Expand All @@ -89,7 +92,7 @@
"@semantic-release/npm": "^9.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
"@swc/core": "^1.2.210",
"@swc/jest": "^0.2.36",
"@swc/jest": "^0.2.37",
"@types/file-entry-cache": "^5.0.2",
"@types/jest": "^29.5.13",
"@types/karma": "^6.3.3",
Expand All @@ -111,7 +114,7 @@
"husky": "^7.0.4",
"jest": "^29.7.0",
"jest-mock": "^29.7.0",
"karma": "^6.4.0",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.1.1",
"karma-jasmine": "^5.1.0",
"karma-typescript": "^5.5.3",
Expand All @@ -125,7 +128,7 @@
"semantic-release": "^19.0.5",
"ts-jest": "^29.2.5",
"ts-node": "^10.8.2",
"typescript": "^4.4.4"
"typescript": "4.4.4"
},
"lint-staged": {
"*.{ts,js}": [
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## @stoplight/spectral-cli [6.14.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.14.0...@stoplight/spectral-cli-6.14.1) (2024-11-13)


### Bug Fixes

* **cli:** update dependencies and trigger docker release ([c87eacf](https://github.com/stoplightio/spectral/commit/c87eacff7c6d97ec139cc66623e4b0b27158a0cc))

# @stoplight/spectral-cli [6.14.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.13.1...@stoplight/spectral-cli-6.14.0) (2024-11-12)


### Features

* **cli:** require new stoplight dependencies ([#2726](https://github.com/stoplightio/spectral/issues/2726)) ([8a736b5](https://github.com/stoplightio/spectral/commit/8a736b557a441e578c498df5af4cf5313c6dc2d5))

## @stoplight/spectral-cli [6.13.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-6.13.0...@stoplight/spectral-cli-6.13.1) (2024-09-21)


Expand Down
22 changes: 11 additions & 11 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@stoplight/spectral-cli",
"version": "6.13.1",
"version": "6.14.1",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <support@stoplight.io>",
"bin": {
"spectral": "./dist/index.js"
},
"engines": {
"node": "^12.20 || >= 14.13"
"node": "^16.20 || ^18.18 || >= 20.17"
},
"license": "Apache-2.0",
"main": "dist/index.js",
Expand Down Expand Up @@ -36,29 +36,29 @@
"dependencies": {
"@stoplight/json": "~3.21.0",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-formatters": "^1.3.0",
"@stoplight/spectral-parsers": "^1.0.3",
"@stoplight/spectral-core": "^1.19.2",
"@stoplight/spectral-formatters": "^1.4.1",
"@stoplight/spectral-parsers": "^1.0.4",
"@stoplight/spectral-ref-resolver": "^1.0.4",
"@stoplight/spectral-ruleset-bundler": "^1.5.4",
"@stoplight/spectral-ruleset-migrator": "^1.9.6",
"@stoplight/spectral-ruleset-bundler": "^1.6.0",
"@stoplight/spectral-ruleset-migrator": "^1.11.0",
"@stoplight/spectral-rulesets": ">=1",
"@stoplight/spectral-runtime": "^1.1.2",
"@stoplight/types": "^13.6.0",
"chalk": "4.1.2",
"fast-glob": "~3.2.12",
"hpagent": "~1.2.0",
"lodash": "~4.17.21",
"pony-cause": "^1.0.0",
"stacktracey": "^2.1.7",
"tslib": "^2.3.0",
"pony-cause": "^1.1.1",
"stacktracey": "^2.1.8",
"tslib": "^2.8.1",
"yargs": "~17.7.2"
},
"devDependencies": {
"@types/es-aggregate-error": "^1.0.2",
"@types/xml2js": "^0.4.9",
"@types/yargs": "^17.0.8",
"@yao-pkg/pkg": "^5.11.1",
"@yao-pkg/pkg": "5.11.0",
"es-aggregate-error": "^1.0.7",
"nock": "^13.5.4",
"xml2js": "^0.5.0"
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ const lintCommand: CommandModule = {
description: 'no logging - output only',
type: 'boolean',
},
parser: {
alias: 'p',
description: 'specify the parser used to read the file',
choices: ["Json", "Yaml"],
default: 'Yaml',
type: 'string',
}
}),

async handler(args) {
Expand All @@ -175,6 +182,7 @@ const lintCommand: CommandModule = {
encoding,
ignoreUnknownFormat,
failOnUnmatchedGlobs,
parser,
...config
} = args as unknown as ILintConfig & {
documents: Array<number | string>;
Expand All @@ -191,6 +199,7 @@ const lintCommand: CommandModule = {
failOnUnmatchedGlobs,
ruleset,
stdinFilepath,
parser,
...pick<Partial<ILintConfig>, keyof ILintConfig>(config, ['verbose', 'quiet', 'resolver']),
});

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/services/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dictionary } from '@stoplight/types';
import { HumanReadableDiagnosticSeverity } from '@stoplight/spectral-core';
import * as Parsers from "@stoplight/spectral-parsers"

export type FailSeverity = HumanReadableDiagnosticSeverity;

Expand Down Expand Up @@ -29,4 +30,5 @@ export interface ILintConfig {
failOnUnmatchedGlobs: boolean;
verbose?: boolean;
quiet?: boolean;
parser?: keyof Pick<typeof Parsers, "Yaml" | "Json">
}
17 changes: 15 additions & 2 deletions packages/cli/src/services/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function lint(documents: Array<number | string>, flags: ILintConfig
console.info(`Linting ${targetUri}`);
}

const document = await createDocument(targetUri, { encoding: flags.encoding }, flags.stdinFilepath ?? '<STDIN>');
const document = await createDocument(targetUri, { encoding: flags.encoding }, flags.stdinFilepath ?? '<STDIN>', flags.parser);

results.push(
...(await spectral.run(document, {
Expand All @@ -63,7 +63,20 @@ const createDocument = async (
identifier: string | number,
opts: IFileReadOptions,
source: string,
): Promise<Document<unknown, Parsers.YamlParserResult<unknown>>> => {
parser: ILintConfig["parser"] = "Yaml"
) => {
// I wanted to dynamically assign the parser using something like this:
// const parserImplementation = Parsers[parser]
// but I got a type-error on new Document() that I was unable to resolve dynamically (not sure why)

if (parser === "Json") {
if (typeof identifier === 'string') {
return new Document(await readParsable(identifier, opts), Parsers.Json, identifier);
}

return new Document(await readFileDescriptor(identifier, opts), Parsers.Json, source);
}

if (typeof identifier === 'string') {
return new Document(await readParsable(identifier, opts), Parsers.Yaml, identifier);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## @stoplight/spectral-core [1.19.3](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-1.19.2...@stoplight/spectral-core-1.19.3) (2024-11-13)


### Bug Fixes

* **cli:** update dependencies and trigger docker release ([c87eacf](https://github.com/stoplightio/spectral/commit/c87eacff7c6d97ec139cc66623e4b0b27158a0cc))

## @stoplight/spectral-core [1.19.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-1.19.1...@stoplight/spectral-core-1.19.2) (2024-11-12)


### Bug Fixes

* **core:** require new formats version ([#2725](https://github.com/stoplightio/spectral/issues/2725)) ([8ec328f](https://github.com/stoplightio/spectral/commit/8ec328fe68e42519cea1d6afedc4eb309a2c121c))

## @stoplight/spectral-core [1.19.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-1.19.0...@stoplight/spectral-core-1.19.1) (2024-09-13)


Expand Down
14 changes: 7 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-core",
"version": "1.19.1",
"version": "1.19.3",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand Down Expand Up @@ -31,15 +31,15 @@
}
},
"engines": {
"node": "^12.20 || >= 14.13"
"node": "^16.20 || ^18.18 || >= 20.17"
},
"dependencies": {
"@stoplight/better-ajv-errors": "1.0.3",
"@stoplight/json": "~3.21.0",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-parsers": "^1.0.0",
"@stoplight/spectral-ref-resolver": "^1.0.4",
"@stoplight/spectral-runtime": "^1.0.0",
"@stoplight/spectral-runtime": "^1.1.2",
"@stoplight/types": "~13.6.0",
"@types/es-aggregate-error": "^1.0.2",
"@types/json-schema": "^7.0.11",
Expand All @@ -52,12 +52,12 @@
"lodash.topath": "^4.5.2",
"minimatch": "3.1.2",
"nimma": "0.2.3",
"pony-cause": "^1.0.0",
"simple-eval": "1.0.0",
"tslib": "^2.3.0"
"pony-cause": "^1.1.1",
"simple-eval": "1.0.1",
"tslib": "^2.8.1"
},
"devDependencies": {
"@stoplight/spectral-formats": "^1.7.0",
"@stoplight/spectral-formats": "^1.8.1",
"@stoplight/spectral-functions": "*",
"@stoplight/spectral-parsers": "*",
"@stoplight/yaml": "^4.2.2",
Expand Down
21 changes: 21 additions & 0 deletions packages/formats/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## @stoplight/spectral-formats [1.8.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formats-1.8.1...@stoplight/spectral-formats-1.8.2) (2024-11-13)


### Bug Fixes

* **cli:** update dependencies and trigger docker release ([c87eacf](https://github.com/stoplightio/spectral/commit/c87eacff7c6d97ec139cc66623e4b0b27158a0cc))

## @stoplight/spectral-formats [1.8.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formats-1.8.0...@stoplight/spectral-formats-1.8.1) (2024-11-12)


### Bug Fixes

* **formats:** update spectral core version ([6b196da](https://github.com/stoplightio/spectral/commit/6b196dac0a91f433aaf8cff3bbf889f23c31b0ab))

# @stoplight/spectral-formats [1.8.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formats-1.7.0...@stoplight/spectral-formats-1.8.0) (2024-11-12)


### Features

* **rulesets:** add AsyncAPI v3 support ([#2697](https://github.com/stoplightio/spectral/issues/2697)) ([3d69be7](https://github.com/stoplightio/spectral/commit/3d69be7058e8f25f0697b69fd8317a2aefe313c1))

# @stoplight/spectral-formats [1.7.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formats-1.6.0...@stoplight/spectral-formats-1.7.0) (2024-09-12)


Expand Down
8 changes: 4 additions & 4 deletions packages/formats/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-formats",
"version": "1.7.0",
"version": "1.8.2",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand All @@ -16,12 +16,12 @@
],
"types": "dist/index.d.ts",
"engines": {
"node": ">=12"
"node": "^16.20 || ^18.18 || >= 20.17"
},
"dependencies": {
"@stoplight/json": "^3.17.0",
"@stoplight/spectral-core": "^1.8.0",
"@stoplight/spectral-core": "^1.19.2",
"@types/json-schema": "^7.0.7",
"tslib": "^2.3.1"
"tslib": "^2.8.1"
}
}
14 changes: 14 additions & 0 deletions packages/formatters/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## @stoplight/spectral-formatters [1.4.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formatters-1.4.1...@stoplight/spectral-formatters-1.4.2) (2024-11-13)


### Bug Fixes

* **cli:** update dependencies and trigger docker release ([c87eacf](https://github.com/stoplightio/spectral/commit/c87eacff7c6d97ec139cc66623e4b0b27158a0cc))

## @stoplight/spectral-formatters [1.4.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formatters-1.4.0...@stoplight/spectral-formatters-1.4.1) (2024-11-12)


### Bug Fixes

* **formatters:** update spectral core to latest version ([8a382f4](https://github.com/stoplightio/spectral/commit/8a382f4c40cdd2089e3404668c30552300be94eb))

# @stoplight/spectral-formatters [1.4.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-formatters-1.3.0...@stoplight/spectral-formatters-1.4.0) (2024-09-13)


Expand Down
Loading