Skip to content

Commit

Permalink
Merge branch 'develop' into gx/package-with-absolute-path
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros authored Oct 27, 2023
2 parents cdcccee + f9804a8 commit 7852c32
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/best-practises/one-contract-per-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OneContractPerFileChecker extends BaseChecker {

SourceUnit(node) {
const contractDefinitionCount = node.children.reduce((count, child) => {
if (child.type === 'ContractDefinition') {
if (child.type === 'ContractDefinition' && child.kind !== 'interface') {
return count + 1
}
return count
Expand Down
38 changes: 37 additions & 1 deletion test/fixtures/best-practises/one-contract-per-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,40 @@ const THREE_CONTRACTS = `
uint256 public constant TESTC = "testC";
}
`
module.exports = { ONE_CONTRACT, TWO_CONTRACTS, THREE_CONTRACTS }

const TWO_LIBRARIES = `
pragma solidity 0.8.0;
library A { }
library B { }
`

const ONE_CONTRACT_WITH_INTERFACES = `
pragma solidity 0.8.0;
contract A { }
interface B { }
interface C { }
`

const ONE_LIBRARY_WITH_INTERFACES = `
pragma solidity 0.8.0;
library A { }
interface B { }
interface C { }
`

module.exports = {
ONE_CONTRACT,
TWO_CONTRACTS,
THREE_CONTRACTS,
TWO_LIBRARIES,
ONE_CONTRACT_WITH_INTERFACES,
ONE_LIBRARY_WITH_INTERFACES,
}
31 changes: 31 additions & 0 deletions test/rules/best-practises/one-contract-per-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ describe('Linter - one-contract-per-file', () => {
assertNoWarnings(report)
})

it('should not raise error for ONE contract and multiple interfaces in the same file', () => {
const code = contracts.ONE_CONTRACT_WITH_INTERFACES

const report = linter.processStr(code, {
rules: { 'one-contract-per-file': 'error' },
})

assertNoWarnings(report)
})

it('should not raise error for ONE library and multiple interfaces in the same file', () => {
const code = contracts.ONE_LIBRARY_WITH_INTERFACES

const report = linter.processStr(code, {
rules: { 'one-contract-per-file': 'error' },
})

assertNoWarnings(report)
})

it('should raise error for TWO contracts in same file', () => {
const code = contracts.TWO_CONTRACTS

Expand All @@ -34,4 +54,15 @@ describe('Linter - one-contract-per-file', () => {
assertErrorCount(report, 1)
assertErrorMessage(report, 'Found more than One contract per file. 3 contracts found!')
})

it('should raise error for TWO libraries in same file', () => {
const code = contracts.TWO_LIBRARIES

const report = linter.processStr(code, {
rules: { 'one-contract-per-file': 'error' },
})

assertErrorCount(report, 1)
assertErrorMessage(report, 'Found more than One contract per file. 2 contracts found!')
})
})

0 comments on commit 7852c32

Please sign in to comment.