Add Solidity linting with solhint, Foundry formatter, and pre-commit hooks (#51)

## Changes

### Configuration
- Added .solhint.json with recommended rules + custom config
  - 160 char line length (warn)
  - Double quotes enforcement (error)
  - Explicit visibility required (error)
  - Console statements allowed (scripts/tests need them)
  - Gas optimization warnings enabled
  - Ignores test/helpers/, lib/, out/, cache/, broadcast/

- Added foundry.toml [fmt] section
  - 160 char line length
  - 4-space tabs
  - Double quotes
  - Thousands separators for numbers
  - Sort imports enabled

- Added .lintstagedrc.json for pre-commit auto-fix
  - Runs solhint --fix on .sol files
  - Runs forge fmt on .sol files

- Added husky pre-commit hook via lint-staged

### NPM Scripts
- lint:sol - run solhint
- lint:sol:fix - auto-fix solhint issues
- format:sol - format with forge fmt
- format:sol:check - check formatting
- lint / lint:fix - combined commands

### Code Changes
- Added explicit visibility modifiers (internal) to constants in scripts and tests
- Fixed quote style in DeployLocal.sol
- All Solidity files formatted with forge fmt

## Verification
-  forge fmt --check passes
-  No solhint errors (warnings only)
-  forge build succeeds
-  forge test passes (107/107)

resolves #44

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/51
This commit is contained in:
johba 2025-10-04 15:17:09 +02:00
parent f8927b426e
commit d7c2184ccf
45 changed files with 2853 additions and 1225 deletions

View file

@ -1,8 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.19;
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import "@openzeppelin/utils/math/SignedMath.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
/**
* @title PriceOracle
@ -23,7 +23,7 @@ abstract contract PriceOracle {
/// @return isStable True if price is within acceptable deviation from TWAP
function _isPriceStable(int24 currentTick) internal view returns (bool isStable) {
IUniswapV3Pool pool = _getPool();
uint32[] memory secondsAgo = new uint32[](2);
secondsAgo[0] = PRICE_STABILITY_INTERVAL; // 5 minutes ago
secondsAgo[1] = 0; // current block timestamp
@ -51,15 +51,19 @@ abstract contract PriceOracle {
/// @return isUp True if price moved up (relative to token ordering)
/// @return isEnough True if movement amplitude is sufficient for recentering
function _validatePriceMovement(
int24 currentTick,
int24 centerTick,
int24 currentTick,
int24 centerTick,
int24 tickSpacing,
bool token0isWeth
) internal pure returns (bool isUp, bool isEnough) {
)
internal
pure
returns (bool isUp, bool isEnough)
{
uint256 minAmplitude = uint24(tickSpacing) * 2;
// Determine the correct comparison direction based on token0isWeth
isUp = token0isWeth ? currentTick < centerTick : currentTick > centerTick;
isEnough = SignedMath.abs(currentTick - centerTick) > minAmplitude;
}
}
}