@flint.fyi/plugin-flint 0.1.0 → 0.2.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/CHANGELOG.md +6 -0
- package/lib/findProperty.d.ts +2 -0
- package/lib/findProperty.js +7 -0
- package/lib/flint.d.ts +4 -0
- package/lib/flint.js +2 -1
- package/lib/getRuleTesterDescribedCases.d.ts +5 -0
- package/lib/getRuleTesterDescribedCases.js +31 -0
- package/lib/parseTestCases.d.ts +4 -0
- package/lib/parseTestCases.js +62 -0
- package/lib/rules/invalidCodeLines.d.ts +6 -0
- package/lib/rules/invalidCodeLines.js +71 -0
- package/lib/rules/invalidCodeLines.test.d.ts +1 -0
- package/lib/rules/invalidCodeLines.test.js +197 -0
- package/lib/rules/testCaseDuplicates.js +2 -2
- package/lib/types.d.ts +17 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
- package/src/findProperty.ts +15 -0
- package/src/flint.ts +2 -1
- package/src/getRuleTesterDescribedCases.ts +48 -0
- package/src/parseTestCases.ts +96 -0
- package/src/rules/invalidCodeLines.test.ts +198 -0
- package/src/rules/invalidCodeLines.ts +84 -0
- package/src/rules/testCaseDuplicates.ts +4 -5
- package/src/types.ts +22 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/getRuleTesterDescribedCases.d.ts +0 -9
- package/lib/rules/getRuleTesterDescribedCases.js +0 -59
- package/src/rules/getRuleTesterDescribedCases.ts +0 -102
- /package/lib/{rules/tsAstToLiteral.d.ts → tsAstToLiteral.d.ts} +0 -0
- /package/lib/{rules/tsAstToLiteral.js → tsAstToLiteral.js} +0 -0
- /package/src/{rules/tsAstToLiteral.ts → tsAstToLiteral.ts} +0 -0
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { TestCase } from "@flint.fyi/rule-tester";
|
|
2
|
-
import { isTruthy } from "@flint.fyi/utils";
|
|
3
|
-
import * as ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { tsAstToLiteral } from "./tsAstToLiteral.js";
|
|
6
|
-
|
|
7
|
-
export interface ParsedTestCase extends TestCase {
|
|
8
|
-
node: ts.Node;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function getRuleTesterDescribedCases(node: ts.CallExpression) {
|
|
12
|
-
if (
|
|
13
|
-
!ts.isPropertyAccessExpression(node.expression) ||
|
|
14
|
-
!ts.isIdentifier(node.expression.expression) ||
|
|
15
|
-
!ts.isIdentifier(node.expression.name) ||
|
|
16
|
-
node.expression.name.text !== "describe" ||
|
|
17
|
-
node.arguments.length !== 2
|
|
18
|
-
) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// TODO: Check node.expression.expression's type for being a RuleTester
|
|
23
|
-
// https://github.com/JoshuaKGoldberg/flint/issues/152
|
|
24
|
-
|
|
25
|
-
const argument = node.arguments[1];
|
|
26
|
-
if (!ts.isObjectLiteralExpression(argument)) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const invalid = findProperty(
|
|
31
|
-
argument.properties,
|
|
32
|
-
"invalid",
|
|
33
|
-
ts.isArrayLiteralExpression,
|
|
34
|
-
);
|
|
35
|
-
if (!invalid) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const valid = findProperty(
|
|
40
|
-
argument.properties,
|
|
41
|
-
"valid",
|
|
42
|
-
ts.isArrayLiteralExpression,
|
|
43
|
-
);
|
|
44
|
-
if (!valid) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
invalid: invalid.elements.map(parseTestCase).filter(isTruthy),
|
|
50
|
-
valid: valid.elements.map(parseTestCase).filter(isTruthy),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function findProperty<Node extends ts.Node>(
|
|
55
|
-
properties: ts.NodeArray<ts.ObjectLiteralElementLike>,
|
|
56
|
-
name: string,
|
|
57
|
-
predicate: (node: ts.Node) => node is Node,
|
|
58
|
-
) {
|
|
59
|
-
return properties.find(
|
|
60
|
-
(property): property is ts.PropertyAssignment & { initializer: Node } =>
|
|
61
|
-
ts.isPropertyAssignment(property) &&
|
|
62
|
-
ts.isIdentifier(property.name) &&
|
|
63
|
-
property.name.text === name &&
|
|
64
|
-
predicate(property.initializer),
|
|
65
|
-
)?.initializer;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function parseTestCase(node: ts.Expression): ParsedTestCase | undefined {
|
|
69
|
-
if (ts.isStringLiteralLike(node)) {
|
|
70
|
-
return {
|
|
71
|
-
code: node.text,
|
|
72
|
-
node,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!ts.isObjectLiteralExpression(node)) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const code = findProperty(node.properties, "code", ts.isStringLiteralLike);
|
|
81
|
-
if (!code) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const fileName = findProperty(
|
|
86
|
-
node.properties,
|
|
87
|
-
"fileName",
|
|
88
|
-
ts.isStringLiteralLike,
|
|
89
|
-
);
|
|
90
|
-
const options = findProperty(
|
|
91
|
-
node.properties,
|
|
92
|
-
"options",
|
|
93
|
-
ts.isObjectLiteralExpression,
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
code: code.text,
|
|
98
|
-
fileName: fileName?.text,
|
|
99
|
-
node,
|
|
100
|
-
options: options && tsAstToLiteral(options),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|