Skip to content

Commit 9af04b2

Browse files
authored
fix(flatten): update license handling logic (#184)
Closes #183 Instead of finding line containing license in target source and adding it to the top, we find it and extract the license identifier itself
1 parent ec205aa commit 9af04b2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

crates/compilers/src/flatten.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a> FlatteningResult<'a> {
161161
let mut result = String::new();
162162

163163
if let Some(license) = &self.license {
164-
result.push_str(&format!("{license}\n"));
164+
result.push_str(&format!("// {license}\n"));
165165
}
166166
for pragma in &self.pragmas {
167167
result.push_str(&format!("{pragma}\n"));
@@ -757,7 +757,9 @@ impl Flattener {
757757

758758
for loc in &self.collect_licenses() {
759759
if loc.path == self.target {
760-
target_license = Some(self.read_location(loc));
760+
let license_line = self.read_location(loc);
761+
let license_start = license_line.find("SPDX-License-Identifier:").unwrap();
762+
target_license = Some(license_line[license_start..].trim());
761763
}
762764
updates.entry(loc.path.clone()).or_default().insert((
763765
loc.start,

test-data/hardhat-sample/contracts/Greeter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//SPDX-License-Identifier: Unlicense
1+
// SPDX-License-Identifier: Unlicense
22
pragma solidity >=0.6.0;
33

44
import "hardhat/console.sol";

0 commit comments

Comments
 (0)