@openlint/openlint-cli 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +71 -2
- package/dist/commands/lint.d.ts +6 -0
- package/dist/commands/lint.js +272 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +7 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/services/config.d.ts +30 -0
- package/dist/services/config.js +19 -0
- package/dist/services/config.js.map +1 -0
- package/dist/services/linter/index.d.ts +1 -0
- package/dist/services/linter/index.js +5 -0
- package/dist/services/linter/index.js.map +1 -0
- package/dist/services/linter/linter.d.ts +7 -0
- package/dist/services/linter/linter.js +57 -0
- package/dist/services/linter/linter.js.map +1 -0
- package/dist/services/linter/utils/getResolver.d.ts +3 -0
- package/dist/services/linter/utils/getResolver.js +24 -0
- package/dist/services/linter/utils/getResolver.js.map +1 -0
- package/dist/services/linter/utils/getRuleset.d.ts +3 -0
- package/dist/services/linter/utils/getRuleset.js +115 -0
- package/dist/services/linter/utils/getRuleset.js.map +1 -0
- package/dist/services/linter/utils/index.d.ts +4 -0
- package/dist/services/linter/utils/index.js +8 -0
- package/dist/services/linter/utils/index.js.map +1 -0
- package/dist/services/linter/utils/listFiles.d.ts +1 -0
- package/dist/services/linter/utils/listFiles.js +44 -0
- package/dist/services/linter/utils/listFiles.js.map +1 -0
- package/dist/services/linter/utils/readFileDescriptor.d.ts +2 -0
- package/dist/services/linter/utils/readFileDescriptor.js +23 -0
- package/dist/services/linter/utils/readFileDescriptor.js.map +1 -0
- package/dist/services/linter/utils/segregateEntriesPerKind.d.ts +1 -0
- package/dist/services/linter/utils/segregateEntriesPerKind.js +15 -0
- package/dist/services/linter/utils/segregateEntriesPerKind.js.map +1 -0
- package/dist/services/output.d.ts +5 -0
- package/dist/services/output.js +45 -0
- package/dist/services/output.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +78 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2018 Stoplight, Inc.
|
|
179
|
+
Copyright 2026 OpenLint
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OpenLint CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
- **Custom Rulesets**: Create custom rules to lint JSON or YAML objects
|
|
4
|
+
- **Ready-to-use Rulesets**: Validate and lint **OpenAPI v3.x & v2.x**, **AsyncAPI**, and **Arazzo v1** Documents
|
|
5
|
+
- **JSON Path Support**: Use JSON path to apply rules to specific parts of your objects
|
|
6
|
+
- **Ready-to-use Functions**: Built-in set of functions to help create custom rules. Functions include pattern checks, parameter checks, alphabetical ordering, a specified number of characters, provided keys are present in an object, etc.
|
|
7
|
+
- **Custom Functions**: Create custom functions for advanced use cases
|
|
8
|
+
- **JSON Validation**: Validate JSON with [Ajv](https://www.npmjs.com/package/ajv)
|
|
9
|
+
|
|
10
|
+
# Overview
|
|
11
|
+
|
|
12
|
+
- [OpenLint CLI](#openlint-cli)
|
|
13
|
+
- [Overview](#overview)
|
|
14
|
+
- [🧰 Installation and Usage](#-installation-and-usage)
|
|
15
|
+
- [📖 Documentation and Community](#-documentation-and-community)
|
|
16
|
+
- [ℹ️ Support](#ℹ️-support)
|
|
17
|
+
- [🏁 Help Others Utilize OpenLint](#-help-others-utilize-openlint)
|
|
18
|
+
- [👏 Contributing](#-contributing)
|
|
19
|
+
- [🎉 Thanks](#-thanks)
|
|
20
|
+
- [📜 License](#-license)
|
|
21
|
+
|
|
22
|
+
## 🧰 Installation and Usage
|
|
23
|
+
|
|
24
|
+
**Install**
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @openlint/openlint-cli
|
|
28
|
+
|
|
29
|
+
# OR
|
|
30
|
+
|
|
31
|
+
yarn global add @openlint/openlint-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Find more [installation methods](https://docs.openlint.org/getting-started/installation) in our documentation.
|
|
35
|
+
|
|
36
|
+
**Lint**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
spectral lint petstore.yaml
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 📖 Documentation and Community
|
|
43
|
+
|
|
44
|
+
Currently the documentation is in `./docs` as we work to get a website together.
|
|
45
|
+
|
|
46
|
+
## ℹ️ Support
|
|
47
|
+
|
|
48
|
+
If you need help using Spectral or have a support question, please use [GitHub Discussions](https://github.com/opemlint/openlint/discussions). It's also a great place to share your rulesets, or tools that leverage Spectral.
|
|
49
|
+
|
|
50
|
+
If you have a bug or feature request, please [create an issue](https://github.com/opemlint/openlint/issues).
|
|
51
|
+
|
|
52
|
+
## 🏁 Help Others Utilize OpenLint
|
|
53
|
+
|
|
54
|
+
If you're using OpenLint for an interesting use case, create an issue with details on how you're using it. We'll add it to a list here. Spread the goodness 🎉
|
|
55
|
+
|
|
56
|
+
## 👏 Contributing
|
|
57
|
+
|
|
58
|
+
If you are interested in contributing to OpenLint, check out [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
59
|
+
|
|
60
|
+
## 🎉 Thanks
|
|
61
|
+
|
|
62
|
+
- [Stoplight.io](https://github.com/stoplightio) for creating, managing, and growing Spectral for years.
|
|
63
|
+
- [Mike Ralphson](https://github.com/MikeRalphson) for kicking off the Spectral CLI and his work on Speccy
|
|
64
|
+
- [Jamund Ferguson](https://github.com/xjamundx) for JUnit formatter
|
|
65
|
+
- [Sindre Sorhus](https://github.com/sindresorhus) for Stylish formatter
|
|
66
|
+
- [Ava Thorn](https://github.com/amthorn) for the Pretty formatter
|
|
67
|
+
- Julian Laval for HTML formatter
|
|
68
|
+
- [@nulltoken](https://github.com/nulltoken) for a whole bunch of amazing features
|
|
69
|
+
|
|
70
|
+
## 📜 License
|
|
71
|
+
|
|
72
|
+
Spectral is 100% free and open-source, under [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IRuleResult } from '@openlint/openlint-core';
|
|
2
|
+
import type { CommandModule } from 'yargs';
|
|
3
|
+
import { FailSeverity } from '../services/config';
|
|
4
|
+
declare const lintCommand: CommandModule;
|
|
5
|
+
export declare const severeEnoughToFail: (results: IRuleResult[], failSeverity: FailSeverity) => boolean;
|
|
6
|
+
export default lintCommand;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.severeEnoughToFail = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const types_1 = require("@stoplight/types");
|
|
6
|
+
const json_1 = require("@stoplight/json");
|
|
7
|
+
const openlint_core_1 = require("@openlint/openlint-core");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const process = tslib_1.__importStar(require("process"));
|
|
10
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
+
const stacktracey_1 = tslib_1.__importDefault(require("stacktracey"));
|
|
12
|
+
const linter_1 = require("../services/linter");
|
|
13
|
+
const output_1 = require("../services/output");
|
|
14
|
+
const config_1 = require("../services/config");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const formatOptions = Object.values(config_1.OutputFormat);
|
|
17
|
+
const lintCommand = {
|
|
18
|
+
describe: 'lint JSON/YAML documents from files or URLs',
|
|
19
|
+
command: 'lint [documents..]',
|
|
20
|
+
builder: yargs => yargs
|
|
21
|
+
.strict()
|
|
22
|
+
.positional('documents', {
|
|
23
|
+
description: 'Location of JSON/YAML documents. Can be either a file, a glob or fetchable resource(s) on the web.',
|
|
24
|
+
coerce(values) {
|
|
25
|
+
if (Array.isArray(values) && values.length > 0) {
|
|
26
|
+
return values;
|
|
27
|
+
}
|
|
28
|
+
if (process.stdin.isTTY) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return [process.stdin.fd];
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
.middleware((argv) => {
|
|
35
|
+
const formats = argv.format;
|
|
36
|
+
if (argv.output === void 0) {
|
|
37
|
+
argv.output = { [formats[0]]: '<stdout>' };
|
|
38
|
+
}
|
|
39
|
+
else if (typeof argv.output === 'string') {
|
|
40
|
+
argv.output = { [formats[0]]: argv.output };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const output = argv.output;
|
|
44
|
+
if (Object.keys(output).length >= formats.length) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const firstMissingFormat = formats.find(f => !(f in output));
|
|
48
|
+
if (firstMissingFormat !== void 0) {
|
|
49
|
+
output[firstMissingFormat] = '<stdout>';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
.check((argv) => {
|
|
54
|
+
if (!Array.isArray(argv.documents) || argv.documents.length === 0) {
|
|
55
|
+
throw new errors_1.CLIError('No documents provided.');
|
|
56
|
+
}
|
|
57
|
+
const format = argv.format;
|
|
58
|
+
const output = argv.output;
|
|
59
|
+
if (format.length === 1) {
|
|
60
|
+
if (output === void 0 || Object.keys(output).length === 1) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
throw new errors_1.CLIError('Output must be either string or unspecified when a single format is specified');
|
|
64
|
+
}
|
|
65
|
+
if (!(0, json_1.isPlainObject)(output)) {
|
|
66
|
+
throw new errors_1.CLIError('Multiple outputs have to be provided when more than a single format is specified');
|
|
67
|
+
}
|
|
68
|
+
const keys = Object.keys(output);
|
|
69
|
+
if (format.length !== keys.length) {
|
|
70
|
+
throw new errors_1.CLIError('The number of outputs must match the number of formats');
|
|
71
|
+
}
|
|
72
|
+
const diff = (0, lodash_1.difference)(format, keys);
|
|
73
|
+
if (diff.length !== 0) {
|
|
74
|
+
throw new errors_1.CLIError(`Missing outputs for the following formats: ${diff.join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
})
|
|
78
|
+
.options({
|
|
79
|
+
encoding: {
|
|
80
|
+
alias: 'e',
|
|
81
|
+
description: 'text encoding to use',
|
|
82
|
+
type: 'string',
|
|
83
|
+
default: 'utf8',
|
|
84
|
+
choices: ['utf8', 'ascii', 'utf-8', 'utf16le', 'ucs2', 'ucs-2', 'base64', 'latin1'],
|
|
85
|
+
},
|
|
86
|
+
format: {
|
|
87
|
+
alias: 'f',
|
|
88
|
+
description: 'formatters to use for outputting results, more than one can be provided by using multiple flags',
|
|
89
|
+
choices: formatOptions,
|
|
90
|
+
default: config_1.OutputFormat.STYLISH,
|
|
91
|
+
type: 'string',
|
|
92
|
+
coerce(values) {
|
|
93
|
+
return Array.isArray(values) ? values : [values];
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
output: {
|
|
97
|
+
alias: 'o',
|
|
98
|
+
description: `where to output results, can be a single file name, multiple "output.<format>" or missing to print to stdout`,
|
|
99
|
+
type: 'string',
|
|
100
|
+
coerce(value) {
|
|
101
|
+
if (!(0, json_1.isPlainObject)(value))
|
|
102
|
+
return value;
|
|
103
|
+
const raw = value;
|
|
104
|
+
const normalized = {};
|
|
105
|
+
for (const format of formatOptions) {
|
|
106
|
+
if (format in raw) {
|
|
107
|
+
normalized[format] = raw[format];
|
|
108
|
+
}
|
|
109
|
+
else if ((0, lodash_1.camelCase)(format) in raw) {
|
|
110
|
+
normalized[format] = raw[(0, lodash_1.camelCase)(format)];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return normalized;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
'stdin-filepath': {
|
|
117
|
+
description: 'path to a file to pretend that stdin comes from',
|
|
118
|
+
type: 'string',
|
|
119
|
+
},
|
|
120
|
+
resolver: {
|
|
121
|
+
description: 'path to custom json-ref-resolver instance',
|
|
122
|
+
type: 'string',
|
|
123
|
+
},
|
|
124
|
+
ruleset: {
|
|
125
|
+
alias: 'r',
|
|
126
|
+
description: 'path/URL to a ruleset file',
|
|
127
|
+
type: 'string',
|
|
128
|
+
},
|
|
129
|
+
'fail-severity': {
|
|
130
|
+
alias: 'F',
|
|
131
|
+
description: 'results of this level or above will trigger a failure exit code',
|
|
132
|
+
choices: ['error', 'warn', 'info', 'hint'],
|
|
133
|
+
default: 'error',
|
|
134
|
+
type: 'string',
|
|
135
|
+
},
|
|
136
|
+
'display-only-failures': {
|
|
137
|
+
alias: 'D',
|
|
138
|
+
description: 'only output results equal to or greater than --fail-severity',
|
|
139
|
+
type: 'boolean',
|
|
140
|
+
default: false,
|
|
141
|
+
},
|
|
142
|
+
'ignore-unknown-format': {
|
|
143
|
+
description: 'do not warn about unmatched formats',
|
|
144
|
+
type: 'boolean',
|
|
145
|
+
default: false,
|
|
146
|
+
},
|
|
147
|
+
'fail-on-unmatched-globs': {
|
|
148
|
+
description: 'fail on unmatched glob patterns',
|
|
149
|
+
type: 'boolean',
|
|
150
|
+
default: false,
|
|
151
|
+
},
|
|
152
|
+
'show-documentation-url': {
|
|
153
|
+
description: 'show documentation url in output result',
|
|
154
|
+
type: 'boolean',
|
|
155
|
+
default: false,
|
|
156
|
+
},
|
|
157
|
+
verbose: {
|
|
158
|
+
alias: 'v',
|
|
159
|
+
description: 'increase verbosity',
|
|
160
|
+
type: 'boolean',
|
|
161
|
+
},
|
|
162
|
+
quiet: {
|
|
163
|
+
alias: 'q',
|
|
164
|
+
description: 'no logging - output only',
|
|
165
|
+
type: 'boolean',
|
|
166
|
+
},
|
|
167
|
+
}),
|
|
168
|
+
async handler(args) {
|
|
169
|
+
const { documents, failSeverity, displayOnlyFailures, ruleset, stdinFilepath, format, output, encoding, ignoreUnknownFormat, failOnUnmatchedGlobs, showDocumentationUrl, ...config } = args;
|
|
170
|
+
try {
|
|
171
|
+
const linterResult = await (0, linter_1.lint)(documents, {
|
|
172
|
+
format,
|
|
173
|
+
output,
|
|
174
|
+
encoding,
|
|
175
|
+
ignoreUnknownFormat,
|
|
176
|
+
failOnUnmatchedGlobs,
|
|
177
|
+
showDocumentationUrl,
|
|
178
|
+
ruleset,
|
|
179
|
+
stdinFilepath,
|
|
180
|
+
...(0, lodash_1.pick)(config, ['verbose', 'quiet', 'resolver']),
|
|
181
|
+
});
|
|
182
|
+
if (displayOnlyFailures) {
|
|
183
|
+
linterResult.results = filterResultsBySeverity(linterResult.results, failSeverity);
|
|
184
|
+
}
|
|
185
|
+
if (!showDocumentationUrl) {
|
|
186
|
+
linterResult.results = removeDocumentationUrlFromResults(linterResult.results);
|
|
187
|
+
}
|
|
188
|
+
await Promise.all(format.map(f => {
|
|
189
|
+
var _a;
|
|
190
|
+
const formattedOutput = (0, output_1.formatOutput)(linterResult.results, f, { failSeverity: (0, openlint_core_1.getDiagnosticSeverity)(failSeverity) }, linterResult.resolvedRuleset);
|
|
191
|
+
return (0, output_1.writeOutput)(formattedOutput, (_a = output === null || output === void 0 ? void 0 : output[f]) !== null && _a !== void 0 ? _a : '<stdout>');
|
|
192
|
+
}));
|
|
193
|
+
if (linterResult.results.length > 0) {
|
|
194
|
+
process.exit((0, exports.severeEnoughToFail)(linterResult.results, failSeverity) ? 1 : 0);
|
|
195
|
+
}
|
|
196
|
+
else if (config.quiet !== true) {
|
|
197
|
+
const isErrorSeverity = (0, openlint_core_1.getDiagnosticSeverity)(failSeverity) === types_1.DiagnosticSeverity.Error;
|
|
198
|
+
process.stdout.write(`No results with a severity of '${failSeverity}' ${isErrorSeverity ? '' : 'or higher '}found!\n`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (ex) {
|
|
202
|
+
fail((0, lodash_1.isError)(ex) ? ex : new Error(String(ex)), config.verbose === true);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
const fail = (error, verbose) => {
|
|
207
|
+
if (error instanceof errors_1.CLIError) {
|
|
208
|
+
process.stderr.write(chalk_1.default.red(error.message));
|
|
209
|
+
process.exit(2);
|
|
210
|
+
}
|
|
211
|
+
const errors = 'errors' in error ? error.errors : [error];
|
|
212
|
+
process.stderr.write(chalk_1.default.red('Error running OpenLint!\n'));
|
|
213
|
+
if (!verbose) {
|
|
214
|
+
process.stderr.write(chalk_1.default.red('Use --verbose flag to print the error stack.\n'));
|
|
215
|
+
}
|
|
216
|
+
for (const [i, error] of errors.entries()) {
|
|
217
|
+
const actualError = (0, lodash_1.isError)(error) && 'cause' in error ? error.cause : error;
|
|
218
|
+
const message = (0, lodash_1.isError)(actualError) ? actualError.message : String(actualError);
|
|
219
|
+
const location = formatErrorLocation(actualError);
|
|
220
|
+
const info = `Error #${i + 1}: `;
|
|
221
|
+
process.stderr.write(`${info}${location}${chalk_1.default.red(message)}\n`);
|
|
222
|
+
if (verbose && (0, lodash_1.isError)(actualError)) {
|
|
223
|
+
process.stderr.write(`${chalk_1.default.red(printErrorStacks(actualError, info.length))}\n`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
process.exit(2);
|
|
227
|
+
};
|
|
228
|
+
function formatErrorLocation(error) {
|
|
229
|
+
var _a;
|
|
230
|
+
if (typeof error !== 'object' || error === null)
|
|
231
|
+
return '';
|
|
232
|
+
const source = error.source;
|
|
233
|
+
if (typeof source !== 'string')
|
|
234
|
+
return '';
|
|
235
|
+
const range = error.range;
|
|
236
|
+
if (typeof ((_a = range === null || range === void 0 ? void 0 : range.start) === null || _a === void 0 ? void 0 : _a.line) === 'number' && typeof range.start.character === 'number') {
|
|
237
|
+
return `${source}:${range.start.line + 1}:${range.start.character + 1} — `;
|
|
238
|
+
}
|
|
239
|
+
return `${source} — `;
|
|
240
|
+
}
|
|
241
|
+
function getWidth(ratio) {
|
|
242
|
+
return Math.min(20, Math.floor(ratio * process.stderr.columns));
|
|
243
|
+
}
|
|
244
|
+
function printErrorStacks(error, padding) {
|
|
245
|
+
return new stacktracey_1.default(error)
|
|
246
|
+
.slice(0, 5)
|
|
247
|
+
.withSources()
|
|
248
|
+
.asTable({
|
|
249
|
+
maxColumnWidths: {
|
|
250
|
+
callee: getWidth(0.2),
|
|
251
|
+
file: getWidth(0.4),
|
|
252
|
+
sourceLine: getWidth(0.4),
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
.split('\n')
|
|
256
|
+
.map(error => `${' '.repeat(padding)}${error}`)
|
|
257
|
+
.join('\n');
|
|
258
|
+
}
|
|
259
|
+
const filterResultsBySeverity = (results, failSeverity) => {
|
|
260
|
+
const diagnosticSeverity = (0, openlint_core_1.getDiagnosticSeverity)(failSeverity);
|
|
261
|
+
return results.filter(r => r.severity <= diagnosticSeverity);
|
|
262
|
+
};
|
|
263
|
+
const removeDocumentationUrlFromResults = (results) => {
|
|
264
|
+
return results.map(r => ({ ...r, documentationUrl: undefined }));
|
|
265
|
+
};
|
|
266
|
+
const severeEnoughToFail = (results, failSeverity) => {
|
|
267
|
+
const diagnosticSeverity = (0, openlint_core_1.getDiagnosticSeverity)(failSeverity);
|
|
268
|
+
return results.some(r => r.severity <= diagnosticSeverity);
|
|
269
|
+
};
|
|
270
|
+
exports.severeEnoughToFail = severeEnoughToFail;
|
|
271
|
+
exports.default = lintCommand;
|
|
272
|
+
//# sourceMappingURL=lint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/commands/lint.ts"],"names":[],"mappings":";;;;AAAA,4CAAkE;AAClE,0CAAgD;AAChD,2DAA6E;AAC7E,mCAA8D;AAE9D,yDAAmC;AACnC,0DAA0B;AAC1B,sEAAsC;AAEtC,+CAA0C;AAC1C,+CAA+D;AAC/D,+CAA6E;AAE7E,sCAAqC;AAErC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAY,CAAC,CAAC;AAElD,MAAM,WAAW,GAAkB;IACjC,QAAQ,EAAE,6CAA6C;IACvD,OAAO,EAAE,oBAAoB;IAC7B,OAAO,EAAE,KAAK,CAAC,EAAE,CACf,KAAK;SACF,MAAM,EAAE;SACR,UAAU,CAAC,WAAW,EAAE;QACvB,WAAW,EACT,oGAAoG;QACtG,MAAM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sB,EAAiB,EAAE;IAClF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEK,MAAM,kBAAkB,GAAG,CAAC,OAAsB,EAAE,YAA0B,EAAW,EAAE;IAChG,MAAM,kBAAkB,GAAG,IAAA,qCAAqB,EAAC,YAAY,CAAC,CAAC;IAC/D,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC;AAC7D,CAAC,CAAC;AAHW,QAAA,kBAAkB,sBAG7B;AAEF,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAS,SAAQ,KAAK;CAAG;AAAtC,4BAAsC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs = tslib_1.__importStar(require("yargs"));
|
|
6
|
+
const openlint_runtime_1 = require("@openlint/openlint-runtime");
|
|
7
|
+
const lint_1 = tslib_1.__importDefault(require("./commands/lint"));
|
|
8
|
+
if (typeof process.env.PROXY === 'string') {
|
|
9
|
+
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
|
|
10
|
+
const httpAgent = new HttpProxyAgent({ proxy: process.env.PROXY });
|
|
11
|
+
const httpsAgent = new HttpsProxyAgent({ proxy: process.env.PROXY });
|
|
12
|
+
openlint_runtime_1.DEFAULT_REQUEST_OPTIONS.agent = url => (url.protocol === 'http:' ? httpAgent : httpsAgent);
|
|
13
|
+
}
|
|
14
|
+
exports.default = yargs
|
|
15
|
+
.scriptName('openlint')
|
|
16
|
+
.parserConfiguration({
|
|
17
|
+
'camel-case-expansion': true,
|
|
18
|
+
})
|
|
19
|
+
.version()
|
|
20
|
+
.help(true)
|
|
21
|
+
.strictCommands()
|
|
22
|
+
.strictOptions()
|
|
23
|
+
.showHelpOnFail(true)
|
|
24
|
+
.wrap(yargs.terminalWidth())
|
|
25
|
+
.command(lint_1.default)
|
|
26
|
+
.demandCommand(1, '').argv;
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAEA,qDAA+B;AAE/B,iEAAqE;AACrE,mEAA0C;AAE1C,IAAI,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;IAE1C,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,SAAS,CAA6B,CAAC;IAC3F,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;IACnE,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;IAErE,0CAAuB,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;AAC7F,CAAC;AAED,kBAAe,KAAK;KACjB,UAAU,CAAC,UAAU,CAAC;KACtB,mBAAmB,CAAC;IACnB,sBAAsB,EAAE,IAAI;CAC7B,CAAC;KACD,OAAO,EAAE;KACT,IAAI,CAAC,IAAI,CAAC;KACV,cAAc,EAAE;KAChB,aAAa,EAAE;KACf,cAAc,CAAC,IAAI,CAAC;KACpB,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;KAC3B,OAAO,CAAC,cAAW,CAAC;KACpB,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Dictionary } from '@stoplight/types';
|
|
2
|
+
import { HumanReadableDiagnosticSeverity } from '@openlint/openlint-core';
|
|
3
|
+
export type FailSeverity = Exclude<HumanReadableDiagnosticSeverity, 'off'>;
|
|
4
|
+
export declare enum OutputFormat {
|
|
5
|
+
JSON = "json",
|
|
6
|
+
STYLISH = "stylish",
|
|
7
|
+
JUNIT = "junit",
|
|
8
|
+
HTML = "html",
|
|
9
|
+
TEXT = "text",
|
|
10
|
+
TEAMCITY = "teamcity",
|
|
11
|
+
PRETTY = "pretty",
|
|
12
|
+
GITHUB_ACTIONS = "github-actions",
|
|
13
|
+
SARIF = "sarif",
|
|
14
|
+
CODE_CLIMATE = "code-climate",
|
|
15
|
+
GITLAB = "gitlab",
|
|
16
|
+
MARKDOWN = "markdown"
|
|
17
|
+
}
|
|
18
|
+
export interface ILintConfig {
|
|
19
|
+
encoding: 'utf8' | 'ascii' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex';
|
|
20
|
+
format: OutputFormat[];
|
|
21
|
+
output?: Dictionary<string>;
|
|
22
|
+
resolver?: string;
|
|
23
|
+
ruleset?: string;
|
|
24
|
+
stdinFilepath?: string;
|
|
25
|
+
ignoreUnknownFormat: boolean;
|
|
26
|
+
failOnUnmatchedGlobs: boolean;
|
|
27
|
+
showDocumentationUrl: boolean;
|
|
28
|
+
verbose?: boolean;
|
|
29
|
+
quiet?: boolean;
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutputFormat = void 0;
|
|
4
|
+
var OutputFormat;
|
|
5
|
+
(function (OutputFormat) {
|
|
6
|
+
OutputFormat["JSON"] = "json";
|
|
7
|
+
OutputFormat["STYLISH"] = "stylish";
|
|
8
|
+
OutputFormat["JUNIT"] = "junit";
|
|
9
|
+
OutputFormat["HTML"] = "html";
|
|
10
|
+
OutputFormat["TEXT"] = "text";
|
|
11
|
+
OutputFormat["TEAMCITY"] = "teamcity";
|
|
12
|
+
OutputFormat["PRETTY"] = "pretty";
|
|
13
|
+
OutputFormat["GITHUB_ACTIONS"] = "github-actions";
|
|
14
|
+
OutputFormat["SARIF"] = "sarif";
|
|
15
|
+
OutputFormat["CODE_CLIMATE"] = "code-climate";
|
|
16
|
+
OutputFormat["GITLAB"] = "gitlab";
|
|
17
|
+
OutputFormat["MARKDOWN"] = "markdown";
|
|
18
|
+
})(OutputFormat || (exports.OutputFormat = OutputFormat = {}));
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/services/config.ts"],"names":[],"mappings":";;;AAKA,IAAY,YAaX;AAbD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,+BAAe,CAAA;IACf,6BAAa,CAAA;IACb,6BAAa,CAAA;IACb,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,iDAAiC,CAAA;IACjC,+BAAe,CAAA;IACf,6CAA6B,CAAA;IAC7B,iCAAiB,CAAA;IACjB,qCAAqB,CAAA;AACvB,CAAC,EAbW,YAAY,4BAAZ,YAAY,QAavB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './linter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/linter/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IRuleResult, Ruleset } from '@openlint/openlint-core';
|
|
2
|
+
import { ILintConfig } from '../config';
|
|
3
|
+
export interface LinterResult {
|
|
4
|
+
results: IRuleResult[];
|
|
5
|
+
resolvedRuleset: Ruleset;
|
|
6
|
+
}
|
|
7
|
+
export declare function lint(documents: Array<number | string>, flags: ILintConfig): Promise<LinterResult>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lint = lint;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const openlint_core_1 = require("@openlint/openlint-core");
|
|
6
|
+
const openlint_runtime_1 = require("@openlint/openlint-runtime");
|
|
7
|
+
const Parsers = tslib_1.__importStar(require("@openlint/openlint-parsers"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const getResolver_1 = require("./utils/getResolver");
|
|
10
|
+
const errors_1 = require("../../errors");
|
|
11
|
+
async function lint(documents, flags) {
|
|
12
|
+
var _a;
|
|
13
|
+
const openlint = new openlint_core_1.OpenLint({
|
|
14
|
+
resolver: (0, getResolver_1.getResolver)(flags.resolver),
|
|
15
|
+
});
|
|
16
|
+
const ruleset = await (0, utils_1.getRuleset)(flags.ruleset);
|
|
17
|
+
openlint.setRuleset(ruleset);
|
|
18
|
+
if (flags.verbose === true) {
|
|
19
|
+
const rules = Object.values(ruleset.rules);
|
|
20
|
+
console.info(`Found ${rules.length} rules (${rules.filter(rule => rule.enabled).length} enabled)`);
|
|
21
|
+
}
|
|
22
|
+
const [globs, fileDescriptors] = (0, utils_1.segregateEntriesPerKind)(documents);
|
|
23
|
+
const [targetUris, unmatchedPatterns] = await (0, utils_1.listFiles)(globs, !flags.failOnUnmatchedGlobs);
|
|
24
|
+
const results = [];
|
|
25
|
+
if (unmatchedPatterns.length > 0) {
|
|
26
|
+
if (flags.failOnUnmatchedGlobs) {
|
|
27
|
+
throw new errors_1.CLIError(`Unmatched glob patterns: \`${unmatchedPatterns.join(',')}\``);
|
|
28
|
+
}
|
|
29
|
+
for (const unmatchedPattern of unmatchedPatterns) {
|
|
30
|
+
console.log(`Glob pattern \`${unmatchedPattern}\` did not match any files`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const targets = [...targetUris, ...fileDescriptors];
|
|
34
|
+
if (targets.length === 0) {
|
|
35
|
+
throw new errors_1.CLIError(`No files found to lint. Please check your file path and extension and try again`);
|
|
36
|
+
}
|
|
37
|
+
for (const targetUri of targets) {
|
|
38
|
+
if (flags.verbose === true) {
|
|
39
|
+
console.info(`Linting ${targetUri}`);
|
|
40
|
+
}
|
|
41
|
+
const document = await createDocument(targetUri, { encoding: flags.encoding }, (_a = flags.stdinFilepath) !== null && _a !== void 0 ? _a : '<STDIN>');
|
|
42
|
+
results.push(...(await openlint.run(document, {
|
|
43
|
+
ignoreUnknownFormat: flags.ignoreUnknownFormat,
|
|
44
|
+
})));
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
results: results,
|
|
48
|
+
resolvedRuleset: ruleset,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const createDocument = async (identifier, opts, source) => {
|
|
52
|
+
if (typeof identifier === 'string') {
|
|
53
|
+
return new openlint_core_1.Document(await (0, openlint_runtime_1.readParsable)(identifier, opts), Parsers.Yaml, identifier);
|
|
54
|
+
}
|
|
55
|
+
return new openlint_core_1.Document(await (0, utils_1.readFileDescriptor)(identifier, opts), Parsers.Yaml, source);
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=linter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../../src/services/linter/linter.ts"],"names":[],"mappings":";;AAcA,oBAkDC;;AA/DD,2DAAmF;AACnF,iEAA4E;AAC5E,4EAAsD;AACtD,mCAA6F;AAC7F,qDAAkD;AAElD,yCAAwC;AAOjC,KAAK,UAAU,IAAI,CAAC,SAAiC,EAAE,KAAkB;;IAC9E,MAAM,Q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= void 0;
|
|
4
|
+
const path_1 = require("@stoplight/path");
|
|
5
|
+
const openlint_ref_resolver_1 = require("@openlint/openlint-ref-resolver");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const errors_1 = require("../../../errors");
|
|
8
|
+
const getResolver = (resolver) => {
|
|
9
|
+
if (resolver !== void 0) {
|
|
10
|
+
try {
|
|
11
|
+
return require((0, path_1.isAbsolute)(resolver) ? resolver : (0, path_1.join)(process.cwd(), resolver));
|
|
12
|
+
}
|
|
13
|
+
catch (ex) {
|
|
14
|
+
throw new errors_1.CLIError((0, lodash_1.isError)(ex) ? formatMessage(ex.message) : String(ex));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return (0, openlint_ref_resolver_1.createHttpAndFileResolver)();
|
|
18
|
+
};
|
|
19
|
+
exports.getResolver = getResolver;
|
|
20
|
+
function formatMessage(message) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return (_b = (_a = message.split(/\r?\n/)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.replace(/\\/g, '/');
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getResolver.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/getResolver.ts"],"names":[],"mappings":";;;AAAA,0CAAmD;AAEnD,2EAAsF;AACtF,mCAAiC;AACjC,4CAA2C;AAEpC,MAAM,WAAW,GAAG,CAAC,QAA0B,EAAY,EAAE;IAClE,IAAI,QAAQ,KAAK,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC;YAEH,OAAO,OAAO,CAAC,IAAA,iBAAU,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClF,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,iBAAQ,CAAC,IAAA,gBAAO,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,OAAO,IAAA,iDAAyB,GAAE,CAAC;AACrC,CAAC,CAAC;AAXW,QAAA,WAAW,eAWtB;AAEF,SAAS,aAAa,CAAC,OAAe;;IACpC,OAAO,MAAA,MAAA,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,0CAAG,CAAC,CAAC,0CAAE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRuleset = getRuleset;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const openlint_core_1 = require("@openlint/openlint-core");
|
|
6
|
+
const openlint_parsers_1 = require("@openlint/openlint-parsers");
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
8
|
+
const path = tslib_1.__importStar(require("@stoplight/path"));
|
|
9
|
+
const process = tslib_1.__importStar(require("process"));
|
|
10
|
+
const module_1 = require("module");
|
|
11
|
+
const openlint_runtime_1 = require("@openlint/openlint-runtime");
|
|
12
|
+
const openlint_ruleset_migrator_1 = require("@openlint/openlint-ruleset-migrator");
|
|
13
|
+
const openlint_ruleset_bundler_1 = require("@openlint/openlint-ruleset-bundler");
|
|
14
|
+
const node_1 = require("@openlint/openlint-ruleset-bundler/presets/node");
|
|
15
|
+
const commonjs_1 = require("@openlint/openlint-ruleset-bundler/plugins/commonjs");
|
|
16
|
+
const stdin_1 = require("@openlint/openlint-ruleset-bundler/plugins/stdin");
|
|
17
|
+
const builtins_1 = require("@openlint/openlint-ruleset-bundler/plugins/builtins");
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
19
|
+
const errors_1 = require("../../../errors");
|
|
20
|
+
async function getDefaultRulesetFile() {
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
for (const filename of await fs.promises.readdir(cwd)) {
|
|
23
|
+
if (openlint_core_1.Ruleset.isDefaultRulesetFile(filename)) {
|
|
24
|
+
return path.join(cwd, filename);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
function isErrorWithCode(error) {
|
|
30
|
+
return 'code' in error && typeof error.code === 'string';
|
|
31
|
+
}
|
|
32
|
+
async function getRuleset(rulesetFile) {
|
|
33
|
+
if (rulesetFile === void 0) {
|
|
34
|
+
rulesetFile = await getDefaultRulesetFile();
|
|
35
|
+
}
|
|
36
|
+
else if (!path.isAbsolute(rulesetFile)) {
|
|
37
|
+
rulesetFile = path.join(process.cwd(), rulesetFile);
|
|
38
|
+
}
|
|
39
|
+
if (rulesetFile === void 0) {
|
|
40
|
+
throw new errors_1.CLIError('No ruleset has been found. Please provide a ruleset using the --ruleset CLI argument, or make sure your ruleset file matches .openlint.js/yaml/json or .openlint.js/yaml/json');
|
|
41
|
+
}
|
|
42
|
+
let ruleset;
|
|
43
|
+
let sourceContext;
|
|
44
|
+
const originalRulesetFile = rulesetFile;
|
|
45
|
+
try {
|
|
46
|
+
if (await (0, openlint_ruleset_migrator_1.isBasicRuleset)(rulesetFile)) {
|
|
47
|
+
sourceContext = await buildSourceContext(originalRulesetFile);
|
|
48
|
+
const migratedRuleset = await (0, openlint_ruleset_migrator_1.migrateRuleset)(rulesetFile, {
|
|
49
|
+
format: 'esm',
|
|
50
|
+
fs,
|
|
51
|
+
});
|
|
52
|
+
rulesetFile = path.join(path.dirname(rulesetFile), '.openlint.js');
|
|
53
|
+
ruleset = await (0, openlint_ruleset_bundler_1.bundleRuleset)(rulesetFile, {
|
|
54
|
+
target: 'node',
|
|
55
|
+
format: 'commonjs',
|
|
56
|
+
plugins: [(0, stdin_1.stdin)(migratedRuleset, rulesetFile), (0, builtins_1.builtins)(), (0, commonjs_1.commonjs)(), ...(0, node_1.node)({ fs, fetch: openlint_runtime_1.fetch })],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
ruleset = await (0, openlint_ruleset_bundler_1.bundleRuleset)(rulesetFile, {
|
|
61
|
+
target: 'node',
|
|
62
|
+
format: 'commonjs',
|
|
63
|
+
plugins: [(0, builtins_1.builtins)(), (0, commonjs_1.commonjs)(), ...(0, node_1.node)({ fs, fetch: openlint_runtime_1.fetch })],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (!(0, lodash_1.isError)(e) || !isErrorWithCode(e) || e.code !== 'UNRESOLVED_ENTRY') {
|
|
69
|
+
throw e;
|
|
70
|
+
}
|
|
71
|
+
throw new errors_1.CLIError(`Could not read ruleset at ${rulesetFile}.`);
|
|
72
|
+
}
|
|
73
|
+
return new openlint_core_1.Ruleset(load(ruleset, rulesetFile), {
|
|
74
|
+
severity: 'recommended',
|
|
75
|
+
source: rulesetFile,
|
|
76
|
+
sourceContext,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function buildSourceContext(rulesetFile) {
|
|
80
|
+
try {
|
|
81
|
+
const input = await fs.promises.readFile(rulesetFile, 'utf8');
|
|
82
|
+
if (path.extname(rulesetFile) === '.json') {
|
|
83
|
+
const parserResult = openlint_parsers_1.Json.parse(input);
|
|
84
|
+
return {
|
|
85
|
+
source: rulesetFile,
|
|
86
|
+
getLocationForJsonPath(jsonPath) {
|
|
87
|
+
return openlint_parsers_1.Json.getLocationForJsonPath(parserResult, jsonPath);
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const parserResult = openlint_parsers_1.Yaml.parse(input);
|
|
92
|
+
return {
|
|
93
|
+
source: rulesetFile,
|
|
94
|
+
getLocationForJsonPath(jsonPath) {
|
|
95
|
+
return openlint_parsers_1.Yaml.getLocationForJsonPath(parserResult, jsonPath);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function load(source, uri) {
|
|
104
|
+
const actualUri = path.isURL(uri) ? uri.replace(/^https?:\//, '') : uri;
|
|
105
|
+
const req = (0, module_1.createRequire)(actualUri);
|
|
106
|
+
const m = {};
|
|
107
|
+
const paths = [path.dirname(uri), __dirname];
|
|
108
|
+
const _require = (id) => req(req.resolve(id, { paths }));
|
|
109
|
+
Function('module, require', source)(m, _require);
|
|
110
|
+
if (!(0, lodash_1.isObject)(m.exports)) {
|
|
111
|
+
throw new errors_1.CLIError('No valid export found');
|
|
112
|
+
}
|
|
113
|
+
return m.exports;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=getRuleset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRuleset.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/getRuleset.ts"],"names":[],"mappings":";;AAgCA,gCAqDC;;AApFD,2DAA2F;AAC3F,iEAAwD;AACxD,+CAAyB;AACzB,8DAAwC;AACxC,yDAAmC;AACnC,mCAAuC;AACvC,iEAAmD;AACnD,mFAAqF;AACrF,iFAAmE;AACnE,0EAAuE;AACvE,kFAA+E;AAC/E,4EAAyE;AACzE,kFAA+E;AAC/E,mCAA2C;AAC3C,4CAA2C;AAE3C,KAAK,UAAU,qBAAqB;IAClC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACtD,IAAI,uBAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CA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O,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./getRuleset"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./listFiles"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./readFileDescriptor"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./segregateEntriesPerKind"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,sDAA4B;AAC5B,+DAAqC;AACrC,oEAA0C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listFiles(patterns: string[], ignoreUnmatchedGlobs: boolean): Promise<[string[], string[]]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listFiles = listFiles;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = require("@stoplight/path");
|
|
6
|
+
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
|
7
|
+
const GLOB_OPTIONS = {
|
|
8
|
+
absolute: true,
|
|
9
|
+
dot: true,
|
|
10
|
+
};
|
|
11
|
+
async function match(pattern) {
|
|
12
|
+
return (await (0, fast_glob_1.default)(pattern, GLOB_OPTIONS)).map(path_1.normalize);
|
|
13
|
+
}
|
|
14
|
+
const compareString = (a, b) => a.localeCompare(b);
|
|
15
|
+
async function listFiles(patterns, ignoreUnmatchedGlobs) {
|
|
16
|
+
const { files, urls } = patterns.reduce((group, pattern) => {
|
|
17
|
+
if (!/^https?:\/\//.test(pattern)) {
|
|
18
|
+
group.files.push(pattern.replace(/\\/g, '/'));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
group.urls.push(pattern);
|
|
22
|
+
}
|
|
23
|
+
return group;
|
|
24
|
+
}, {
|
|
25
|
+
files: [],
|
|
26
|
+
urls: [],
|
|
27
|
+
});
|
|
28
|
+
const filesFound = [];
|
|
29
|
+
const fileSearchWithoutResult = [];
|
|
30
|
+
if (ignoreUnmatchedGlobs) {
|
|
31
|
+
filesFound.push(...(await match(files)));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
await Promise.all(files.map(async (pattern) => {
|
|
35
|
+
const resultFg = await match(pattern);
|
|
36
|
+
if (resultFg.length === 0) {
|
|
37
|
+
fileSearchWithoutResult.push(pattern);
|
|
38
|
+
}
|
|
39
|
+
filesFound.push(...resultFg);
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
return [[...urls, ...filesFound].sort(compareString), fileSearchWithoutResult];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=listFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listFiles.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/listFiles.ts"],"names":[],"mappings":";;AAcA,8BAwCC;;AAtDD,0CAA4C;AAC5C,kEAA2B;AAE3B,MAAM,YAAY,GAAG;IACnB,QAAQ,EAAE,IAAI;IACd,GAAG,EAAE,IAAI;CACV,CAAC;AAEF,KAAK,UAAU,KAAK,CAAC,OAAkC;IACrD,OAAO,CAAC,MAAM,IAAA,mBAAE,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,gBAAS,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAEpE,KAAK,UAAU,SAAS,CAAC,QAAkB,EAAE,oBAA6B;IAC/E,MAAM,EAAE,KAAK,EAAE,IAAI,EA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Module", { value: true });
|
|
3
|
+
exports.readFileDescriptor = readFileDescriptor;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
6
|
+
async function readFileDescriptor(fd, opts) {
|
|
7
|
+
let result = '';
|
|
8
|
+
const stream = fs.createReadStream('', { fd });
|
|
9
|
+
stream.setEncoding(opts.encoding);
|
|
10
|
+
stream.on('readable', () => {
|
|
11
|
+
let chunk;
|
|
12
|
+
while ((chunk = stream.read()) !== null) {
|
|
13
|
+
result += chunk;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
stream.on('error', reject);
|
|
18
|
+
stream.on('end', () => {
|
|
19
|
+
resolve(result);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=readFileDescriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readFileDescriptor.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/readFileDescriptor.ts"],"names":[],"mappings":";;AAIA,gDAoBC;;AAxBD,+CAAyB;AAIlB,KAAK,UAAU,kBAAkB,CAAC,EAAU,EAAE,IAAsB;IACzE,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/C,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAElC,MAAM,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QACzB,IAAI,KAAa,CAAC;QAElB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,EAAY,CAAC,KAAK,IAAI,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function segregateEntriesPerKind(entries: Array<string | number>): [string[], number[]];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.segregateEntriesPerKind = segregateEntriesPerKind;
|
|
4
|
+
function segregateEntriesPerKind(entries) {
|
|
5
|
+
return entries.reduce((group, entry) => {
|
|
6
|
+
if (typeof entry === 'string') {
|
|
7
|
+
group[0].push(entry);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
group[1].push(entry);
|
|
11
|
+
}
|
|
12
|
+
return group;
|
|
13
|
+
}, [[], []]);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=segregateEntriesPerKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segregateEntriesPerKind.js","sourceRoot":"","sources":["../../../../src/services/linter/utils/segregateEntriesPerKind.ts"],"names":[],"mappings":";;AAAA,0DAaC;AAbD,SAAgB,uBAAuB,CAAC,OAA+B;IACrE,OAAO,OAAO,CAAC,MAAM,CACnB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,EACD,CAAC,EAAE,EAAE,EAAE,CAAC,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IRuleResult, Ruleset } from '@openlint/openlint-core';
|
|
2
|
+
import type { FormatterOptions } from '@openlint/openlint-formatters';
|
|
3
|
+
import type { OutputFormat } from './config';
|
|
4
|
+
export declare function formatOutput(results: IRuleResult[], format: OutputFormat, formatOptions: FormatterOptions, ruleset: Ruleset): string;
|
|
5
|
+
export declare function writeOutput(outputStr: string, outputFile: string): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatOutput = formatOutput;
|
|
4
|
+
exports.writeOutput = writeOutput;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const process = tslib_1.__importStar(require("process"));
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const openlint_formatters_1 = require("@openlint/openlint-formatters");
|
|
9
|
+
const version_1 = require("../version");
|
|
10
|
+
const formatters = {
|
|
11
|
+
json: openlint_formatters_1.json,
|
|
12
|
+
stylish: openlint_formatters_1.stylish,
|
|
13
|
+
pretty: openlint_formatters_1.pretty,
|
|
14
|
+
junit: openlint_formatters_1.junit,
|
|
15
|
+
html: openlint_formatters_1.html,
|
|
16
|
+
text: openlint_formatters_1.text,
|
|
17
|
+
teamcity: openlint_formatters_1.teamcity,
|
|
18
|
+
'github-actions': openlint_formatters_1.githubActions,
|
|
19
|
+
sarif: openlint_formatters_1.sarif,
|
|
20
|
+
'code-climate': openlint_formatters_1.codeClimate,
|
|
21
|
+
gitlab: openlint_formatters_1.codeClimate,
|
|
22
|
+
markdown: openlint_formatters_1.markdown,
|
|
23
|
+
};
|
|
24
|
+
function formatOutput(results, format, formatOptions, ruleset) {
|
|
25
|
+
return formatters[format](results, formatOptions, {
|
|
26
|
+
ruleset,
|
|
27
|
+
spectralVersion: version_1.VERSION,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function writeOutput(outputStr, outputFile) {
|
|
31
|
+
if (outputFile !== '<stdout>') {
|
|
32
|
+
await fs_1.promises.writeFile(outputFile, outputStr);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
process.stdout.write(outputStr, err => {
|
|
37
|
+
if (err)
|
|
38
|
+
reject(err);
|
|
39
|
+
else
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/services/output.ts"],"names":[],"mappings":";;AAmCA,oCAWC;AAED,kCAaC;;AA7DD,yDAAmC;AAEnC,2BAAoC;AACpC,uEAYuC;AAGvC,wCAAqC;AAErC,MAAM,UAAU,GAAoC;IAClD,IAAI,EAAJ,0BAAI;IACJ,OAAO,EAAP,6BAAO;IACP,MAAM,EAAN,4BAAM;IACN,KAAK,EAAL,2BAAK;IACL,IAAI,EAAJ,0BAAI;IACJ,IAAI,EAAJ,0BAAI;IACJ,QAAQ,EAAR,8BAAQ;IACR,gBAAgB,EAAE,mCAAa;IAC/B,KAAK,EAAL,2BAAK;IACL,cAAc,EAAE,iCAAW;IAC3B,MAAM,EAAE,iCAAW;IACnB,QAAQ,EAAR,8BAAQ;CACT,CAAC;AAEF,SAAgB,YAAY,CAC1B,OAAsB,EACtB,MAAoB,EACpB,aAA+B,EAC/B,OAAgB;IAEhB,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,aAAa,EAAE;QAChD,OAAO;QAEP,eAAe,EAAE,iBAAO;KACzB,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,WAAW,CAAC,SAAiB,EAAE,UAAkB;IACrE,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC9B,MAAM,aAAE,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC5C,CAAC;SAAM,CAAC;QAGN,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE;gBACpC,IAAI,GAAG;oBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;oBAChB,OAAO,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.0.1";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openlint/openlint-cli",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"homepage": "https://github.com/openlint/openlint",
|
|
5
|
+
"bugs": "https://github.com/openlint/openlint/issues",
|
|
6
|
+
"author": "OpenLint <info@openlint.org>",
|
|
7
|
+
"bin": {
|
|
8
|
+
"openlint": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": "^22.0 || >= 24.0"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"/dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/openlint/openlint.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prelint": "node ../../scripts/inline-version.mjs",
|
|
28
|
+
"prepare": "node ../../scripts/inline-version.mjs",
|
|
29
|
+
"prebuild": "node ../../scripts/inline-version.mjs",
|
|
30
|
+
"build.binary": "pkg . --output ./binaries/openlint",
|
|
31
|
+
"build.windows": "pkg . --targets windows --out-path ./binaries",
|
|
32
|
+
"build.nix": "pkg . --targets linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64 --out-path ./binaries",
|
|
33
|
+
"cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts",
|
|
34
|
+
"cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@openlint/openlint-core": "0.0.1",
|
|
38
|
+
"@openlint/openlint-formatters": "0.0.1",
|
|
39
|
+
"@openlint/openlint-parsers": "0.0.1",
|
|
40
|
+
"@openlint/openlint-ref-resolver": "0.0.1",
|
|
41
|
+
"@openlint/openlint-ruleset-bundler": "0.0.1",
|
|
42
|
+
"@openlint/openlint-ruleset-migrator": "0.0.1",
|
|
43
|
+
"@openlint/openlint-rulesets": "0.0.1",
|
|
44
|
+
"@openlint/openlint-runtime": "0.0.1",
|
|
45
|
+
"@stoplight/json": "~3.21.0",
|
|
46
|
+
"@stoplight/path": "1.3.2",
|
|
47
|
+
"@stoplight/types": "^13.6.0",
|
|
48
|
+
"chalk": "4.1.2",
|
|
49
|
+
"fast-glob": "~3.2.12",
|
|
50
|
+
"hpagent": "~1.2.0",
|
|
51
|
+
"lodash": "^4.18.1",
|
|
52
|
+
"stacktracey": "^2.1.8",
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"yargs": "~17.7.2"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/xml2js": "^0.4.9",
|
|
58
|
+
"@types/yargs": "^17.0.8",
|
|
59
|
+
"@yao-pkg/pkg": "6.22.0",
|
|
60
|
+
"nock": "^13.5.4",
|
|
61
|
+
"tsconfig-paths": "^4.2.0",
|
|
62
|
+
"xml2js": "^0.5.0"
|
|
63
|
+
},
|
|
64
|
+
"pkg": {
|
|
65
|
+
"scripts": [
|
|
66
|
+
"./dist/**/*.js",
|
|
67
|
+
"../../node_modules/async-function/index.js",
|
|
68
|
+
"../../node_modules/async-generator-function/index.js",
|
|
69
|
+
"../../node_modules/generator-function/index.js"
|
|
70
|
+
],
|
|
71
|
+
"assets": [
|
|
72
|
+
"./dist/**/*.json",
|
|
73
|
+
"../*/dist/**/*.js.map",
|
|
74
|
+
"../*/src/**/*.ts"
|
|
75
|
+
],
|
|
76
|
+
"options": [
|
|
77
|
+
"no-experimental-require-module"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|