Skip to content

Commit dc85793

Browse files
authored
Merge pull request #5556 from NomicFoundation/galargh/issue/5057
fix: exit check task with exit code 1 when solhint raises errors
2 parents 599a285 + 570f79d commit dc85793

File tree

10 files changed

+146
-17
lines changed

10 files changed

+146
-17
lines changed

.changeset/breezy-chairs-relax.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomiclabs/hardhat-solhint": major
3+
---
4+
5+
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

.changeset/early-laws-trade.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomiclabs/hardhat-solhint": major
3+
---
4+
5+
Updated solhint dependency to [v5.0.2](https://github.com/protofire/solhint/releases/tag/v5.0.2)

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ Unlike linking, if you make a change in the code, you'll need to repeat the proc
119119

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

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

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

packages/hardhat-solhint/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"README.md"
3636
],
3737
"dependencies": {
38-
"solhint": "^3.4.0"
38+
"solhint": "^5.0.2"
3939
},
4040
"devDependencies": {
4141
"@nomicfoundation/eslint-plugin-hardhat-internal-rules": "workspace:^",

packages/hardhat-solhint/src/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,16 @@ task("check", async (_, { run }, runSuper) => {
127127
const reports = await run("hardhat-solhint:run-solhint");
128128

129129
printReport(reports);
130+
131+
const errorsCount = reports.reduce(
132+
(acc: number, i: { errorCount: number }) => {
133+
return acc + i.errorCount;
134+
},
135+
0
136+
);
137+
138+
if (errorsCount > 0) {
139+
process.exitCode = 1;
140+
return;
141+
}
130142
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "solhint:all"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pragma solidity ^0.8.0;
2+
3+
4+
contract Greeter {
5+
6+
string greeting;
7+
constructor(string memory _greeting) public {
8+
greeting = _greeting;
9+
}
10+
11+
function greet() public view returns (string memory) {
12+
return greeting;
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require("../../../src/index");
2+
3+
module.exports = {
4+
solidity: "0.5.15",
5+
};

packages/hardhat-solhint/test/tests.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,24 @@ describe("Solhint plugin", function () {
3636
);
3737
});
3838

39-
it("should run the check task without throwing an error", async function () {
39+
it("should run the check task and set the exit code to 1", async function () {
4040
const consoleLogStub = sinon.stub(console, "log");
4141
await this.env.run("check");
4242
assert.isTrue(consoleLogStub.calledOnce);
43+
assert.strictEqual(process.exitCode, 1);
4344
consoleLogStub.restore();
45+
process.exitCode = undefined;
46+
});
47+
});
48+
49+
describe("Project with no errors", function () {
50+
useEnvironment("no-errors-project");
51+
52+
it("should run the check task and not set the exit code", async function () {
53+
const consoleLogStub = sinon.stub(console, "log");
54+
await this.env.run("check");
55+
assert.isTrue(consoleLogStub.calledOnce);
56+
assert.strictEqual(process.exitCode, undefined);
4457
});
4558
});
4659

pnpm-lock.yaml

+84-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)