Skip to content

Commit

Permalink
Remove use of any
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Oct 20, 2023
1 parent 5b9f32b commit 9155f51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/core/src/cli/validate/find-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('fully qualified - match', async t => {
fullyQualifiedName: 'contracts/MyContract.sol:Foo',
};

t.true(isMatch('contracts/MyContract.sol:Foo', sourceContract as any));
t.true(isMatch('contracts/MyContract.sol:Foo', sourceContract));
});

test('fully qualified without folder - match', async t => {
Expand All @@ -17,7 +17,7 @@ test('fully qualified without folder - match', async t => {
fullyQualifiedName: 'MyContract.sol:Foo',
};

t.true(isMatch('MyContract.sol:Foo', sourceContract as any));
t.true(isMatch('MyContract.sol:Foo', sourceContract));
});

test('short name - match', async t => {
Expand All @@ -26,7 +26,7 @@ test('short name - match', async t => {
fullyQualifiedName: 'contracts/MyContract.sol:Foo',
};

t.true(isMatch('Foo', sourceContract as any));
t.true(isMatch('Foo', sourceContract));
});

test('short name - match without folder', async t => {
Expand All @@ -35,7 +35,7 @@ test('short name - match without folder', async t => {
fullyQualifiedName: 'MyContract.sol:Foo',
};

t.true(isMatch('Foo', sourceContract as any));
t.true(isMatch('Foo', sourceContract));
});

test('short name with .sol - no match', async t => {
Expand All @@ -44,8 +44,8 @@ test('short name with .sol - no match', async t => {
fullyQualifiedName: 'contracts/MyContract.sol:Foo',
};

t.false(isMatch('MyContract.sol', sourceContract as any));
t.false(isMatch('Foo.sol', sourceContract as any));
t.false(isMatch('MyContract.sol', sourceContract));
t.false(isMatch('Foo.sol', sourceContract));
});

test('short name with .sol - match', async t => {
Expand All @@ -54,7 +54,7 @@ test('short name with .sol - match', async t => {
fullyQualifiedName: 'contracts/Foo.sol:Foo',
};

t.true(isMatch('Foo.sol', sourceContract as any));
t.true(isMatch('Foo.sol', sourceContract));
});

test('short name with .sol - match without folder', async t => {
Expand All @@ -63,5 +63,5 @@ test('short name with .sol - match without folder', async t => {
fullyQualifiedName: 'Foo.sol:Foo',
};

t.true(isMatch('Foo.sol', sourceContract as any));
t.true(isMatch('Foo.sol', sourceContract));
});
10 changes: 6 additions & 4 deletions packages/core/src/cli/validate/find-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export function findContract(contractName: string, origin: SourceContract | unde
}
}

export function isMatch(contractName: string, contract: SourceContract) {
type SourceContractIdentifier = Pick<SourceContract, 'name' | 'fullyQualifiedName'>;

export function isMatch(contractName: string, contract: SourceContractIdentifier) {
return (
contract.fullyQualifiedName === contractName || // contracts/MyContract.sol:MyContract
contract.name === contractName || // MyContract
Expand All @@ -52,7 +54,7 @@ export function isMatch(contractName: string, contract: SourceContract) {
);
}

function matchesDotSolAndName(contractName: string, contract: SourceContract) {
function matchesDotSolAndName(contractName: string, contract: SourceContractIdentifier) {
if (contractName.includes('.sol:')) {
const [fileWithoutExtension, name] = contractName.split('.sol:');
return matchesFullyQualifiedName(fileWithoutExtension, name, contract);
Expand All @@ -61,7 +63,7 @@ function matchesDotSolAndName(contractName: string, contract: SourceContract) {
}
}

function matchesDotSol(contractName: string, contract: SourceContract) {
function matchesDotSol(contractName: string, contract: SourceContractIdentifier) {
if (contractName.endsWith('.sol')) {
const name = contractName.slice(0, contractName.length - 4);
return matchesFullyQualifiedName(name, name, contract);
Expand All @@ -70,7 +72,7 @@ function matchesDotSol(contractName: string, contract: SourceContract) {
}
}

function matchesFullyQualifiedName(fileNameWithoutExtension: string, name: string, contract: SourceContract) {
function matchesFullyQualifiedName(fileNameWithoutExtension: string, name: string, contract: SourceContractIdentifier) {
const lastSlash = contract.fullyQualifiedName.lastIndexOf('/');
const fullyQualifiedWithoutPath =
lastSlash >= 0 ? contract.fullyQualifiedName.slice(lastSlash + 1) : contract.fullyQualifiedName;
Expand Down

0 comments on commit 9155f51

Please sign in to comment.