hardhat-log-remover
Version:
Remove Hardhat console.log imports and calls from Solidity source files
80 lines (64 loc) • 1.87 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const regexp_1 = __importDefault(require("../src/lib/regexp"));
const chai_1 = require("chai");
const testString = `
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import 'hardhat/console.sol';
import'hardhat/console.sol';
import "hardhat/console.sol";
import
'hardhat/console.sol'
;
abstract contract Token is ERC20 {
uint private _n;
function runAction () external {
_n++;
console.log(_n);
console.log(
_n
);
_n--;
console.log(_n, 'n');
console.logInt(1);
// console.log(_n, 'n');
console.logBytes27(
'0x');
if (_n == 0) { console.log(_n); }
if (_n == 0) console.log(_n);
}
}
`;
const expectedOutput = `
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
abstract contract Token is ERC20 {
uint private _n;
function runAction () external {
_n++;
_n--;
if (_n == 0) { }
if (_n == 0)
}
}
`;
describe('regular expressions', function () {
it('remove console.log imports', function () {
(0, chai_1.expect)(testString.replace(regexp_1.default.imports, '')).not.to.include('console.sol');
});
it('remove console.log calls', function () {
(0, chai_1.expect)(testString.replace(regexp_1.default.calls, '')).not.to.include('console.log');
});
it('leave unrelated code intact', function () {
const output = testString
.replace(regexp_1.default.imports, '')
.replace(regexp_1.default.calls, '');
(0, chai_1.expect)(output).to.equal(expectedOutput);
});
});