1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 05:12:18 +01:00
metamask-extension/development/fitness-functions/rules/sinon-assert-syntax.ts
Pedro Figueiredo 632ae0b7c3
Prevent new JS files in shared folder (#17737)
* Prevent new JS files in shared folder

* migrate to typescript

* fix types

* cleanup
2023-04-24 15:44:42 +01:00

31 lines
863 B
TypeScript

import { EXCLUDE_E2E_TESTS_REGEX } from '../common/constants';
import {
filterDiffLineAdditions,
filterDiffByFilePath,
hasNumberOfCodeBlocksIncreased,
} from '../common/shared';
const codeBlocks = [
"import { strict as assert } from 'assert';",
'assert.deepEqual',
'assert.equal',
'assert.rejects',
'assert.strictEqual',
'sinon.',
];
function preventSinonAssertSyntax(diff: string): boolean {
const diffByFilePath = filterDiffByFilePath(diff, EXCLUDE_E2E_TESTS_REGEX);
const diffAdditions = filterDiffLineAdditions(diffByFilePath);
const hashmap = hasNumberOfCodeBlocksIncreased(diffAdditions, codeBlocks);
const haveOccurencesOfAtLeastOneCodeBlockIncreased =
Object.values(hashmap).includes(true);
if (haveOccurencesOfAtLeastOneCodeBlockIncreased) {
return false;
}
return true;
}
export { preventSinonAssertSyntax };