Skip to content

Commit

Permalink
use micromatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Oct 22, 2024
1 parent 6a41c62 commit 281c322
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions scripts/checks/inheritance-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

const path = require('path');
const graphlib = require('graphlib');
const match = require('micromatch');
const { findAll } = require('solidity-ast/utils');
const { _: artifacts } = require('yargs').argv;

// files to skip
const skipPatterns = ['contracts-exposed/**', 'contracts/mocks/**'];

for (const artifact of artifacts) {
const { output: solcOutput } = require(path.resolve(__dirname, '../..', artifact));

Expand All @@ -13,10 +17,7 @@ for (const artifact of artifacts) {
const linearized = [];

for (const source in solcOutput.contracts) {
if (['contracts-exposed/', 'contracts/mocks/'].some(pattern => source.startsWith(pattern))) {
continue;
}

if (match.any(source, skipPatterns)) continue;
for (const contractDef of findAll('ContractDefinition', solcOutput.sources[source].ast)) {
names[contractDef.id] = contractDef.name;
linearized.push(contractDef.linearizedBaseContracts);
Expand Down
8 changes: 4 additions & 4 deletions scripts/checks/pragma-consistency.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

const path = require('path');
const semver = require('semver');
const match = require('micromatch');
const { findAll } = require('solidity-ast/utils');
const { _: artifacts } = require('yargs').argv;

// files to skip
const skipPatterns = ['contracts-exposed/', 'contracts/mocks/WithInit.sol'];
const skip = source => skipPatterns.some(pattern => source.startsWith(pattern));
const skipPatterns = ['contracts-exposed/**', 'contracts/mocks/WithInit.sol'];

for (const artifact of artifacts) {
const { output: solcOutput } = require(path.resolve(__dirname, '../..', artifact));
Expand All @@ -16,7 +16,7 @@ for (const artifact of artifacts) {

// Extract pragma directive for all files
for (const source in solcOutput.contracts) {
if (skip(source)) continue;
if (match.any(source, skipPatterns)) continue;
for (const { literals } of findAll('PragmaDirective', solcOutput.sources[source].ast)) {
// There should only be one.
const [first, ...rest] = literals;
Expand All @@ -26,7 +26,7 @@ for (const artifact of artifacts) {

// Compare the pragma directive of the file, to that of the files it imports
for (const source in solcOutput.contracts) {
if (skip(source)) continue;
if (match.any(source, skipPatterns)) continue;
// minimum version of the compiler that matches source's pragma
const minVersion = semver.minVersion(pragma[source]);
// loop over all imports in source
Expand Down

0 comments on commit 281c322

Please sign in to comment.