Skip to content

Commit 55590fd

Browse files
authored
Fix linting errors (#143)
* Fix formatter errors * Fix eslint errors
1 parent fb208f0 commit 55590fd

33 files changed

+305
-185
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ syntest/
88
.*
99
*.json
1010
*.md
11+
12+
13+
# Since the javascript files have a lot of eslint errors that will be fixed by refactoring to typescript we ignore them for now.
14+
src/**/*.js

api.js

-3
This file was deleted.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"detect-port": "1.3.0",
5959
"figlet": "1.5.2",
6060
"fs-extra": "11.1.0",
61-
"global-modules": "^2.0.0",
6261
"globby": "^11.0.4",
6362
"lodash.clonedeep": "4.5.0",
6463
"mocha": "10.2.0",

src/SolidityLauncher.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { SoliditySuiteBuilder } from "./testbuilding/SoliditySuiteBuilder";
2222
import { SolidityRunner } from "./testcase/execution/SolidityRunner";
2323
import { SolidityRandomSampler } from "./testcase/sampling/SolidityRandomSampler";
2424
import { SolidityCFGFactory } from "./graph/SolidityCFGFactory";
25-
const SolidityParser = require("@solidity-parser/parser");
25+
import SolidityParser = require("@solidity-parser/parser");
2626

2727
import {
2828
Archive,
@@ -65,7 +65,6 @@ import { setNetwork, setNetworkFrom } from "./util/network";
6565
import {
6666
createTruffleConfig,
6767
getTestFilePaths,
68-
loadLibrary,
6968
setupTempFolders,
7069
} from "./util/fileSystem";
7170

@@ -88,8 +87,9 @@ import {
8887
collectInitialVariables,
8988
collectStatistics,
9089
} from "./util/collection";
91-
90+
// eslint-disable-next-line
9291
const pkg = require("../package.json");
92+
// eslint-disable-next-line
9393
const Web3 = require("web3");
9494

9595
export class SolidityLauncher {
@@ -190,7 +190,7 @@ export class SolidityLauncher {
190190

191191
getUserInterface().report("clear", []);
192192
getUserInterface().report("asciiArt", ["Syntest"]);
193-
getUserInterface().report("version", [require("../package.json").version]);
193+
getUserInterface().report("version", [pkg.version]);
194194

195195
this.config.compilers = {
196196
solc: {
@@ -204,7 +204,7 @@ export class SolidityLauncher {
204204
},
205205
},
206206
};
207-
this.truffle = loadLibrary(this.config);
207+
this.truffle = require("truffle");
208208
this.api = new API(myConfig);
209209

210210
if (args.includes("--help") || args.includes("-h")) {
@@ -327,7 +327,7 @@ export class SolidityLauncher {
327327
for (const target of targetPool.targets) {
328328
targetPaths.add(target.canonicalPath);
329329

330-
const [importsMap, dependencyMap] = targetPool.getImportDependencies(
330+
const { dependencyMap } = targetPool.getImportDependencies(
331331
target.canonicalPath,
332332
target.targetName
333333
);
@@ -366,7 +366,7 @@ export class SolidityLauncher {
366366
target.canonicalPath,
367367
target.targetName
368368
);
369-
const [importsMap, dependencyMap] = targetPool.getImportDependencies(
369+
const { importMap, dependencyMap } = targetPool.getImportDependencies(
370370
target.canonicalPath,
371371
target.targetName
372372
);
@@ -375,7 +375,7 @@ export class SolidityLauncher {
375375

376376
finalImportsMap = new Map([
377377
...Array.from(finalImportsMap.entries()),
378-
...Array.from(importsMap.entries()),
378+
...Array.from(importMap.entries()),
379379
]);
380380
finalDependencies = new Map([
381381
...Array.from(finalDependencies.entries()),
@@ -454,7 +454,7 @@ export class SolidityLauncher {
454454

455455
const ast = targetPool.getAST(targetPath);
456456

457-
const functionMap = targetPool.getFunctionMap(targetPath, target);
457+
const functionMap = targetPool.getFunctionMapSpecific(targetPath, target);
458458

459459
const currentSubject = new SoliditySubject(
460460
path.basename(targetPath),
@@ -468,12 +468,12 @@ export class SolidityLauncher {
468468
return new Archive();
469469
}
470470

471-
const [importsMap, dependencyMap] = targetPool.getImportDependencies(
471+
const { importMap, dependencyMap } = targetPool.getImportDependencies(
472472
targetPath,
473473
target
474474
);
475475

476-
const stringifier = new SolidityDecoder(importsMap, dependencyMap);
476+
const stringifier = new SolidityDecoder(importMap, dependencyMap);
477477
const suiteBuilder = new SoliditySuiteBuilder(
478478
stringifier,
479479
this.api,

src/analysis/static/SolidityTarget.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { DependencyAnalyzer } from "./dependency/DependencyAnalyzer";
2424
import { TargetContext } from "./dependency/TargetContext";
2525
import { ContractMetadata } from "./map/ContractMetadata";
2626
import { Graph } from "./Graph";
27+
import { SourceUnit } from "@solidity-parser/parser/dist/src/ast-types";
28+
import { ContractFunction } from "./map/ContractFunction";
2729

2830
/**
2931
* Target system under test.
@@ -41,12 +43,12 @@ export class SolidityTarget extends Target {
4143
protected _sources: Map<string, string>;
4244

4345
// Mapping: filepath -> AST
44-
protected _abstractSyntaxTrees: Map<string, any>;
46+
protected _abstractSyntaxTrees: Map<string, SourceUnit>;
4547

4648
protected _context: TargetContext<ContractMetadata>;
4749

4850
// Mapping: target name -> function name -> function
49-
protected _functions: Map<string, Map<string, any>>;
51+
protected _functions: Map<string, Map<string, ContractFunction>>;
5052

5153
// Mapping: target name -> (function name -> CFG)
5254
protected _controlFlowGraphs: Map<string, CFG>;
@@ -59,10 +61,10 @@ export class SolidityTarget extends Target {
5961
targetPath: string,
6062
targetName: string,
6163
sources: Map<string, string>,
62-
ASTs: Map<string, any>,
64+
ASTs: Map<string, SourceUnit>,
6365
context: TargetContext<ContractMetadata>,
64-
functions: Map<string, Map<string, any>>,
65-
CFGs: Map<string, any>,
66+
functions: Map<string, Map<string, ContractFunction>>,
67+
CFGs: Map<string, CFG>,
6668
linkingGraph: Graph<string>
6769
) {
6870
super();
@@ -92,8 +94,8 @@ export class SolidityTarget extends Target {
9294

9395
// Get source, AST, FunctionMap, and CFG for target under test
9496
const sources = new Map<string, string>();
95-
const abstractSyntaxTrees = new Map<string, any>();
96-
const functionMaps = new Map<string, Map<string, any>>();
97+
const abstractSyntaxTrees = new Map<string, SourceUnit>();
98+
const functionMaps = new Map<string, Map<string, ContractFunction>>();
9799
const controlFlowGraphs = new Map<string, CFG>();
98100

99101
sources.set(absoluteTargetPath, targetPool.getSource(absoluteTargetPath));
@@ -103,7 +105,7 @@ export class SolidityTarget extends Target {
103105
);
104106
functionMaps.set(
105107
targetName,
106-
targetPool.getFunctionMap(absoluteTargetPath, targetName)
108+
targetPool.getFunctionMapSpecific(absoluteTargetPath, targetName)
107109
);
108110
controlFlowGraphs.set(
109111
targetName,
@@ -125,7 +127,7 @@ export class SolidityTarget extends Target {
125127
context.getTargets(filePath).forEach((contractMetadata) => {
126128
functionMaps.set(
127129
contractMetadata.name,
128-
targetPool.getFunctionMap(filePath, contractMetadata.name)
130+
targetPool.getFunctionMapSpecific(filePath, contractMetadata.name)
129131
);
130132
});
131133
});
@@ -160,15 +162,15 @@ export class SolidityTarget extends Target {
160162
return this._sources.get(targetPath);
161163
}
162164

163-
getAST(targetPath: string): any {
165+
getAST(targetPath: string): SourceUnit {
164166
return this._abstractSyntaxTrees.get(targetPath);
165167
}
166168

167169
getContext(): TargetContext<ContractMetadata> {
168170
return this._context;
169171
}
170172

171-
getFunctions(targetName: string): Map<string, any> {
173+
getFunctions(targetName: string): Map<string, ContractFunction> {
172174
return this._functions.get(targetName);
173175
}
174176

src/analysis/static/SolidityTargetPool.ts

+39-15
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import { CFG, Properties, TargetPool, Target } from "@syntest/core";
2727
import { ImportVisitor } from "./dependency/ImportVisitor";
2828
import * as fs from "fs";
2929
import { LibraryVisitor } from "./dependency/LibraryVisitor";
30-
const SolidityParser = require("@solidity-parser/parser");
30+
import SolidityParser = require("@solidity-parser/parser");
31+
import { SourceUnit } from "@solidity-parser/parser/dist/src/ast-types";
32+
// eslint-disable-next-line
3133
const { outputFileSync, copySync } = require("fs-extra");
32-
const Instrumenter = require("../../../src/instrumentation/instrumenter"); // Local version
3334

3435
/**
3536
* Pool for retrieving and caching expensive processing calls.
@@ -48,7 +49,7 @@ export class SolidityTargetPool extends TargetPool {
4849
protected _sources: Map<string, string>;
4950

5051
// Mapping: filepath -> AST
51-
protected _abstractSyntaxTrees: Map<string, any>;
52+
protected _abstractSyntaxTrees: Map<string, SourceUnit>;
5253

5354
// Mapping: filepath -> target name -> target
5455
protected _targetMap: Map<string, Map<string, ContractMetadata>>;
@@ -62,10 +63,13 @@ export class SolidityTargetPool extends TargetPool {
6263
// Mapping: filepath -> target name -> (function name -> CFG)
6364
protected _controlFlowGraphs: Map<string, Map<string, CFG>>;
6465

65-
// Mapping: filepath -> target name -> [importsMap, dependencyMap]
66+
// Mapping: filepath -> target name -> {importsMap, dependencyMap}
6667
protected _dependencyMaps: Map<
6768
string,
68-
Map<string, [Map<string, string>, Map<string, Target[]>]>
69+
Map<
70+
string,
71+
{ importMap: Map<string, string>; dependencyMap: Map<string, Target[]> }
72+
>
6973
>;
7074

7175
constructor(
@@ -81,7 +85,7 @@ export class SolidityTargetPool extends TargetPool {
8185
this._controlFlowGraphGenerator = controlFlowGraphGenerator;
8286

8387
this._sources = new Map<string, string>();
84-
this._abstractSyntaxTrees = new Map<string, any>();
88+
this._abstractSyntaxTrees = new Map<string, SourceUnit>();
8589
this._targetMap = new Map<string, Map<string, ContractMetadata>>();
8690
this._functionMaps = new Map<
8791
string,
@@ -104,7 +108,7 @@ export class SolidityTargetPool extends TargetPool {
104108
}
105109
}
106110

107-
getAST(targetPath: string): any {
111+
getAST(targetPath: string): SourceUnit {
108112
const absoluteTargetPath = path.resolve(targetPath);
109113

110114
if (this._abstractSyntaxTrees.has(absoluteTargetPath)) {
@@ -118,7 +122,7 @@ export class SolidityTargetPool extends TargetPool {
118122
}
119123
}
120124

121-
getTargetMap(targetPath: string): Map<string, any> {
125+
getTargetMap(targetPath: string): Map<string, ContractMetadata> {
122126
const absoluteTargetPath = path.resolve(targetPath);
123127

124128
if (this._targetMap.has(absoluteTargetPath)) {
@@ -133,7 +137,26 @@ export class SolidityTargetPool extends TargetPool {
133137
}
134138
}
135139

136-
getFunctionMap(targetPath: string, targetName: string): Map<string, any> {
140+
getFunctionMap(
141+
targetPath: string
142+
): Map<string, Map<string, ContractFunction>> {
143+
const absoluteTargetPath = path.resolve(targetPath);
144+
145+
if (!this._functionMaps.has(absoluteTargetPath)) {
146+
const targetAST = this.getAST(absoluteTargetPath);
147+
const { targetMap, functionMap } =
148+
this._targetMapGenerator.generate(targetAST);
149+
this._targetMap.set(absoluteTargetPath, targetMap);
150+
this._functionMaps.set(absoluteTargetPath, functionMap);
151+
}
152+
153+
return this._functionMaps.get(absoluteTargetPath);
154+
}
155+
156+
getFunctionMapSpecific(
157+
targetPath: string,
158+
targetName: string
159+
): Map<string, ContractFunction> {
137160
const absoluteTargetPath = path.resolve(targetPath);
138161

139162
if (!this._functionMaps.has(absoluteTargetPath)) {
@@ -176,7 +199,7 @@ export class SolidityTargetPool extends TargetPool {
176199
getImportDependencies(
177200
targetPath: string,
178201
targetName: string
179-
): [Map<string, string>, Map<string, Target[]>] {
202+
): { importMap: Map<string, string>; dependencyMap: Map<string, Target[]> } {
180203
const absoluteTargetPath = path.resolve(targetPath);
181204

182205
if (!this._dependencyMaps.has(absoluteTargetPath))
@@ -186,8 +209,8 @@ export class SolidityTargetPool extends TargetPool {
186209
return this._dependencyMaps.get(absoluteTargetPath).get(targetName);
187210
} else {
188211
// Import the contract under test
189-
const importsMap = new Map<string, string>();
190-
importsMap.set(targetName, targetName);
212+
const importMap = new Map<string, string>();
213+
importMap.set(targetName, targetName);
191214

192215
// Find all external imports in the contract under test
193216
const importVisitor = new ImportVisitor();
@@ -214,7 +237,7 @@ export class SolidityTargetPool extends TargetPool {
214237
SolidityParser.visit(astLib, libraryVisitor);
215238

216239
// Import the external file in the test
217-
importsMap.set(
240+
importMap.set(
218241
path.basename(importPath).split(".")[0],
219242
path.basename(importPath).split(".")[0]
220243
);
@@ -237,11 +260,12 @@ export class SolidityTargetPool extends TargetPool {
237260

238261
this._dependencyMaps
239262
.get(targetPath)
240-
.set(targetName, [importsMap, dependencyMap]);
241-
return [importsMap, dependencyMap];
263+
.set(targetName, { importMap, dependencyMap });
264+
return { importMap, dependencyMap };
242265
}
243266
}
244267

268+
// eslint-disable-next-line
245269
async prepareAndInstrument(api: any): Promise<void> {
246270
const absoluteRootPath = path.resolve(Properties.target_root_directory);
247271

src/analysis/static/ast/ASTGenerator.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
const SolidityParser = require("@solidity-parser/parser");
19+
import SolidityParser = require("@solidity-parser/parser");
20+
import { SourceUnit } from "@solidity-parser/parser/dist/src/ast-types";
2021

2122
/**
2223
* Abstract Syntax Trees (AST) generator for targets.
@@ -29,8 +30,8 @@ export class ASTGenerator {
2930
*
3031
* @param targetSource The source of the target
3132
*/
32-
generate(targetSource: string): string {
33-
return SolidityParser.parse(targetSource, {
33+
generate(targetSource: string): SourceUnit {
34+
return <SourceUnit>SolidityParser.parse(targetSource, {
3435
loc: true,
3536
range: true,
3637
});

src/analysis/static/dependency/DependencyAnalyzer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ImportVisitor } from "./ImportVisitor";
2525
import { Graph } from "../Graph";
2626
import { PublicVisibility } from "../parsing/Visibility";
2727

28-
const SolidityParser = require("@solidity-parser/parser");
28+
import SolidityParser = require("@solidity-parser/parser");
2929

3030
/**
3131
* Analyzer that discovers all dependencies in the target.
@@ -183,7 +183,7 @@ export class DependencyAnalyzer {
183183
const contracts = this._targetPool.getTargetMap(importedFilePath);
184184
contracts.forEach((contractMetadata: ContractMetadata) => {
185185
if (contractMetadata.kind === ContractKind.Library) {
186-
const functions = this._targetPool.getFunctionMap(
186+
const functions = this._targetPool.getFunctionMapSpecific(
187187
importedFilePath,
188188
contractMetadata.name
189189
);

0 commit comments

Comments
 (0)