Suppress compilation warnings introduced by injected trace statements (#583)

experimental-options
cgewecke 4 years ago
parent 7f85a0c2c8
commit 43ccd3b181
  1. 13
      plugins/hardhat.plugin.js
  2. 19
      plugins/resources/truffle.utils.js
  3. 9
      plugins/truffle.plugin.js
  4. 1
      test/units/truffle/flags.js

@ -9,6 +9,7 @@ const {
TASK_COMPILE,
TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT,
TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS
} = require("hardhat/builtin-tasks/task-names");
// Toggled true for `coverage` task only.
@ -75,6 +76,18 @@ subtask(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_,
return compilationJob;
});
// Suppress compilation warnings because injected trace function triggers
// complaint about unused variable
subtask(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_ERRORS).setAction(async (_, __, runSuper) => {
const defaultWarn = console.warn;
if (measureCoverage) {
console.warn = () => {};
}
await runSuper();
console.warn = defaultWarn;
});
/**
* Coverage task implementation
* @param {HardhatUserArgs} args

@ -196,10 +196,29 @@ function normalizeConfig(config){
return config;
}
/**
* Replacement logger which filters out compilation warnings triggered by injected trace
* function definitions.
*
* @type {Object}
*/
const filteredLogger = {
log: (val) => {
const loggable = typeof val === 'string' &&
!val.includes('Warning:') && // solc msg grep
!process.env.SILENT; // unit tests
loggable && console.log(val);
},
warn: console.warn,
error: console.error
}
module.exports = {
getTestFilePaths,
setNetwork,
setNetworkFrom,
loadLibrary,
normalizeConfig,
filteredLogger
}

@ -90,7 +90,14 @@ async function plugin(config){
path.basename(config.contracts_build_directory)
);
// Filter compilation warnings
const defaultLogger = config.logger;
if (!config.verbose){
config.logger = truffleUtils.filteredLogger;
}
config.all = true;
config.strict = false;
config.compilers.solc.settings.optimizer.enabled = false;
// Run pre-compile hook;
@ -98,6 +105,8 @@ async function plugin(config){
// Compile Instrumented Contracts
await truffle.contracts.compile(config);
config.logger = defaultLogger;
await api.onCompileComplete(config);
config.test_files = await truffleUtils.getTestFilePaths(config);

@ -190,6 +190,7 @@ describe('Truffle Plugin: command line options', function() {
truffleConfig.logger = mock.testLogger;
truffleConfig.temp = 'special_location';
truffleConfig.verbose = true;
mock.install('Simple', 'simple.js', solcoverConfig);
await plugin(truffleConfig);

Loading…
Cancel
Save