Skip to content

Commit 14eafdd

Browse files
authored
refactor: use types from @typescript-eslint/utils for snapshot processor (#1504)
1 parent 8fac5eb commit 14eafdd

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/processors/__tests__/snapshot-processor.test.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('snapshot-processor', () => {
1212
it('should pass on untouched source code to source array', () => {
1313
const { preprocess } = snapshotProcessor;
1414
const sourceCode = "const name = 'johnny bravo';";
15-
const result = preprocess(sourceCode);
15+
const result = preprocess(sourceCode, 'my-file.snap');
1616

1717
expect(result).toEqual([sourceCode]);
1818
});
@@ -21,13 +21,35 @@ describe('snapshot-processor', () => {
2121
describe('postprocess function', () => {
2222
it('should only return messages about snapshot specific rules', () => {
2323
const { postprocess } = snapshotProcessor;
24-
const result = postprocess([
25-
['no-console', 'global-require', 'jest/no-large-snapshots'].map(
26-
ruleId => ({ ruleId }),
27-
),
28-
]);
2924

30-
expect(result).toEqual([{ ruleId: 'jest/no-large-snapshots' }]);
25+
const result = postprocess(
26+
[
27+
['no-console', 'global-require', 'jest/no-large-snapshots'].map(
28+
ruleId => ({
29+
ruleId,
30+
column: 1,
31+
line: 1,
32+
source: null,
33+
nodeType: 'Program',
34+
message: 'something is not right about this...',
35+
severity: 1,
36+
}),
37+
),
38+
],
39+
'my-file.snap',
40+
);
41+
42+
expect(result).toEqual([
43+
{
44+
ruleId: 'jest/no-large-snapshots',
45+
column: 1,
46+
line: 1,
47+
source: null,
48+
nodeType: 'Program',
49+
message: 'something is not right about this...',
50+
severity: 1,
51+
},
52+
]);
3153
});
3254
});
3355
});

src/processors/snapshot-processor.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
22
// https://github.com/typescript-eslint/typescript-eslint/issues/808
3+
import type { TSESLint } from '@typescript-eslint/utils';
34
import {
45
name as packageName,
56
version as packageVersion,
67
} from '../../package.json';
78

8-
type PostprocessMessage = { ruleId: string };
9+
type SnapshotProcessor = Required<TSESLint.Linter.Processor>;
910

1011
export const meta = { name: packageName, version: packageVersion };
11-
export const preprocess = (source: string): string[] => [source];
12-
export const postprocess = (messages: PostprocessMessage[][]) =>
12+
export const preprocess: SnapshotProcessor['preprocess'] = source => [source];
13+
export const postprocess: SnapshotProcessor['postprocess'] = messages =>
1314
// snapshot files should only be linted with snapshot specific rules
1415
messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots');

0 commit comments

Comments
 (0)