@flint.fyi/plugin-flint 0.2.0 → 0.2.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 (40) hide show
  1. package/lib/findProperty.d.ts +1 -0
  2. package/lib/findProperty.js +1 -0
  3. package/lib/flint.d.ts +3 -2
  4. package/lib/flint.js +2 -1
  5. package/lib/getRuleTesterDescribedCases.d.ts +1 -0
  6. package/lib/getRuleTesterDescribedCases.js +2 -1
  7. package/lib/index.d.ts +1 -0
  8. package/lib/index.js +1 -0
  9. package/lib/parseTestCases.d.ts +1 -0
  10. package/lib/parseTestCases.js +1 -0
  11. package/lib/rules/invalidCodeLines.d.ts +2 -1
  12. package/lib/rules/invalidCodeLines.js +16 -10
  13. package/lib/rules/invalidCodeLines.test.d.ts +1 -0
  14. package/lib/rules/invalidCodeLines.test.js +1 -0
  15. package/lib/rules/ruleTester.d.ts +1 -0
  16. package/lib/rules/ruleTester.js +6 -1
  17. package/lib/rules/testCaseDuplicates.d.ts +2 -1
  18. package/lib/rules/testCaseDuplicates.js +6 -5
  19. package/lib/rules/testCaseDuplicates.test.d.ts +1 -0
  20. package/lib/rules/testCaseDuplicates.test.js +1 -0
  21. package/lib/tsAstToLiteral.d.ts +1 -0
  22. package/lib/tsAstToLiteral.js +1 -0
  23. package/lib/types.d.ts +1 -0
  24. package/lib/types.js +1 -0
  25. package/package.json +17 -7
  26. package/CHANGELOG.md +0 -36
  27. package/src/findProperty.ts +0 -15
  28. package/src/flint.ts +0 -9
  29. package/src/getRuleTesterDescribedCases.ts +0 -48
  30. package/src/index.ts +0 -1
  31. package/src/parseTestCases.ts +0 -96
  32. package/src/rules/invalidCodeLines.test.ts +0 -198
  33. package/src/rules/invalidCodeLines.ts +0 -84
  34. package/src/rules/ruleTester.ts +0 -4
  35. package/src/rules/testCaseDuplicates.test.ts +0 -174
  36. package/src/rules/testCaseDuplicates.ts +0 -63
  37. package/src/tsAstToLiteral.ts +0 -55
  38. package/src/types.ts +0 -22
  39. package/tsconfig.json +0 -14
  40. package/tsconfig.tsbuildinfo +0 -1
@@ -1,2 +1,3 @@
1
1
  import * as ts from "typescript";
2
2
  export declare function findProperty<Node extends ts.Node>(properties: ts.NodeArray<ts.ObjectLiteralElementLike>, name: string, predicate: (node: ts.Node) => node is Node): (ts.Expression & Node) | undefined;
3
+ //# sourceMappingURL=findProperty.d.ts.map
@@ -5,3 +5,4 @@ export function findProperty(properties, name, predicate) {
5
5
  property.name.text === name &&
6
6
  predicate(property.initializer))?.initializer;
7
7
  }
8
+ //# sourceMappingURL=findProperty.js.map
package/lib/flint.d.ts CHANGED
@@ -2,8 +2,9 @@ export declare const flint: import("@flint.fyi/core").Plugin<import("@flint.fyi/
2
2
  readonly description: "Reports cases for invalid code that isn't formatted across lines.";
3
3
  readonly id: "invalidCodeLines";
4
4
  readonly preset: "logical";
5
- }, import("@flint.fyi/ts/lib/nodes.js").TSNodesByName, import("@flint.fyi/ts").TypeScriptServices, "singleLineTest", undefined>, import("@flint.fyi/core").Rule<{
5
+ }, import("@flint.fyi/ts").TSNodesByName, import("@flint.fyi/ts").TypeScriptFileServices, "singleLineTest", undefined>, import("@flint.fyi/core").Rule<{
6
6
  readonly description: "Reports test cases that are identical to previous test cases.";
7
7
  readonly id: "testCaseDuplicates";
8
8
  readonly preset: "logical";
9
- }, import("@flint.fyi/ts/lib/nodes.js").TSNodesByName, import("@flint.fyi/ts").TypeScriptServices, "duplicateTest", undefined>]>;
9
+ }, import("@flint.fyi/ts").TSNodesByName, import("@flint.fyi/ts").TypeScriptFileServices, "duplicateTest", undefined>]>;
10
+ //# sourceMappingURL=flint.d.ts.map
package/lib/flint.js CHANGED
@@ -2,6 +2,7 @@ import { createPlugin } from "@flint.fyi/core";
2
2
  import invalidCodeLines from "./rules/invalidCodeLines.js";
3
3
  import testCaseDuplicates from "./rules/testCaseDuplicates.js";
4
4
  export const flint = createPlugin({
5
- name: "flint",
5
+ name: "Flint",
6
6
  rules: [invalidCodeLines, testCaseDuplicates],
7
7
  });
8
+ //# sourceMappingURL=flint.js.map
@@ -3,3 +3,4 @@ export declare function getRuleTesterDescribedCases(node: ts.CallExpression): {
3
3
  invalid: import("./types.js").ParsedTestCaseInvalid[];
4
4
  valid: import("./types.js").ParsedTestCase[];
5
5
  } | undefined;
6
+ //# sourceMappingURL=getRuleTesterDescribedCases.d.ts.map
@@ -11,7 +11,7 @@ export function getRuleTesterDescribedCases(node) {
11
11
  return undefined;
12
12
  }
13
13
  // TODO: Check node.expression.expression's type for being a RuleTester
14
- // https://github.com/JoshuaKGoldberg/flint/issues/152
14
+ // https://github.com/flint-fyi/flint/issues/152
15
15
  const argument = node.arguments[1];
16
16
  if (!ts.isObjectLiteralExpression(argument)) {
17
17
  return undefined;
@@ -29,3 +29,4 @@ export function getRuleTesterDescribedCases(node) {
29
29
  valid: valid.elements.map(parseTestCase).filter(isTruthy),
30
30
  };
31
31
  }
32
+ //# sourceMappingURL=getRuleTesterDescribedCases.js.map
package/lib/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./flint.js";
2
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export * from "./flint.js";
2
+ //# sourceMappingURL=index.js.map
@@ -2,3 +2,4 @@ import * as ts from "typescript";
2
2
  import type { ParsedTestCase, ParsedTestCaseInvalid } from "./types.js";
3
3
  export declare function parseTestCase(node: ts.Expression): ParsedTestCase | undefined;
4
4
  export declare function parseTestCaseInvalid(node: ts.Expression): ParsedTestCaseInvalid | undefined;
5
+ //# sourceMappingURL=parseTestCases.d.ts.map
@@ -60,3 +60,4 @@ export function parseTestCaseInvalid(node) {
60
60
  snapshot: snapshot.text,
61
61
  };
62
62
  }
63
+ //# sourceMappingURL=parseTestCases.js.map
@@ -2,5 +2,6 @@ declare const _default: import("@flint.fyi/core").Rule<{
2
2
  readonly description: "Reports cases for invalid code that isn't formatted across lines.";
3
3
  readonly id: "invalidCodeLines";
4
4
  readonly preset: "logical";
5
- }, import("@flint.fyi/ts/lib/nodes.js").TSNodesByName, import("@flint.fyi/ts").TypeScriptServices, "singleLineTest", undefined>;
5
+ }, import("@flint.fyi/ts").TSNodesByName, import("@flint.fyi/ts").TypeScriptFileServices, "singleLineTest", undefined>;
6
6
  export default _default;
7
+ //# sourceMappingURL=invalidCodeLines.d.ts.map
@@ -21,23 +21,26 @@ export default typescriptLanguage.createRule({
21
21
  },
22
22
  },
23
23
  setup(context) {
24
- function checkTestCase(testCase) {
24
+ function checkTestCase(testCase, sourceFile) {
25
25
  if (!testCase.code.startsWith("\n")) {
26
26
  context.report({
27
- fix: [createFixForCode(testCase), createFixForSnapshot(testCase)],
27
+ fix: [
28
+ createFixForCode(testCase, sourceFile),
29
+ createFixForSnapshot(testCase, sourceFile),
30
+ ],
28
31
  message: "singleLineTest",
29
- range: getTSNodeRange(testCase.nodes.code, context.sourceFile),
32
+ range: getTSNodeRange(testCase.nodes.code, sourceFile),
30
33
  });
31
34
  }
32
35
  }
33
- function createFixForCode(testCase) {
36
+ function createFixForCode(testCase, sourceFile) {
34
37
  if (ts.isStringLiteral(testCase.nodes.code)) {
35
38
  return {
36
- range: getTSNodeRange(testCase.nodes.code, context.sourceFile),
39
+ range: getTSNodeRange(testCase.nodes.code, sourceFile),
37
40
  text: `\`\n${testCase.code}\n\``,
38
41
  };
39
42
  }
40
- const begin = testCase.nodes.code.getStart(context.sourceFile) + 1;
43
+ const begin = testCase.nodes.code.getStart(sourceFile) + 1;
41
44
  return {
42
45
  range: {
43
46
  begin,
@@ -46,8 +49,8 @@ export default typescriptLanguage.createRule({
46
49
  text: "\n",
47
50
  };
48
51
  }
49
- function createFixForSnapshot(testCase) {
50
- const begin = testCase.nodes.snapshot.getStart(context.sourceFile) + 1;
52
+ function createFixForSnapshot(testCase, sourceFile) {
53
+ const begin = testCase.nodes.snapshot.getStart(sourceFile) + 1;
51
54
  return {
52
55
  range: {
53
56
  begin,
@@ -58,14 +61,17 @@ export default typescriptLanguage.createRule({
58
61
  }
59
62
  return {
60
63
  visitors: {
61
- CallExpression(node) {
64
+ CallExpression(node, { sourceFile }) {
62
65
  const describedCases = getRuleTesterDescribedCases(node);
63
66
  if (!describedCases) {
64
67
  return;
65
68
  }
66
- describedCases.invalid.forEach(checkTestCase);
69
+ describedCases.invalid.forEach((testCase) => {
70
+ checkTestCase(testCase, sourceFile);
71
+ });
67
72
  },
68
73
  },
69
74
  };
70
75
  },
71
76
  });
77
+ //# sourceMappingURL=invalidCodeLines.js.map
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=invalidCodeLines.test.d.ts.map
@@ -195,3 +195,4 @@ Rule report message.
195
195
  `,
196
196
  ],
197
197
  });
198
+ //# sourceMappingURL=invalidCodeLines.test.js.map
@@ -1,2 +1,3 @@
1
1
  import { RuleTester } from "@flint.fyi/rule-tester";
2
2
  export declare const ruleTester: RuleTester;
3
+ //# sourceMappingURL=ruleTester.d.ts.map
@@ -1,3 +1,8 @@
1
1
  import { RuleTester } from "@flint.fyi/rule-tester";
2
2
  import { describe, it } from "vitest";
3
- export const ruleTester = new RuleTester({ describe, it });
3
+ export const ruleTester = new RuleTester({
4
+ defaults: { fileName: "file.test.ts" },
5
+ describe,
6
+ it,
7
+ });
8
+ //# sourceMappingURL=ruleTester.js.map
@@ -2,5 +2,6 @@ declare const _default: import("@flint.fyi/core").Rule<{
2
2
  readonly description: "Reports test cases that are identical to previous test cases.";
3
3
  readonly id: "testCaseDuplicates";
4
4
  readonly preset: "logical";
5
- }, import("@flint.fyi/ts/lib/nodes.js").TSNodesByName, import("@flint.fyi/ts").TypeScriptServices, "duplicateTest", undefined>;
5
+ }, import("@flint.fyi/ts").TSNodesByName, import("@flint.fyi/ts").TypeScriptFileServices, "duplicateTest", undefined>;
6
6
  export default _default;
7
+ //# sourceMappingURL=testCaseDuplicates.d.ts.map
@@ -20,7 +20,7 @@ export default typescriptLanguage.createRule({
20
20
  },
21
21
  },
22
22
  setup(context) {
23
- function checkTestCases(testCases) {
23
+ function checkTestCases(testCases, sourceFile) {
24
24
  const seen = new Set();
25
25
  for (const testCase of testCases) {
26
26
  const key = JSON.stringify({
@@ -31,7 +31,7 @@ export default typescriptLanguage.createRule({
31
31
  if (seen.has(key)) {
32
32
  context.report({
33
33
  message: "duplicateTest",
34
- range: getTSNodeRange(testCase.nodes.case, context.sourceFile),
34
+ range: getTSNodeRange(testCase.nodes.case, sourceFile),
35
35
  });
36
36
  }
37
37
  else {
@@ -41,15 +41,16 @@ export default typescriptLanguage.createRule({
41
41
  }
42
42
  return {
43
43
  visitors: {
44
- CallExpression(node) {
44
+ CallExpression(node, { sourceFile }) {
45
45
  const describedCases = getRuleTesterDescribedCases(node);
46
46
  if (!describedCases) {
47
47
  return;
48
48
  }
49
- checkTestCases(describedCases.invalid);
50
- checkTestCases(describedCases.valid);
49
+ checkTestCases(describedCases.invalid, sourceFile);
50
+ checkTestCases(describedCases.valid, sourceFile);
51
51
  },
52
52
  },
53
53
  };
54
54
  },
55
55
  });
56
+ //# sourceMappingURL=testCaseDuplicates.js.map
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=testCaseDuplicates.test.d.ts.map
@@ -171,3 +171,4 @@ ruleTester.describe(rule, {
171
171
  `,
172
172
  ],
173
173
  });
174
+ //# sourceMappingURL=testCaseDuplicates.test.js.map
@@ -2,3 +2,4 @@ import ts from "typescript";
2
2
  export declare function tsAstToLiteral(node: ts.ArrayLiteralExpression): unknown[];
3
3
  export declare function tsAstToLiteral(node: ts.ObjectLiteralExpression): object;
4
4
  export declare function tsAstToLiteral(node: ts.Node): unknown;
5
+ //# sourceMappingURL=tsAstToLiteral.d.ts.map
@@ -35,3 +35,4 @@ export function tsAstToLiteral(node) {
35
35
  }
36
36
  return undefined;
37
37
  }
38
+ //# sourceMappingURL=tsAstToLiteral.js.map
package/lib/types.d.ts CHANGED
@@ -15,3 +15,4 @@ export interface ParsedTestCaseNodes {
15
15
  export interface ParsedTestCaseNodesInvalid extends ParsedTestCaseNodes {
16
16
  snapshot: ts.Node;
17
17
  }
18
+ //# sourceMappingURL=types.d.ts.map
package/lib/types.js CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@flint.fyi/plugin-flint",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "[Experimental] A Flint plugin for linting Flint plugins.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/JoshuaKGoldberg/flint",
7
+ "url": "git+https://github.com/flint-fyi/flint.git",
8
8
  "directory": "packages/plugin-flint"
9
9
  },
10
10
  "license": "MIT",
@@ -12,19 +12,29 @@
12
12
  "name": "JoshuaKGoldberg",
13
13
  "email": "npm@joshuakgoldberg.com"
14
14
  },
15
+ "sideEffects": false,
15
16
  "type": "module",
16
- "main": "./lib/index.js",
17
+ "exports": {
18
+ ".": "./lib/index.js"
19
+ },
20
+ "files": [
21
+ "lib/",
22
+ "!lib/**/*.map"
23
+ ],
17
24
  "dependencies": {
18
25
  "@flint.fyi/core": "",
19
- "@flint.fyi/rule-tester": "",
20
26
  "@flint.fyi/ts": "",
21
- "@flint.fyi/utils": ""
27
+ "@flint.fyi/utils": "",
28
+ "typescript": "^5.9.3"
29
+ },
30
+ "devDependencies": {
31
+ "@flint.fyi/rule-tester": "",
32
+ "vitest": "4.0.15"
22
33
  },
23
34
  "engines": {
24
35
  "node": ">=24.0.0"
25
36
  },
26
37
  "publishConfig": {
27
- "access": "public",
28
- "provenance": true
38
+ "access": "public"
29
39
  }
30
40
  }
package/CHANGELOG.md DELETED
@@ -1,36 +0,0 @@
1
- # @flint.fyi/plugin-flint
2
-
3
- ## 0.2.0
4
-
5
- ### Minor Changes
6
-
7
- - 950e84c: feat(rule-tester): [invalidCodeLines] add rule
8
-
9
- ## 0.1.0
10
-
11
- ### Minor Changes
12
-
13
- - d89c480: feat(comparisons): add eslint-plugin-eslint-plugin comparisons
14
-
15
- ### Patch Changes
16
-
17
- - Updated dependencies [738fe36]
18
- - @flint.fyi/rule-tester@0.14.3
19
-
20
- ## 0.0.2
21
-
22
- ### Patch Changes
23
-
24
- - 0b80834: allow rules to indicate dependencies
25
- - 63b61e5: add --suggestions to CLI
26
- - Updated dependencies [0b80834]
27
- - Updated dependencies [63b61e5]
28
- - @flint.fyi/core@0.13.5
29
- - @flint.fyi/ts@0.13.2
30
- - @flint.fyi/utils@0.13.2
31
-
32
- ## 0.0.1
33
-
34
- ### Patch Changes
35
-
36
- - 83a4361: initial functionality
@@ -1,15 +0,0 @@
1
- import * as ts from "typescript";
2
-
3
- export function findProperty<Node extends ts.Node>(
4
- properties: ts.NodeArray<ts.ObjectLiteralElementLike>,
5
- name: string,
6
- predicate: (node: ts.Node) => node is Node,
7
- ) {
8
- return properties.find(
9
- (property): property is ts.PropertyAssignment & { initializer: Node } =>
10
- ts.isPropertyAssignment(property) &&
11
- ts.isIdentifier(property.name) &&
12
- property.name.text === name &&
13
- predicate(property.initializer),
14
- )?.initializer;
15
- }
package/src/flint.ts DELETED
@@ -1,9 +0,0 @@
1
- import { createPlugin } from "@flint.fyi/core";
2
-
3
- import invalidCodeLines from "./rules/invalidCodeLines.js";
4
- import testCaseDuplicates from "./rules/testCaseDuplicates.js";
5
-
6
- export const flint = createPlugin({
7
- name: "flint",
8
- rules: [invalidCodeLines, testCaseDuplicates],
9
- });
@@ -1,48 +0,0 @@
1
- import { isTruthy } from "@flint.fyi/utils";
2
- import * as ts from "typescript";
3
-
4
- import { findProperty } from "./findProperty.js";
5
- import { parseTestCase, parseTestCaseInvalid } from "./parseTestCases.js";
6
-
7
- export function getRuleTesterDescribedCases(node: ts.CallExpression) {
8
- if (
9
- !ts.isPropertyAccessExpression(node.expression) ||
10
- !ts.isIdentifier(node.expression.expression) ||
11
- !ts.isIdentifier(node.expression.name) ||
12
- node.expression.name.text !== "describe" ||
13
- node.arguments.length !== 2
14
- ) {
15
- return undefined;
16
- }
17
-
18
- // TODO: Check node.expression.expression's type for being a RuleTester
19
- // https://github.com/JoshuaKGoldberg/flint/issues/152
20
-
21
- const argument = node.arguments[1];
22
- if (!ts.isObjectLiteralExpression(argument)) {
23
- return undefined;
24
- }
25
-
26
- const invalid = findProperty(
27
- argument.properties,
28
- "invalid",
29
- ts.isArrayLiteralExpression,
30
- );
31
- if (!invalid) {
32
- return undefined;
33
- }
34
-
35
- const valid = findProperty(
36
- argument.properties,
37
- "valid",
38
- ts.isArrayLiteralExpression,
39
- );
40
- if (!valid) {
41
- return undefined;
42
- }
43
-
44
- return {
45
- invalid: invalid.elements.map(parseTestCaseInvalid).filter(isTruthy),
46
- valid: valid.elements.map(parseTestCase).filter(isTruthy),
47
- };
48
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./flint.js";
@@ -1,96 +0,0 @@
1
- import * as ts from "typescript";
2
-
3
- import type { ParsedTestCase, ParsedTestCaseInvalid } from "./types.js";
4
-
5
- import { findProperty } from "./findProperty.js";
6
- import { tsAstToLiteral } from "./tsAstToLiteral.js";
7
-
8
- export function parseTestCase(node: ts.Expression): ParsedTestCase | undefined {
9
- if (ts.isStringLiteralLike(node)) {
10
- return {
11
- code: node.text,
12
- nodes: {
13
- case: node,
14
- code: node,
15
- },
16
- };
17
- }
18
-
19
- if (!ts.isObjectLiteralExpression(node)) {
20
- return undefined;
21
- }
22
-
23
- const code = findProperty(node.properties, "code", ts.isStringLiteralLike);
24
- if (!code) {
25
- return undefined;
26
- }
27
-
28
- const fileName = findProperty(
29
- node.properties,
30
- "fileName",
31
- ts.isStringLiteralLike,
32
- );
33
- const options = findProperty(
34
- node.properties,
35
- "options",
36
- ts.isObjectLiteralExpression,
37
- );
38
-
39
- return {
40
- code: code.text,
41
- fileName: fileName?.text,
42
- nodes: {
43
- case: node,
44
- code,
45
- fileName,
46
- options,
47
- },
48
- options: options && tsAstToLiteral(options),
49
- };
50
- }
51
-
52
- export function parseTestCaseInvalid(
53
- node: ts.Expression,
54
- ): ParsedTestCaseInvalid | undefined {
55
- if (!ts.isObjectLiteralExpression(node)) {
56
- return undefined;
57
- }
58
-
59
- const code = findProperty(node.properties, "code", ts.isStringLiteralLike);
60
- if (!code) {
61
- return undefined;
62
- }
63
-
64
- const fileName = findProperty(
65
- node.properties,
66
- "fileName",
67
- ts.isStringLiteralLike,
68
- );
69
- const options = findProperty(
70
- node.properties,
71
- "options",
72
- ts.isObjectLiteralExpression,
73
- );
74
- const snapshot = findProperty(
75
- node.properties,
76
- "snapshot",
77
- ts.isStringLiteralLike,
78
- );
79
- if (!snapshot) {
80
- return undefined;
81
- }
82
-
83
- return {
84
- code: code.text,
85
- fileName: fileName?.text,
86
- nodes: {
87
- case: node,
88
- code,
89
- fileName,
90
- options,
91
- snapshot,
92
- },
93
- options: options && tsAstToLiteral(options),
94
- snapshot: snapshot.text,
95
- };
96
- }