Automatically prepend Solidity source files in Hardhat projects with an SPDX License Identifier.
Versions of this plugin prior to
3.0.0were released ashardhat-spdx-license-identifier, outside of the@solidstatenamespace.
Versions of this plugin prior to
2.0.0were released asbuidler-spdx-license-identifier.
npm install --save-dev @solidstate/hardhat-license-identifier
# or
pnpm add -D @solidstate/hardhat-license-identifierLoad plugin in Hardhat config:
import hardhatLicenseIdentifier from '@solidstate/hardhat-license-identifier';
const config: HardhatUserConfig = {
plugins: [
hardhatLicenseIdentifier,
],
licenseIdentifier: {
... // see table for configuration options
},
};Add configuration under the licenseIdentifier key:
| option | description | default |
|---|---|---|
license |
SPDX license to add to source files | license field of package.json |
overwrite |
whether to overwrite existing SPDX license identifiers | false |
runOnCompile |
whether to automatically prepend identifiers during compilation | false |
only |
Array of String matchers used to select included paths, defaults to all contracts if length is 0 |
[] |
except |
Array of String matchers used to exclude paths |
[] |
licenseIdentifier: {
overwrite: true,
runOnCompile: true,
except: ['vendor/']
}The included Hardhat task may be run manually. Its arguments override any existing configuration:
npx hardhat prepend-license UNLICENSED --overwrite
# or
pnpm hardhat prepend-license UNLICENSED --overwriteFiles which do not contain a license identifier will be prepended with one. Files with a license identifier which does not match that which is specified in package.json may be updated, depending on configuration.
Install dependencies via pnpm:
pnpm installSetup Husky to format code on commit:
pnpm prepare