@opensip-cli/checks-python 0.1.0
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 +202 -0
- package/NOTICE +8 -0
- package/README.md +31 -0
- package/dist/__tests__/display.test.d.ts +2 -0
- package/dist/__tests__/display.test.d.ts.map +1 -0
- package/dist/__tests__/display.test.js +21 -0
- package/dist/__tests__/display.test.js.map +1 -0
- package/dist/__tests__/fixture-coverage.allowlist.d.ts +17 -0
- package/dist/__tests__/fixture-coverage.allowlist.d.ts.map +1 -0
- package/dist/__tests__/fixture-coverage.allowlist.js +16 -0
- package/dist/__tests__/fixture-coverage.allowlist.js.map +1 -0
- package/dist/__tests__/fixture-coverage.test.d.ts +13 -0
- package/dist/__tests__/fixture-coverage.test.d.ts.map +1 -0
- package/dist/__tests__/fixture-coverage.test.js +57 -0
- package/dist/__tests__/fixture-coverage.test.js.map +1 -0
- package/dist/__tests__/function-too-long.test.d.ts +2 -0
- package/dist/__tests__/function-too-long.test.d.ts.map +1 -0
- package/dist/__tests__/function-too-long.test.js +69 -0
- package/dist/__tests__/function-too-long.test.js.map +1 -0
- package/dist/__tests__/no-bare-except.test.d.ts +2 -0
- package/dist/__tests__/no-bare-except.test.d.ts.map +1 -0
- package/dist/__tests__/no-bare-except.test.js +75 -0
- package/dist/__tests__/no-bare-except.test.js.map +1 -0
- package/dist/__tests__/run.test.d.ts +2 -0
- package/dist/__tests__/run.test.d.ts.map +1 -0
- package/dist/__tests__/run.test.js +56 -0
- package/dist/__tests__/run.test.js.map +1 -0
- package/dist/checks/function-too-long.d.ts +16 -0
- package/dist/checks/function-too-long.d.ts.map +1 -0
- package/dist/checks/function-too-long.js +54 -0
- package/dist/checks/function-too-long.js.map +1 -0
- package/dist/checks/no-bare-except.d.ts +23 -0
- package/dist/checks/no-bare-except.d.ts.map +1 -0
- package/dist/checks/no-bare-except.js +52 -0
- package/dist/checks/no-bare-except.js.map +1 -0
- package/dist/display/index.d.ts +9 -0
- package/dist/display/index.d.ts.map +1 -0
- package/dist/display/index.js +4 -0
- package/dist/display/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
OpenSIP CLI
|
|
2
|
+
Copyright 2026 opensip-ai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this software except in compliance with the License. A copy of the License is
|
|
6
|
+
included in the LICENSE file and is also available at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Generated by scripts/build-package-readmes.mjs โ do not edit by hand.
|
|
2
|
+
Change the package's "description" (or the generator template) and run
|
|
3
|
+
`pnpm docs:readmes`. CI enforces sync via `pnpm docs:readmes:check`. -->
|
|
4
|
+
|
|
5
|
+
# @opensip-cli/checks-python
|
|
6
|
+
|
|
7
|
+
> Python fitness checks for opensip-cli
|
|
8
|
+
|
|
9
|
+
This is a **fitness check pack**. Install it alongside the `opensip-cli` CLI and its checks are discovered automatically.
|
|
10
|
+
|
|
11
|
+
Part of [**opensip-cli**](https://github.com/opensip-ai/opensip-cli) โ an open-source codebase-analysis toolkit: fitness checks (`fit`), static call-graph analysis (`graph`), and simulation (`sim`).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Most users install the CLI, which bundles the first-party tools:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://opensip.ai/cli/install.sh | bash
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This package is published for the CLI and advanced plugin authors; most users should not install `@opensip-cli/checks-python` directly.
|
|
22
|
+
|
|
23
|
+
## Documentation
|
|
24
|
+
|
|
25
|
+
- ๐ Project docs: https://opensip.ai/docs/opensip-cli/
|
|
26
|
+
- ๐งญ Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.0/docs/public/70-reference/02-package-catalog.md
|
|
27
|
+
- ๐ฆ Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.0/packages/fitness/checks-python
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Apache-2.0 ยฉ opensip-ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/display.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { checkDisplay } from '../display/index.js';
|
|
3
|
+
describe('checkDisplay metadata', () => {
|
|
4
|
+
it('maps the no-bare-except slug to its [icon, name] tuple', () => {
|
|
5
|
+
expect(checkDisplay['no-bare-except']).toEqual(['๐', 'No Bare Except']);
|
|
6
|
+
});
|
|
7
|
+
it('every entry is a non-empty [icon, displayName] string tuple', () => {
|
|
8
|
+
const entries = Object.entries(checkDisplay);
|
|
9
|
+
expect(entries.length).toBeGreaterThan(0);
|
|
10
|
+
for (const [slug, entry] of entries) {
|
|
11
|
+
expect(slug.length).toBeGreaterThan(0);
|
|
12
|
+
expect(entry).toHaveLength(2);
|
|
13
|
+
const [icon, name] = entry;
|
|
14
|
+
expect(typeof icon).toBe('string');
|
|
15
|
+
expect(icon.length).toBeGreaterThan(0);
|
|
16
|
+
expect(typeof name).toBe('string');
|
|
17
|
+
expect(name.length).toBeGreaterThan(0);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=display.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.test.js","sourceRoot":"","sources":["../../src/__tests__/display.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,GAAG,EAAE;QACrE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC1C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YACpC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC9B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;YAC3B,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-check fixture-coverage allowlist for checks-python (testing gap P0).
|
|
3
|
+
*
|
|
4
|
+
* `ALLOWLIST` is currently empty: every shipped, fixture-exercisable check
|
|
5
|
+
* has clean+violation fixtures. A future entry would mean a check whose
|
|
6
|
+
* pass/fail fixture coverage is still owed.
|
|
7
|
+
*
|
|
8
|
+
* `COMMAND_EXEMPTIONS` are `analysisMode:'command'` checks that shell out to
|
|
9
|
+
* external tools and cannot be exercised by writing a fixture file; they are
|
|
10
|
+
* covered by the failure-mode / packed-smoke lanes instead (gap register).
|
|
11
|
+
*/
|
|
12
|
+
import type { CommandExemptions, CoverageAllowlist, FilenameOverrides } from '@opensip-cli/test-support';
|
|
13
|
+
export declare const ALLOWLIST: CoverageAllowlist;
|
|
14
|
+
export declare const COMMAND_EXEMPTIONS: CommandExemptions;
|
|
15
|
+
export declare const FILENAME_OVERRIDES: FilenameOverrides;
|
|
16
|
+
export declare const KNOWN_UNFIXTURABLE: CommandExemptions;
|
|
17
|
+
//# sourceMappingURL=fixture-coverage.allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-coverage.allowlist.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture-coverage.allowlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,SAAS,EAAE,iBAAsB,CAAC;AAE/C,eAAO,MAAM,kBAAkB,EAAE,iBAAsB,CAAC;AAExD,eAAO,MAAM,kBAAkB,EAAE,iBAAsB,CAAC;AAExD,eAAO,MAAM,kBAAkB,EAAE,iBAAsB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-check fixture-coverage allowlist for checks-python (testing gap P0).
|
|
3
|
+
*
|
|
4
|
+
* `ALLOWLIST` is currently empty: every shipped, fixture-exercisable check
|
|
5
|
+
* has clean+violation fixtures. A future entry would mean a check whose
|
|
6
|
+
* pass/fail fixture coverage is still owed.
|
|
7
|
+
*
|
|
8
|
+
* `COMMAND_EXEMPTIONS` are `analysisMode:'command'` checks that shell out to
|
|
9
|
+
* external tools and cannot be exercised by writing a fixture file; they are
|
|
10
|
+
* covered by the failure-mode / packed-smoke lanes instead (gap register).
|
|
11
|
+
*/
|
|
12
|
+
export const ALLOWLIST = [];
|
|
13
|
+
export const COMMAND_EXEMPTIONS = {};
|
|
14
|
+
export const FILENAME_OVERRIDES = {};
|
|
15
|
+
export const KNOWN_UNFIXTURABLE = {};
|
|
16
|
+
//# sourceMappingURL=fixture-coverage.allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-coverage.allowlist.js","sourceRoot":"","sources":["../../src/__tests__/fixture-coverage.allowlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,MAAM,CAAC,MAAM,SAAS,GAAsB,EAAE,CAAC;AAE/C,MAAM,CAAC,MAAM,kBAAkB,GAAsB,EAAE,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAsB,EAAE,CAAC;AAExD,MAAM,CAAC,MAAM,kBAAkB,GAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-check pass/fail fixture coverage for checks-python (testing gap P0).
|
|
3
|
+
*
|
|
4
|
+
* Every shipped, non-command, fixture-exercisable check must have a clean
|
|
5
|
+
* fixture (0 findings) and a violation fixture (>=1) under a co-located
|
|
6
|
+
* `__fixtures__/<slug>/` directory next to the check's source. The ALLOWLIST is
|
|
7
|
+
* empty, so the ratchet is live: a new uncovered check fails this test. Command
|
|
8
|
+
* checks live in COMMAND_EXEMPTIONS; structurally un-exercisable checks live in
|
|
9
|
+
* KNOWN_UNFIXTURABLE. The harness runs each check in-process via the engine's
|
|
10
|
+
* internal coverage helpers.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=fixture-coverage.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-coverage.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/fixture-coverage.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-check pass/fail fixture coverage for checks-python (testing gap P0).
|
|
3
|
+
*
|
|
4
|
+
* Every shipped, non-command, fixture-exercisable check must have a clean
|
|
5
|
+
* fixture (0 findings) and a violation fixture (>=1) under a co-located
|
|
6
|
+
* `__fixtures__/<slug>/` directory next to the check's source. The ALLOWLIST is
|
|
7
|
+
* empty, so the ratchet is live: a new uncovered check fails this test. Command
|
|
8
|
+
* checks live in COMMAND_EXEMPTIONS; structurally un-exercisable checks live in
|
|
9
|
+
* KNOWN_UNFIXTURABLE. The harness runs each check in-process via the engine's
|
|
10
|
+
* internal coverage helpers.
|
|
11
|
+
*/
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import { planCoverageCases, runCheckOnFixture, validateBookkeeping, } from '@opensip-cli/test-support';
|
|
15
|
+
import { describe, expect, it } from 'vitest';
|
|
16
|
+
import { checks } from '../index.js';
|
|
17
|
+
import { ALLOWLIST, COMMAND_EXEMPTIONS, FILENAME_OVERRIDES, KNOWN_UNFIXTURABLE, } from './fixture-coverage.allowlist.js';
|
|
18
|
+
const PACK_SRC = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
19
|
+
const config = {
|
|
20
|
+
packName: 'checks-python',
|
|
21
|
+
checks,
|
|
22
|
+
allowlist: ALLOWLIST,
|
|
23
|
+
commandExemptions: COMMAND_EXEMPTIONS,
|
|
24
|
+
knownUnfixturable: KNOWN_UNFIXTURABLE,
|
|
25
|
+
filenameOverrides: FILENAME_OVERRIDES,
|
|
26
|
+
};
|
|
27
|
+
const cases = await planCoverageCases(config, PACK_SRC);
|
|
28
|
+
describe('checks-python ยท fixture-coverage bookkeeping', () => {
|
|
29
|
+
it('config is self-consistent (allowlist empty, exemptions valid)', () => {
|
|
30
|
+
expect(validateBookkeeping(config)).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('checks-python ยท fixture-coverage', () => {
|
|
34
|
+
if (cases.length === 0) {
|
|
35
|
+
// No fixturable checks (e.g. an all-command pack): assert every shipped
|
|
36
|
+
// check is accounted for by an exemption rather than silently uncovered.
|
|
37
|
+
it('every shipped check is exempted or allowlisted', () => {
|
|
38
|
+
const accounted = ALLOWLIST.length +
|
|
39
|
+
Object.keys(COMMAND_EXEMPTIONS).length +
|
|
40
|
+
Object.keys(KNOWN_UNFIXTURABLE).length;
|
|
41
|
+
expect(accounted).toBeGreaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
it.each(cases)('$label', async (testCase) => {
|
|
46
|
+
if (!testCase.fixture)
|
|
47
|
+
expect.fail(testCase.missingHint);
|
|
48
|
+
const run = await runCheckOnFixture(testCase.check, testCase.fixture);
|
|
49
|
+
if (testCase.variant === 'clean') {
|
|
50
|
+
expect(run.findings, `clean fixture for '${testCase.slug}' must produce 0 findings`).toHaveLength(0);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
expect(run.findings.length, `violation fixture for '${testCase.slug}' must produce >=1 finding`).toBeGreaterThanOrEqual(1);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=fixture-coverage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture-coverage.test.js","sourceRoot":"","sources":["../../src/__tests__/fixture-coverage.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAErE,MAAM,MAAM,GAAmB;IAC7B,QAAQ,EAAE,eAAe;IACzB,MAAM;IACN,SAAS,EAAE,SAAS;IACpB,iBAAiB,EAAE,kBAAkB;IACrC,iBAAiB,EAAE,kBAAkB;IACrC,iBAAiB,EAAE,kBAAkB;CACtC,CAAC;AAEF,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAExD,QAAQ,CAAC,8CAA8C,EAAE,GAAG,EAAE;IAC5D,EAAE,CAAC,+DAA+D,EAAE,GAAG,EAAE;QACvE,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAA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../../src/__tests__/function-too-long.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { LanguageRegistry, RunScope, runWithScope } from '@opensip-cli/core';
|
|
5
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
6
|
+
import { analyzeFunctionTooLong, pythonFunctionTooLong } from '../checks/function-too-long.js';
|
|
7
|
+
/** A `def` whose body is `bodyLines` assignment statements. */
|
|
8
|
+
function pyFunction(name, bodyLines) {
|
|
9
|
+
const body = Array.from({ length: bodyLines }, (_, i) => ` x${i} = ${i}`).join('\n');
|
|
10
|
+
return `def ${name}():\n${body}\n`;
|
|
11
|
+
}
|
|
12
|
+
describe('python-function-too-long', () => {
|
|
13
|
+
it('flags a function over the line budget', () => {
|
|
14
|
+
const violations = analyzeFunctionTooLong(pyFunction('big', 60), 'big.py');
|
|
15
|
+
expect(violations).toHaveLength(1);
|
|
16
|
+
expect(violations[0].line).toBe(1);
|
|
17
|
+
expect(violations[0].message).toContain('big');
|
|
18
|
+
expect(violations[0].severity).toBe('warning');
|
|
19
|
+
});
|
|
20
|
+
it('does not flag a short function', () => {
|
|
21
|
+
expect(analyzeFunctionTooLong('def small():\n return 1\n', 'small.py')).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
it('counts nested functions independently (only the long one fires)', () => {
|
|
24
|
+
const src = `${pyFunction('outer', 60).trimEnd()}\n def inner():\n return 1\n`;
|
|
25
|
+
const violations = analyzeFunctionTooLong(src, 'nested.py');
|
|
26
|
+
expect(violations).toHaveLength(1);
|
|
27
|
+
expect(violations[0].message).toContain('outer');
|
|
28
|
+
});
|
|
29
|
+
it('returns [] on malformed input without throwing', () => {
|
|
30
|
+
expect(() => analyzeFunctionTooLong('def (:\n', 'bad.py')).not.toThrow();
|
|
31
|
+
expect(analyzeFunctionTooLong('def (:\n', 'bad.py')).toEqual([]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
// Exercises the `analyze` closure declared inside `defineCheck({...})` end-to-end
|
|
35
|
+
// (the pure analyzer above is called directly and never goes through `.run()`).
|
|
36
|
+
// Mirrors run.test.ts: an empty scope drives applyContentFilter's no-adapter path.
|
|
37
|
+
describe('pythonFunctionTooLong.run() execution coverage', () => {
|
|
38
|
+
const emptyScope = new RunScope({ languages: new LanguageRegistry() });
|
|
39
|
+
let cwd;
|
|
40
|
+
let longTarget;
|
|
41
|
+
let shortTarget;
|
|
42
|
+
beforeAll(() => {
|
|
43
|
+
cwd = mkdtempSync(join(tmpdir(), 'opensip-checks-python-ftl-cov-'));
|
|
44
|
+
const longBody = Array.from({ length: 60 }, (_, i) => ` y${i} = ${i}`).join('\n');
|
|
45
|
+
longTarget = join(cwd, 'long.py');
|
|
46
|
+
writeFileSync(longTarget, `def oversized():\n${longBody}\n`);
|
|
47
|
+
shortTarget = join(cwd, 'short.py');
|
|
48
|
+
writeFileSync(shortTarget, 'def tidy():\n return 1\n');
|
|
49
|
+
});
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
52
|
+
});
|
|
53
|
+
it('emits a signal for an over-budget function via .run()', async () => {
|
|
54
|
+
const result = await runWithScope(emptyScope, () => pythonFunctionTooLong.run(cwd, { targetFiles: [longTarget] }));
|
|
55
|
+
expect(Array.isArray(result.signals)).toBe(true);
|
|
56
|
+
expect(result.signals.length).toBeGreaterThanOrEqual(1);
|
|
57
|
+
expect(result.signals.some((s) => JSON.stringify(s).includes('oversized'))).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
it('emits no signal for a function under the budget via .run()', async () => {
|
|
60
|
+
const result = await runWithScope(emptyScope, () => pythonFunctionTooLong.run(cwd, { targetFiles: [shortTarget] }));
|
|
61
|
+
expect(result.signals).toHaveLength(0);
|
|
62
|
+
});
|
|
63
|
+
it('exposes a stable check config (slug/analysisMode/tags)', () => {
|
|
64
|
+
expect(pythonFunctionTooLong.config.slug).toBe('python-function-too-long');
|
|
65
|
+
expect(pythonFunctionTooLong.config.analysisMode).toBe('analyze');
|
|
66
|
+
expect(pythonFunctionTooLong.config.tags).toContain('python');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=function-too-long.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-too-long.test.js","sourceRoot":"","sources":["../../src/__tests__/function-too-long.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE/F,+DAA+D;AAC/D,SAAS,UAAU,CAAC,IAAY,EAAE,SAAiB;IACjD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxF,OAAO,OAAO,IAAI,QAAQ,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,UAAU,GAAG,sBAAsB,CAAC,UAAU,CA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3,"file":"no-bare-except.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/no-bare-except.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { analyzeBareExcept } from '../checks/no-bare-except.js';
|
|
3
|
+
describe('analyzeBareExcept', () => {
|
|
4
|
+
it('flags `except:` on its own line', () => {
|
|
5
|
+
const src = `try:
|
|
6
|
+
risky()
|
|
7
|
+
except:
|
|
8
|
+
pass`;
|
|
9
|
+
const violations = analyzeBareExcept(src);
|
|
10
|
+
expect(violations.length).toBe(1);
|
|
11
|
+
expect(violations[0]?.message).toContain('Bare');
|
|
12
|
+
expect(violations[0]?.severity).toBe('warning');
|
|
13
|
+
expect(violations[0]?.line).toBe(3);
|
|
14
|
+
});
|
|
15
|
+
it('returns an empty list for code without except clauses', () => {
|
|
16
|
+
expect(analyzeBareExcept('def foo(): return 1\n')).toEqual([]);
|
|
17
|
+
});
|
|
18
|
+
it('does not flag `except Exception:`', () => {
|
|
19
|
+
const src = `try:
|
|
20
|
+
risky()
|
|
21
|
+
except Exception:
|
|
22
|
+
pass`;
|
|
23
|
+
const violations = analyzeBareExcept(src);
|
|
24
|
+
expect(violations.length).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
it('does not flag `except (TypeError, ValueError):`', () => {
|
|
27
|
+
const src = `try:
|
|
28
|
+
risky()
|
|
29
|
+
except (TypeError, ValueError):
|
|
30
|
+
pass`;
|
|
31
|
+
const violations = analyzeBareExcept(src);
|
|
32
|
+
expect(violations.length).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
it('does not flag `except Exception as e:`', () => {
|
|
35
|
+
const src = `try:
|
|
36
|
+
risky()
|
|
37
|
+
except Exception as e:
|
|
38
|
+
log(e)`;
|
|
39
|
+
const violations = analyzeBareExcept(src);
|
|
40
|
+
expect(violations.length).toBe(0);
|
|
41
|
+
});
|
|
42
|
+
it('reports correct line number for indented bare except', () => {
|
|
43
|
+
const src = `def fn():
|
|
44
|
+
try:
|
|
45
|
+
risky()
|
|
46
|
+
except:
|
|
47
|
+
pass`;
|
|
48
|
+
const violations = analyzeBareExcept(src);
|
|
49
|
+
expect(violations.length).toBe(1);
|
|
50
|
+
expect(violations[0]?.line).toBe(4);
|
|
51
|
+
});
|
|
52
|
+
it('flags multiple bare excepts independently', () => {
|
|
53
|
+
const src = `try:
|
|
54
|
+
a()
|
|
55
|
+
except:
|
|
56
|
+
pass
|
|
57
|
+
try:
|
|
58
|
+
b()
|
|
59
|
+
except:
|
|
60
|
+
pass`;
|
|
61
|
+
const violations = analyzeBareExcept(src);
|
|
62
|
+
expect(violations.length).toBe(2);
|
|
63
|
+
expect(violations[0]?.line).toBe(3);
|
|
64
|
+
expect(violations[1]?.line).toBe(7);
|
|
65
|
+
});
|
|
66
|
+
it('tolerates whitespace between `except` and `:`', () => {
|
|
67
|
+
const src = `try:
|
|
68
|
+
a()
|
|
69
|
+
except :
|
|
70
|
+
pass`;
|
|
71
|
+
const violations = analyzeBareExcept(src);
|
|
72
|
+
expect(violations.length).toBe(1);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=no-bare-except.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-bare-except.test.js","sourceRoot":"","sources":["../../src/__tests__/no-bare-except.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,GAAG,GAAG;;;SAGP,CAAC;QACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,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EH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,GAAG,GAAG;;;;aAIH,CAAC;QACV,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACnD,MAAM,GAAG,GAAG;;;;;;;SAOP,CAAC;QACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;QACvD,MAAM,GAAG,GAAG;;;SAGP,CAAC;QACN,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/run.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Execute the check end-to-end so the closures inside the
|
|
3
|
+
* `defineCheck({...})` config (specifically `analyze`) are invoked.
|
|
4
|
+
*
|
|
5
|
+
* The pure analyzer is exercised by `no-bare-except.test.ts`. This
|
|
6
|
+
* file's purpose is execution coverage for the un-called closures
|
|
7
|
+
* declared inside the check definition.
|
|
8
|
+
*/
|
|
9
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { tmpdir } from 'node:os';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { LanguageRegistry, RunScope, runWithScope } from '@opensip-cli/core';
|
|
13
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
14
|
+
import { noBareExcept } from '../checks/no-bare-except.js';
|
|
15
|
+
// applyContentFilter resolves the file's adapter via `currentScope()?.languages`
|
|
16
|
+
// (default registry global was removed in T1 cleanup). With no adapter
|
|
17
|
+
// registered for `.py`, applyContentFilter falls through to raw content.
|
|
18
|
+
// Wrap the call in an empty scope so dispatch reaches that no-adapter branch.
|
|
19
|
+
const emptyScope = new RunScope({ languages: new LanguageRegistry() });
|
|
20
|
+
let cwd;
|
|
21
|
+
let target;
|
|
22
|
+
beforeAll(() => {
|
|
23
|
+
cwd = mkdtempSync(join(tmpdir(), 'opensip-checks-python-cov-'));
|
|
24
|
+
target = join(cwd, 'demo.py');
|
|
25
|
+
writeFileSync(target, [
|
|
26
|
+
'def main():',
|
|
27
|
+
' try:',
|
|
28
|
+
' do_work()',
|
|
29
|
+
' except:',
|
|
30
|
+
' pass',
|
|
31
|
+
'',
|
|
32
|
+
'def do_work():',
|
|
33
|
+
' return 1',
|
|
34
|
+
'',
|
|
35
|
+
].join('\n'));
|
|
36
|
+
});
|
|
37
|
+
afterAll(() => {
|
|
38
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
39
|
+
});
|
|
40
|
+
describe('noBareExcept.run() execution coverage', () => {
|
|
41
|
+
it('runs end-to-end against a Python fixture with a bare except', async () => {
|
|
42
|
+
const result = await runWithScope(emptyScope, () => noBareExcept.run(cwd, { targetFiles: [target] }));
|
|
43
|
+
expect(result).toBeDefined();
|
|
44
|
+
expect(Array.isArray(result.signals)).toBe(true);
|
|
45
|
+
expect(typeof result.errors).toBe('number');
|
|
46
|
+
expect(typeof result.warnings).toBe('number');
|
|
47
|
+
// The fixture contains exactly one bare `except:` โ at minimum one signal.
|
|
48
|
+
expect(result.signals.length).toBeGreaterThanOrEqual(1);
|
|
49
|
+
});
|
|
50
|
+
it('exposes a stable check config (slug/analysisMode/tags)', () => {
|
|
51
|
+
expect(noBareExcept.config.slug).toBe('python-no-bare-except');
|
|
52
|
+
expect(noBareExcept.config.analysisMode).toBe('analyze');
|
|
53
|
+
expect(noBareExcept.config.tags).toContain('python');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=run.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.test.js","sourceRoot":"","sources":["../../src/__tests__/run.test.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,iFAAiF;AACjF,uEAAuE;AACvE,yEAAyE;AACzE,8EAA8E;AAC9E,MAAM,UAAU,GAAG,IAAI,QAAQ,CAAC,EAAE,SAAS,EAAE,IAAI,gBAAgB,EAAE,EAAE,CAAC,CAAC;AAEvE,IAAI,GAAW,CAAC;AAChB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BAAsB,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAC/D,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Flag Python functions that exceed a line budget.
|
|
3
|
+
*
|
|
4
|
+
* Parses the file with `@opensip-cli/lang-python`'s `getSharedTree` (cached) and
|
|
5
|
+
* walks the tree-sitter AST: every `function_definition` whose line span exceeds
|
|
6
|
+
* the budget is reported. Long functions are harder to read and test; extracting
|
|
7
|
+
* helpers keeps them in scope.
|
|
8
|
+
*/
|
|
9
|
+
import { type CheckViolation } from '@opensip-cli/fitness';
|
|
10
|
+
/**
|
|
11
|
+
* Pure analysis function. Exported so unit tests can exercise the detection
|
|
12
|
+
* logic directly.
|
|
13
|
+
*/
|
|
14
|
+
export declare function analyzeFunctionTooLong(content: string, filePath: string): CheckViolation[];
|
|
15
|
+
export declare const pythonFunctionTooLong: import("@opensip-cli/fitness").Check;
|
|
16
|
+
//# sourceMappingURL=function-too-long.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-too-long.d.ts","sourceRoot":"","sources":["../../src/checks/function-too-long.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAWxE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CA4B1F;AAED,eAAO,MAAM,qBAAqB,sCAOhC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Flag Python functions that exceed a line budget.
|
|
3
|
+
*
|
|
4
|
+
* Parses the file with `@opensip-cli/lang-python`'s `getSharedTree` (cached) and
|
|
5
|
+
* walks the tree-sitter AST: every `function_definition` whose line span exceeds
|
|
6
|
+
* the budget is reported. Long functions are harder to read and test; extracting
|
|
7
|
+
* helpers keeps them in scope.
|
|
8
|
+
*/
|
|
9
|
+
import { defineCheck } from '@opensip-cli/fitness';
|
|
10
|
+
import { getLineNumber, getSharedTree, isFunction, nameOf, walkNodes, } from '@opensip-cli/lang-python';
|
|
11
|
+
const MAX_FUNCTION_LINES = 50;
|
|
12
|
+
/**
|
|
13
|
+
* Pure analysis function. Exported so unit tests can exercise the detection
|
|
14
|
+
* logic directly.
|
|
15
|
+
*/
|
|
16
|
+
export function analyzeFunctionTooLong(content, filePath) {
|
|
17
|
+
const violations = [];
|
|
18
|
+
const parsed = getSharedTree(filePath, content);
|
|
19
|
+
// Defensive: tree-sitter recovers from any string into a (partial) tree, so
|
|
20
|
+
// getSharedTree never returns null here โ unreachable from a string input.
|
|
21
|
+
/* v8 ignore start */
|
|
22
|
+
if (!parsed)
|
|
23
|
+
return violations;
|
|
24
|
+
/* v8 ignore stop */
|
|
25
|
+
walkNodes(parsed.tree.rootNode, (node) => {
|
|
26
|
+
if (!isFunction(node))
|
|
27
|
+
return;
|
|
28
|
+
const span = node.endPosition.row - node.startPosition.row + 1;
|
|
29
|
+
if (span <= MAX_FUNCTION_LINES)
|
|
30
|
+
return;
|
|
31
|
+
// Defensive: a Python `function_definition` node always carries a `name`
|
|
32
|
+
// field (without it tree-sitter does not classify the node as a function),
|
|
33
|
+
// so the `?? '<anonymous>'` fallback arm is unreachable in practice.
|
|
34
|
+
/* v8 ignore start */
|
|
35
|
+
const name = nameOf(node) ?? '<anonymous>';
|
|
36
|
+
/* v8 ignore stop */
|
|
37
|
+
violations.push({
|
|
38
|
+
message: `Function \`${name}\` is ${span} lines long (max ${MAX_FUNCTION_LINES}).`,
|
|
39
|
+
severity: 'warning',
|
|
40
|
+
line: getLineNumber(node),
|
|
41
|
+
suggestion: 'Extract helpers to bring the function under the line budget.',
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return violations;
|
|
45
|
+
}
|
|
46
|
+
export const pythonFunctionTooLong = defineCheck({
|
|
47
|
+
id: '2063a0cb-a1be-47da-b947-9f938ef485b9',
|
|
48
|
+
slug: 'python-function-too-long',
|
|
49
|
+
description: 'Python functions should stay under a line budget for readability and testability',
|
|
50
|
+
scope: { languages: ['python'], concerns: [] },
|
|
51
|
+
tags: ['quality', 'python', 'complexity'],
|
|
52
|
+
analyze: (content, filePath) => analyzeFunctionTooLong(content, filePath),
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=function-too-long.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-too-long.js","sourceRoot":"","sources":["../../src/checks/function-too-long.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,MAAM,EACN,SAAS,GACV,MAAM,0BAA0B,CAAC;AAElC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe,EAAE,QAAgB;IACtE,MAAM,UAAU,GAAqB,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChD,4EAA4E;IAC5E,2EAA2E;IAC3E,qBAAqB;IACrB,IAAI,CAAC,MAAM;QAAE,OAAO,UAAU,CAAC;IAC/B,oBAAoB;IAEpB,S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
|
+
* usually meant to propagate โ KeyboardInterrupt, SystemExit, and any
|
|
6
|
+
* subclass of BaseException. This makes programs harder to terminate
|
|
7
|
+
* and hides bugs. The Python style guide and most lint tools (ruff
|
|
8
|
+
* E722, pylint W0702) flag this. Always specify what you're catching,
|
|
9
|
+
* even if it's just `except Exception:`.
|
|
10
|
+
*
|
|
11
|
+
* Detection is line-pattern based: a line whose first non-whitespace
|
|
12
|
+
* characters are `except:` (with optional whitespace before the colon).
|
|
13
|
+
* The check uses `strip-strings` content filtering so a literal like
|
|
14
|
+
* `"except:"` inside a docstring or string doesn't false-fire.
|
|
15
|
+
*/
|
|
16
|
+
import { type CheckViolation } from '@opensip-cli/fitness';
|
|
17
|
+
/**
|
|
18
|
+
* Pure analysis function. Exported so unit tests can exercise the
|
|
19
|
+
* detection logic without standing up the full Check framework.
|
|
20
|
+
*/
|
|
21
|
+
export declare function analyzeBareExcept(content: string): CheckViolation[];
|
|
22
|
+
export declare const noBareExcept: import("@opensip-cli/fitness").Check;
|
|
23
|
+
//# sourceMappingURL=no-bare-except.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-bare-except.d.ts","sourceRoot":"","sources":["../../src/checks/no-bare-except.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAKxE;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE,CAgBnE;AAED,eAAO,MAAM,YAAY,sCAWvB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Flag bare `except:` clauses in Python.
|
|
3
|
+
*
|
|
4
|
+
* A bare `except:` catches every exception, including ones that are
|
|
5
|
+
* usually meant to propagate โ KeyboardInterrupt, SystemExit, and any
|
|
6
|
+
* subclass of BaseException. This makes programs harder to terminate
|
|
7
|
+
* and hides bugs. The Python style guide and most lint tools (ruff
|
|
8
|
+
* E722, pylint W0702) flag this. Always specify what you're catching,
|
|
9
|
+
* even if it's just `except Exception:`.
|
|
10
|
+
*
|
|
11
|
+
* Detection is line-pattern based: a line whose first non-whitespace
|
|
12
|
+
* characters are `except:` (with optional whitespace before the colon).
|
|
13
|
+
* The check uses `strip-strings` content filtering so a literal like
|
|
14
|
+
* `"except:"` inside a docstring or string doesn't false-fire.
|
|
15
|
+
*/
|
|
16
|
+
import { defineCheck } from '@opensip-cli/fitness';
|
|
17
|
+
// eslint-disable-next-line sonarjs/slow-regex -- anchored, bounded line scan; \s* on bounded leading whitespace is safe
|
|
18
|
+
const BARE_EXCEPT_PATTERN = /^\s*except\s*:/gm;
|
|
19
|
+
/**
|
|
20
|
+
* Pure analysis function. Exported so unit tests can exercise the
|
|
21
|
+
* detection logic without standing up the full Check framework.
|
|
22
|
+
*/
|
|
23
|
+
export function analyzeBareExcept(content) {
|
|
24
|
+
const violations = [];
|
|
25
|
+
BARE_EXCEPT_PATTERN.lastIndex = 0;
|
|
26
|
+
let match;
|
|
27
|
+
while ((match = BARE_EXCEPT_PATTERN.exec(content)) !== null) {
|
|
28
|
+
// Compute 1-based line number from match index.
|
|
29
|
+
const upto = content.slice(0, match.index);
|
|
30
|
+
const line = upto.split('\n').length;
|
|
31
|
+
violations.push({
|
|
32
|
+
message: 'Bare `except:` catches BaseException โ including KeyboardInterrupt and SystemExit',
|
|
33
|
+
severity: 'warning',
|
|
34
|
+
line,
|
|
35
|
+
suggestion: 'Catch a specific exception (e.g. `except Exception:` or a narrower type)',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return violations;
|
|
39
|
+
}
|
|
40
|
+
export const noBareExcept = defineCheck({
|
|
41
|
+
id: '1e273f06-7960-462d-b88c-dc9169f78cf8',
|
|
42
|
+
slug: 'python-no-bare-except',
|
|
43
|
+
description: 'Bare except clauses catch system-exiting exceptions like KeyboardInterrupt',
|
|
44
|
+
scope: { languages: ['python'], concerns: [] },
|
|
45
|
+
tags: ['quality', 'python'],
|
|
46
|
+
// Use 'strip-strings' so a literal `"except:"` inside a string is
|
|
47
|
+
// not matched. Comments are still visible โ but `# except:` won't
|
|
48
|
+
// match the leading-whitespace anchor since `#` is in the way.
|
|
49
|
+
contentFilter: 'strip-strings',
|
|
50
|
+
analyze: (content) => analyzeBareExcept(content),
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=no-bare-except.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-bare-except.js","sourceRoot":"","sources":["../../src/checks/no-bare-except.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AAExE,wHAAwH;AACxH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,MAAM,UAAU,GAAqB,EAAE,CAAC;IACxC,mBAAmB,CAAC,SAAS,GAAG,CAAC,CAAC;IAClC,IAAI,KAA6B,CAAC;IAClC,OAAO,CAAC,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5D,gDAAgD;QAChD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QACrC,UAAU,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,mFAAmF;YAC5F,QAAQ,EAAE,SAAS;YACnB,IAAI;YACJ,UAAU,EAAE,0EAA0E;SACvF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,EAAE,EAAE,sCAAsC;IAC1C,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EAAE,4EAA4E;IACzF,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC9C,IAAI,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;IAC3B,kEAAkE;IAClE,kEAAkE;IAClE,+DAA+D;IAC/D,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC;CACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display metadata for Python fitness checks.
|
|
3
|
+
*
|
|
4
|
+
* Maps each check slug to its [icon, displayName] tuple for CLI/report
|
|
5
|
+
* rendering. Keys must match the `slug` of the corresponding check.
|
|
6
|
+
*/
|
|
7
|
+
import type { CheckDisplayEntry } from '@opensip-cli/fitness';
|
|
8
|
+
export declare const checkDisplay: Readonly<Record<string, CheckDisplayEntry>>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAEpE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/display/index.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,YAAY,GAAgD;IACvE,gBAAgB,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC;CAC3C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,wCAAyE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { applyCheckDisplay } from '@opensip-cli/fitness';
|
|
2
|
+
import { pythonFunctionTooLong } from './checks/function-too-long.js';
|
|
3
|
+
import { noBareExcept } from './checks/no-bare-except.js';
|
|
4
|
+
import { checkDisplay } from './display/index.js';
|
|
5
|
+
// Display (icon + name) is folded ONTO each check from this pack's `checkDisplay`
|
|
6
|
+
// authoring map (ยง5.3) โ display travels on `check.config`, no separate export.
|
|
7
|
+
export const checks = applyCheckDisplay([noBareExcept, pythonFunctionTooLong], checkDisplay);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,kFAAkF;AAClF,gFAAgF;AAChF,MAAM,CAAC,MAAM,MAAM,GAAG,iBAAiB,CAAC,CAAC,YAAY,EAAE,qBAAqB,CAAC,EAAE,YAAY,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opensip-cli/checks-python",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Python fitness checks for opensip-cli",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"opensip-cli",
|
|
8
|
+
"static-analysis",
|
|
9
|
+
"code-quality",
|
|
10
|
+
"fitness-checks",
|
|
11
|
+
"linting",
|
|
12
|
+
"python"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/opensip-ai/opensip-cli.git",
|
|
17
|
+
"directory": "packages/fitness/checks-python"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/opensip-ai/opensip-cli",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/opensip-ai/opensip-cli/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"opensipTools": {
|
|
25
|
+
"kind": "fit-pack"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@opensip-cli/lang-python": "0.1.0",
|
|
39
|
+
"@opensip-cli/fitness": "0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^24.13.2",
|
|
43
|
+
"vitest": "^4.1.8",
|
|
44
|
+
"@opensip-cli/test-support": "0.1.0",
|
|
45
|
+
"@opensip-cli/core": "0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"test": "vitest run --passWithNoTests",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"clean": "rm -rf dist"
|
|
52
|
+
}
|
|
53
|
+
}
|