@voidh4x0r/slopgate 0.0.0-stage → 0.1.1

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/LICENSE +21 -0
  3. package/README.md +304 -2
  4. package/dist/ast.d.ts +29 -0
  5. package/dist/ast.js +3 -0
  6. package/dist/baseline.d.ts +33 -0
  7. package/dist/baseline.js +104 -0
  8. package/dist/cli.d.ts +9 -0
  9. package/dist/cli.js +487 -0
  10. package/dist/config.d.ts +25 -0
  11. package/dist/config.js +91 -0
  12. package/dist/data/python-stdlib.d.ts +21 -0
  13. package/dist/data/python-stdlib.js +92 -0
  14. package/dist/deps.d.ts +8 -0
  15. package/dist/deps.js +491 -0
  16. package/dist/diff.d.ts +30 -0
  17. package/dist/diff.js +217 -0
  18. package/dist/engine.d.ts +15 -0
  19. package/dist/engine.js +169 -0
  20. package/dist/files.d.ts +33 -0
  21. package/dist/files.js +214 -0
  22. package/dist/mcp.d.ts +41 -0
  23. package/dist/mcp.js +226 -0
  24. package/dist/parser.d.ts +3 -0
  25. package/dist/parser.js +45 -0
  26. package/dist/reporters/github.d.ts +2 -0
  27. package/dist/reporters/github.js +44 -0
  28. package/dist/reporters/json.d.ts +10 -0
  29. package/dist/reporters/json.js +36 -0
  30. package/dist/reporters/pretty.d.ts +12 -0
  31. package/dist/reporters/pretty.js +103 -0
  32. package/dist/reporters/sarif.d.ts +2 -0
  33. package/dist/reporters/sarif.js +75 -0
  34. package/dist/rules/helpers.d.ts +53 -0
  35. package/dist/rules/helpers.js +178 -0
  36. package/dist/rules/index.d.ts +3 -0
  37. package/dist/rules/index.js +4 -0
  38. package/dist/rules/python.d.ts +2 -0
  39. package/dist/rules/python.js +632 -0
  40. package/dist/rules/typescript.d.ts +2 -0
  41. package/dist/rules/typescript.js +563 -0
  42. package/dist/suppress.d.ts +12 -0
  43. package/dist/suppress.js +52 -0
  44. package/dist/types.d.ts +95 -0
  45. package/dist/types.js +1 -0
  46. package/grammars/README.md +28 -0
  47. package/grammars/tree-sitter-python.wasm +0 -0
  48. package/grammars/tree-sitter-tsx.wasm +0 -0
  49. package/grammars/tree-sitter-typescript.wasm +0 -0
  50. package/package.json +61 -4
@@ -0,0 +1,178 @@
1
+ export function startOf(node) {
2
+ return { line: node.startPosition.row + 1, column: node.startPosition.column + 1 };
3
+ }
4
+ export function endOf(node) {
5
+ return { line: node.endPosition.row + 1, column: node.endPosition.column + 1 };
6
+ }
7
+ /** Trimmed first line of a node, capped for display. */
8
+ export function snippetOf(_ctx, node) {
9
+ const firstLine = node.text.split(/\r?\n/, 1)[0] ?? '';
10
+ const trimmed = firstLine.trim();
11
+ if (trimmed.length <= 160)
12
+ return trimmed;
13
+ return trimmed.slice(0, 157) + '...';
14
+ }
15
+ export function isComment(node) {
16
+ return node.type === 'comment' || node.type === 'line_comment' || node.type === 'block_comment';
17
+ }
18
+ /** Named children that are actual statements (comments excluded). */
19
+ export function statementsOf(block) {
20
+ return block.namedChildren.filter((child) => !isComment(child));
21
+ }
22
+ /** Depth-limited, allocation-light walk over named children. */
23
+ export function walk(node, visit, maxDepth = 400) {
24
+ const stack = [{ node, depth: 0 }];
25
+ while (stack.length > 0) {
26
+ const entry = stack.pop();
27
+ if (!entry)
28
+ break;
29
+ const { node: current, depth } = entry;
30
+ const descend = visit(current, depth);
31
+ if (descend === false || depth >= maxDepth)
32
+ continue;
33
+ const children = current.namedChildren;
34
+ for (let i = children.length - 1; i >= 0; i -= 1) {
35
+ const child = children[i];
36
+ if (child)
37
+ stack.push({ node: child, depth: depth + 1 });
38
+ }
39
+ }
40
+ }
41
+ export function descendantsOfType(root, types) {
42
+ const wanted = new Set(types);
43
+ const found = [];
44
+ walk(root, (node) => {
45
+ if (wanted.has(node.type))
46
+ found.push(node);
47
+ });
48
+ return found;
49
+ }
50
+ /** Nearest ancestor whose type is in `types` (excluding the node itself). */
51
+ export function ancestorOfType(node, types) {
52
+ const wanted = new Set(types);
53
+ let current = node.parent;
54
+ while (current) {
55
+ if (wanted.has(current.type))
56
+ return current;
57
+ current = current.parent;
58
+ }
59
+ return undefined;
60
+ }
61
+ /**
62
+ * Real comment nodes in the tree. A `//` inside a string or a `#` inside a URL
63
+ * is not a comment, so rules must not scan raw source text for these markers.
64
+ */
65
+ export function collectCommentRanges(root) {
66
+ return descendantsOfType(root, ['comment', 'line_comment', 'block_comment']).map((node) => ({
67
+ startLine: node.startPosition.row + 1,
68
+ endLine: node.endPosition.row + 1,
69
+ }));
70
+ }
71
+ /**
72
+ * True when a real comment overlaps the given line range. Comments before the
73
+ * first statement of a block are often attached to the parent node, so callers
74
+ * pass the enclosing statement's range (for example the whole `try`, not just
75
+ * the `except` clause).
76
+ */
77
+ export function hasCommentBetween(ctx, fromLine, toLine) {
78
+ return ctx.comments.some((comment) => comment.startLine <= toLine && comment.endLine >= fromLine);
79
+ }
80
+ export function collapseWhitespace(value) {
81
+ return value.replace(/\s+/g, ' ').trim();
82
+ }
83
+ export function truncate(value, max) {
84
+ const single = collapseWhitespace(value);
85
+ return single.length <= max ? single : single.slice(0, max - 3) + '...';
86
+ }
87
+ /**
88
+ * Test files and fixtures are full of intentional stubs, dead branches and
89
+ * swallowed errors (they are testing those behaviours). Rules that are not
90
+ * test-specific skip them; `py/noop-test` and `ts/noop-test` are the rules
91
+ * that look at tests themselves.
92
+ */
93
+ export function isTestPath(file) {
94
+ const lower = file.toLowerCase();
95
+ const parts = lower.split('/');
96
+ const base = parts[parts.length - 1] ?? '';
97
+ if (/^test_.*\.pyi?$/.test(base) || /_tests?\.pyi?$/.test(base))
98
+ return true;
99
+ if (/\.(test|spec)\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(base))
100
+ return true;
101
+ // Test/build infrastructure that pytest, nox and Sphinx import directly.
102
+ if (base === 'conftest.py' || base === 'noxfile.py')
103
+ return true;
104
+ if (lower === 'docs/conf.py' || lower.endsWith('/docs/conf.py'))
105
+ return true;
106
+ return parts.some((part) => part === 'test' || part === 'tests' || part === '__tests__');
107
+ }
108
+ /** Type stubs declare every function with `...`; stub rules must not fire. */
109
+ export function isStubFile(file) {
110
+ return file.toLowerCase().endsWith('.pyi');
111
+ }
112
+ /**
113
+ * Modules whose whole purpose is to provide no-op stand-ins (CPython's
114
+ * `multiprocessing/dummy`, single-threaded shims). Their empty bodies are the
115
+ * implementation, not an unfinished one.
116
+ */
117
+ export function isNoopModulePath(file) {
118
+ return file
119
+ .toLowerCase()
120
+ .split('/')
121
+ .some((part) => /dummy|noop|no-op|shims?/.test(part));
122
+ }
123
+ /** True when the file name follows a test-module convention. */
124
+ export function looksLikeTestModule(file) {
125
+ const base = (file.split('/').pop() ?? '').toLowerCase();
126
+ return (/^test_.*\.pyi?$/.test(base) ||
127
+ /_tests?\.pyi?$/.test(base) ||
128
+ /\.(test|spec)\.(ts|tsx|js|jsx|mts|cts|mjs|cjs)$/.test(base));
129
+ }
130
+ /** Text of the function's leading docstring, if it has one. */
131
+ export function docstringOf(fn) {
132
+ const body = fn.childForFieldName('body');
133
+ const first = body?.namedChildren.find((child) => !isComment(child));
134
+ if (first?.type !== 'expression_statement')
135
+ return undefined;
136
+ const value = first.namedChildren[0];
137
+ return value?.type === 'string' ? value.text : undefined;
138
+ }
139
+ /** True when the function's body starts with a docstring. */
140
+ export function hasDocstring(fn) {
141
+ const body = fn.childForFieldName('body');
142
+ const first = body?.namedChildren.find((child) => !isComment(child));
143
+ return first?.type === 'expression_statement' && first.namedChildren[0]?.type === 'string';
144
+ }
145
+ /** True when the node sits inside `if __name__ == "__main__":`. */
146
+ export function insideMainGuard(node) {
147
+ let current = node.parent;
148
+ while (current) {
149
+ if (current.type === 'if_statement') {
150
+ const condition = current.childForFieldName('condition');
151
+ if (condition && /__name__/.test(condition.text))
152
+ return true;
153
+ }
154
+ current = current.parent;
155
+ }
156
+ return false;
157
+ }
158
+ const CLEANUP_NAMES = new Set([
159
+ 'close',
160
+ '__del__',
161
+ '__exit__',
162
+ 'cleanup',
163
+ '_cleanup',
164
+ 'shutdown',
165
+ 'stop',
166
+ 'cancel',
167
+ 'dispose',
168
+ 'finalize',
169
+ 'teardown',
170
+ 'tearDown',
171
+ 'reset',
172
+ ]);
173
+ /** Cleanup/finaliser code swallows errors on purpose; treat it as medium. */
174
+ export function insideCleanupFunction(node) {
175
+ const fn = ancestorOfType(node, ['function_definition', 'method_definition', 'function_declaration']);
176
+ const name = fn?.childForFieldName('name')?.text;
177
+ return name !== undefined && name !== null && CLEANUP_NAMES.has(name);
178
+ }
@@ -0,0 +1,3 @@
1
+ import type { Rule } from '../types.ts';
2
+ export declare const ALL_RULES: readonly Rule[];
3
+ export declare const RULE_BY_ID: ReadonlyMap<string, Rule>;
@@ -0,0 +1,4 @@
1
+ import { pythonRules } from "./python.js";
2
+ import { typescriptRules } from "./typescript.js";
3
+ export const ALL_RULES = [...pythonRules, ...typescriptRules];
4
+ export const RULE_BY_ID = new Map(ALL_RULES.map((rule) => [rule.meta.id, rule]));
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../types.ts';
2
+ export declare const pythonRules: Rule[];