1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/development/fitness-functions/rules/index.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

43 lines
1.1 KiB
TypeScript

import { preventSinonAssertSyntax } from './sinon-assert-syntax';
import { preventJavaScriptFileAdditions } from './javascript-additions';
const RULES: IRule[] = [
{
name: "Don't use `sinon` or `assert` in unit tests",
fn: preventSinonAssertSyntax,
docURL:
'https://github.com/MetaMask/metamask-extension/blob/develop/docs/testing.md#favor-jest-instead-of-mocha',
},
{
name: "Don't add JS or JSX files to the `shared` directory",
fn: preventJavaScriptFileAdditions,
},
];
interface IRule {
name: string;
fn: (diff: string) => boolean;
docURL?: string;
}
function runFitnessFunctionRule(rule: IRule, diff: string): void {
const { name, fn, docURL } = rule;
console.log(`Checking rule "${name}"...`);
const hasRulePassed: boolean = fn(diff) as boolean;
if (hasRulePassed === true) {
console.log(`...OK`);
} else {
console.log(`...FAILED. Changes not accepted by the fitness function.`);
if (docURL) {
console.log(`For more info: ${docURL}.`);
}
process.exit(1);
}
}
export { RULES, runFitnessFunctionRule };
export type { IRule };