From bc449169cec795f2159ec6fdc35fede45e53d26a Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 4 Aug 2019 18:07:03 +1200 Subject: [PATCH 1/3] chore(snapshot-processor): convert to typescript --- ...ot-processor.test.js => snapshot-processor.test.ts} | 10 ++++------ src/processors/snapshot-processor.js | 8 -------- src/processors/snapshot-processor.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 14 deletions(-) rename src/processors/__tests__/{snapshot-processor.test.js => snapshot-processor.test.ts} (81%) delete mode 100644 src/processors/snapshot-processor.js create mode 100644 src/processors/snapshot-processor.ts diff --git a/src/processors/__tests__/snapshot-processor.test.js b/src/processors/__tests__/snapshot-processor.test.ts similarity index 81% rename from src/processors/__tests__/snapshot-processor.test.js rename to src/processors/__tests__/snapshot-processor.test.ts index 787f6182d..4165e42ef 100644 --- a/src/processors/__tests__/snapshot-processor.test.js +++ b/src/processors/__tests__/snapshot-processor.test.ts @@ -1,4 +1,4 @@ -import * as snapshotProcessor from '../snapshot-processor'; +import { snapshotProcessor } from '../snapshot-processor'; describe('snapshot-processor', () => { it('exports an object with preprocess and postprocess functions', () => { @@ -22,11 +22,9 @@ describe('snapshot-processor', () => { it('should only return messages about snapshot specific rules', () => { const { postprocess } = snapshotProcessor; const result = postprocess([ - [ - { ruleId: 'no-console' }, - { ruleId: 'global-require' }, - { ruleId: 'jest/no-large-snapshots' }, - ], + ['no-console', 'global-require', 'jest/no-large-snapshots'].map( + ruleId => ({ ruleId }), + ), ]); expect(result).toEqual([{ ruleId: 'jest/no-large-snapshots' }]); diff --git a/src/processors/snapshot-processor.js b/src/processors/snapshot-processor.js deleted file mode 100644 index f49843073..000000000 --- a/src/processors/snapshot-processor.js +++ /dev/null @@ -1,8 +0,0 @@ -// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins -export const preprocess = source => [source]; - -export const postprocess = messages => - messages[0].filter( - // snapshot files should only be linted with snapshot specific rules - message => message.ruleId === 'jest/no-large-snapshots', - ); diff --git a/src/processors/snapshot-processor.ts b/src/processors/snapshot-processor.ts new file mode 100644 index 000000000..1ab700298 --- /dev/null +++ b/src/processors/snapshot-processor.ts @@ -0,0 +1,10 @@ +// https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins + +type PostprocessMessage = { ruleId: string }; + +export const snapshotProcessor = { + preprocess: (source: string): string[] => [source], + postprocess: (messages: PostprocessMessage[][]) => + // snapshot files should only be linted with snapshot specific rules + messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots'), +}; From 565ac34860ffc4048929424ce5b5b25bc6106b92 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 6 Aug 2019 22:19:53 +1200 Subject: [PATCH 2/3] chore(snapshot-processor): refactor export --- src/processors/__tests__/snapshot-processor.test.ts | 2 +- src/processors/snapshot-processor.ts | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/processors/__tests__/snapshot-processor.test.ts b/src/processors/__tests__/snapshot-processor.test.ts index 4165e42ef..b4a807af5 100644 --- a/src/processors/__tests__/snapshot-processor.test.ts +++ b/src/processors/__tests__/snapshot-processor.test.ts @@ -1,4 +1,4 @@ -import { snapshotProcessor } from '../snapshot-processor'; +import * as snapshotProcessor from '../snapshot-processor'; describe('snapshot-processor', () => { it('exports an object with preprocess and postprocess functions', () => { diff --git a/src/processors/snapshot-processor.ts b/src/processors/snapshot-processor.ts index 1ab700298..228f5a223 100644 --- a/src/processors/snapshot-processor.ts +++ b/src/processors/snapshot-processor.ts @@ -2,9 +2,7 @@ type PostprocessMessage = { ruleId: string }; -export const snapshotProcessor = { - preprocess: (source: string): string[] => [source], - postprocess: (messages: PostprocessMessage[][]) => - // snapshot files should only be linted with snapshot specific rules - messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots'), -}; +export const preprocess = (source: string): string[] => [source]; +export const postprocess = (messages: PostprocessMessage[][]) => + // snapshot files should only be linted with snapshot specific rules + messages[0].filter(message => message.ruleId === 'jest/no-large-snapshots'); From 17d2430f339545da285ed84e4065efd77056d9ce Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Tue, 6 Aug 2019 22:21:55 +1200 Subject: [PATCH 3/3] chore(snapshot-processor): add link to github issue for types --- src/processors/snapshot-processor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/processors/snapshot-processor.ts b/src/processors/snapshot-processor.ts index 228f5a223..8bf53fc33 100644 --- a/src/processors/snapshot-processor.ts +++ b/src/processors/snapshot-processor.ts @@ -1,4 +1,5 @@ // https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins +// https://github.com/typescript-eslint/typescript-eslint/issues/808 type PostprocessMessage = { ruleId: string };