Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exit check task with exit code 1 when solhint raises errors #5556

Merged
merged 9 commits into from
Aug 1, 2024
5 changes: 5 additions & 0 deletions .changeset/breezy-chairs-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomiclabs/hardhat-solhint": major
---

Ensured the check task exits with exit code 1 when solhint raises any errors; this is a breaking change since the check task would previously always exit with exit code 0
5 changes: 5 additions & 0 deletions .changeset/early-laws-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomiclabs/hardhat-solhint": major
---

Updated solhint dependency to [v5.0.2](https://github.com/protofire/solhint/releases/tag/v5.0.2)
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ Unlike linking, if you make a change in the code, you'll need to repeat the proc

An even more realistic way of using your local changes in a project is to use [`pnpm pack`](https://pnpm.io/cli/pack):

1. Go to `packages/hardhat-core` and run `pnpm pack`. This will create a `nomiclabs-hardhat-x.y.z.tgz` file in that directory.
2. Go to some hardhat project and run `npm install /path/to/hardhat/packages/hardhat/nomiclabs-hardhat-x.y.z.tgz`.
1. Go to `packages/hardhat-core` and run `pnpm pack`. This will create a `hardhat-x.y.z.tgz` file in that directory.
2. Go to some hardhat project and run `npm install /path/to/hardhat/packages/hardhat-core/hardhat-x.y.z.tgz`.

Unlike linking, if you make a change in the code, you'll need to repeat the process.

Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-solhint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"README.md"
],
"dependencies": {
"solhint": "^3.4.0"
"solhint": "^5.0.2"
},
"devDependencies": {
"@nomicfoundation/eslint-plugin-hardhat-internal-rules": "workspace:^",
Expand Down
12 changes: 12 additions & 0 deletions packages/hardhat-solhint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ task("check", async (_, { run }, runSuper) => {
const reports = await run("hardhat-solhint:run-solhint");

printReport(reports);

const errorsCount = reports.reduce(
(acc: number, i: { errorCount: number }) => {
return acc + i.errorCount;
},
0
);

if (errorsCount > 0) {
kanej marked this conversation as resolved.
Show resolved Hide resolved
process.exitCode = 1;
return;
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:all"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.8.0;
kanej marked this conversation as resolved.
Show resolved Hide resolved


contract Greeter {

string greeting;
constructor(string memory _greeting) public {
greeting = _greeting;
}

function greet() public view returns (string memory) {
return greeting;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require("../../../src/index");

module.exports = {
solidity: "0.5.15",
};
15 changes: 14 additions & 1 deletion packages/hardhat-solhint/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ describe("Solhint plugin", function () {
);
});

it("should run the check task without throwing an error", async function () {
it("should run the check task and set the exit code to 1", async function () {
const consoleLogStub = sinon.stub(console, "log");
await this.env.run("check");
assert.isTrue(consoleLogStub.calledOnce);
assert.strictEqual(process.exitCode, 1);
consoleLogStub.restore();
process.exitCode = undefined;
});
});

describe("Project with no errors", function () {
useEnvironment("no-errors-project");

it("should run the check task and not set the exit code", async function () {
const consoleLogStub = sinon.stub(console, "log");
await this.env.run("check");
assert.isTrue(consoleLogStub.calledOnce);
assert.strictEqual(process.exitCode, undefined);
});
});

Expand Down
97 changes: 84 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading