Skip to content

Commit

Permalink
Merge pull request #13 from Aniket-Engg/fix/#12
Browse files Browse the repository at this point in the history
solhint updated and applied
  • Loading branch information
Aniket-Engg authored Mar 29, 2019
2 parents 3eb633b + e250465 commit d98c946
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"esversion": 6
"esversion" : 9,
"strict" : true,
"node" : true
}
7 changes: 3 additions & 4 deletions bin/sol-profiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

"use strict";
const clc = require('cli-color'),
fs = require('fs'),
{ generateAndStore } = require('./../lib/generate'),
Expand All @@ -11,7 +12,6 @@ if(process.argv.length < 3) {
}

let path = process.argv[2];
/* jshint ignore:start */
var profiler = async(path) => {
try{
if(fs.lstatSync(path).isDirectory()){
Expand Down Expand Up @@ -40,9 +40,8 @@ var profiler = async(path) => {
}
}catch(error){
console.error(clc.redBright('Error in generating profile: ' + error.message));
};
}
/* jshint ignore:end */
}
};
module.exports = profiler(path);


12 changes: 5 additions & 7 deletions lib/generate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

const parser= require("solparse"),
clc = require("cli-color"),
table = require('table'),
Expand Down Expand Up @@ -27,7 +29,6 @@ let config = {
};


/* jshint ignore:start */
module.exports.generateAndStore = async(path) => {
try{
let tableRows = [];
Expand All @@ -37,7 +38,6 @@ module.exports.generateAndStore = async(path) => {
let pragma = await file.getPragma(path);
let code = await file.process(path, true);
let source = parser.parse(pragma + '\n\n' + code);
/* jshint ignore:end */
if(source.body[0].type == 'PragmaStatement'){
let pragmaData = source.body[0];
version = pragmaData.start_version.operator + pragmaData.start_version.version;
Expand All @@ -61,13 +61,11 @@ module.exports.generateAndStore = async(path) => {
});
}
});
/* jshint ignore:start */
var tableData = table.table(tableRows, config); /* jshint ignore:end */
var tableData = table.table(tableRows, config);
// Store profile in profiles folder
profile.store(tableData, contractName);
return tableData;
}catch(error){
throw error;
};

}
}
};
26 changes: 10 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Colourful Solidity Smart Contract Profiler",
"main": "index.js",
"scripts": {
"test": "jshint ./bin/sol-profiler.js"
"test": "jshint ./bin ./lib ./utils"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -33,6 +33,6 @@
"table": "^5.2.2"
},
"devDependencies": {
"jshint": "^2.9.7"
"jshint": "^2.10.2"
}
}
4 changes: 3 additions & 1 deletion utils/data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

const clc = require("cli-color");

module.exports.parseData = (contract, part) => {
Expand Down Expand Up @@ -84,4 +86,4 @@ module.exports.parseData = (contract, part) => {
returns : clc.white(returns),
modifiers : clc.white(custom)
};
}
};
6 changes: 4 additions & 2 deletions utils/directory.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"use strict";

const fs = require('fs');

var files = [];

function deepReadDir(path){
let filesArr = fs.readdirSync(path)
let filesArr = fs.readdirSync(path);
for(let file of filesArr){
if(fs.lstatSync(path + '/'+file).isDirectory())
deepReadDir(path + '/'+file);
else if(!files.includes(path + '/'+file))
files.push(path + '/'+file)
files.push(path + '/'+file);
}
return files;
}
Expand Down
17 changes: 9 additions & 8 deletions utils/file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const path = require('path'),
{execSync} = require('child_process');
{execSync} = require('child_process'),
fs = require('fs');

var regEx = {
Expand Down Expand Up @@ -33,15 +35,15 @@ var processFile = async(file, initCall = false) => {
}
catch(error){
throw error;
};
}
}
};

var processImports = async (file, content) => {
try{
let group='';
let result = [];
regEx.import.exec(''); // Resetting state of RegEx
while (group = regEx.import.exec(content)) {
while (group = regEx.import.exec(content)) { // jshint ignore:line
let _importFile = group[1];
let filePath = path.join(path.dirname(file), _importFile);
if(!fs.existsSync(filePath)){
Expand All @@ -58,15 +60,14 @@ var processImports = async (file, content) => {
}
catch(error){
throw error;
};

}
}
};

var getPragma = async(path) => {
let contents = fs.readFileSync(path, { encoding: 'utf-8' });
let group = regEx.pragma.exec(contents);
return group && group[1];
}
};

module.exports.process = processFile;
module.exports.getPragma = getPragma;
4 changes: 3 additions & 1 deletion utils/profile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

const path = require('path'),
fs = require('fs');

Expand All @@ -9,4 +11,4 @@ module.exports.store = (data, contractName) => {
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, ''); // clearing color formatting

fs.writeFileSync(path.join(process.cwd(), 'profiles', contractName + '_Profile.txt'), fileData);
}
};

0 comments on commit d98c946

Please sign in to comment.