Skip to content

Commit 95d95ef

Browse files
committedJul 9, 2024
Define rules to enforce using our own assertions
·
1 parent 99e786c commit 95d95ef

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎config-v-next/eslint.cjs

+20-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ const path = require("path");
1010
* The only packages that should not use this config are our own eslint plugins/rules.
1111
*
1212
* @param {string} configFilePath The path to the config file that is using this function.
13-
* @param {{ onlyHardhatError?: boolean }} options An object with options to enable/disable certain rules.
13+
* @param {{ onlyHardhatError?: boolean, enforceHardhatTestUtils?: boolean }} options An object with options to enable/disable certain rules.
1414
* @returns {import("eslint").Linter.Config}
1515
*/
16-
function createConfig(configFilePath, options = { onlyHardhatError: true }) {
16+
function createConfig(
17+
configFilePath,
18+
options = { onlyHardhatError: true, enforceHardhatTestUtils: true }
19+
) {
1720
/**
1821
* @type {import("eslint").Linter.Config}
1922
*/
@@ -425,6 +428,21 @@ function createConfig(configFilePath, options = { onlyHardhatError: true }) {
425428
});
426429
}
427430

431+
if (options.enforceHardhatTestUtils) {
432+
config.rules["no-restricted-syntax"].push(
433+
{
434+
selector:
435+
"CallExpression[callee.object.name='assert'][callee.property.name=throws]",
436+
message: "Don't use assert.throws. Use our test helpers instead.",
437+
},
438+
{
439+
selector:
440+
"CallExpression[callee.object.name='assert'][callee.property.name=rejects]",
441+
message: "Don't use assert.rejects. Use our test helpers instead.",
442+
}
443+
);
444+
}
445+
428446
return config;
429447
}
430448

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const { createConfig } = require("../../config-v-next/eslint.cjs");
22

3-
module.exports = createConfig(__filename);
3+
module.exports = createConfig(__filename, { enforceHardhatTestUtils: false });

0 commit comments

Comments
 (0)
Please sign in to comment.