encore-auditor
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -12,6 +12,4 @@ #!/usr/bin/env node | ||
.option('--debug', 'Debug encore-auditor program') | ||
.option('--exclude-glob [glob]', 'Ignore files matching given glob.') | ||
.option('--include-directory [directory]', 'Analyze files in given directory') | ||
.parse(process.argv); | ||
cli(program); |
'use strict'; | ||
const Auditor = require('./encore-auditor'); | ||
const BasicReporter = require('./basic-reporter'); | ||
const _ = require('lodash'); | ||
const Auditor = require('./encore-auditor'); | ||
const util = require('util'); | ||
@@ -14,10 +15,25 @@ | ||
// Legacy audits are for deprecations in LTS block(s). | ||
let ltsAudits = require('./audits/blank'); // none for initial release | ||
// Current audits are for deprecations in current major block. | ||
let currentAudits = require('./audits/onedot'); | ||
config.audits = [ ltsAudits, currentAudits ]; | ||
if (program.debug) { | ||
console.log('CONFIG:\n', util.inspect(config)); | ||
console.log('OPTIONS:\n', util.inspect(options)); | ||
console.log('OPTIONS:\n', util.inspect(options, { depth: null })); | ||
console.log('CONFIG:\n', util.inspect(config, { depth: null })); | ||
return; | ||
} | ||
let auditor = new Auditor(); | ||
auditor.analyze(); | ||
// Custom Rules should be fixed AT EARLIEST CONVENIENCE | ||
//config.customRules = require(path_to_custom.json); | ||
let auditor = new Auditor(config); | ||
auditor.analyze().then((results) => { | ||
let reporter = new BasicReporter(results); | ||
reporter.report(); | ||
}).catch((err) => { | ||
console.log('Something broke with the auditor.', err); | ||
}); | ||
}; |
'use strict' | ||
const _ = require('lodash'); | ||
const glob = require('glob'); | ||
const util = require('util'); | ||
const fs = require('fs'); | ||
module.exports = class Auditor { | ||
constructor () { | ||
console.log('NEW Auditor'); | ||
constructor (config) { | ||
this.globs = config.globs; | ||
this.audits = config.audits; | ||
this.config = config; | ||
} | ||
// Start code analysis here! | ||
analyze() { | ||
// Start code analysis here! | ||
console.log('Analyzing!'); | ||
return Promise.all([ | ||
this.analysisOf('markup'), | ||
this.analysisOf('styles'), | ||
this.analysisOf('scripts'), | ||
this.analysisOf('tests') | ||
]); | ||
} | ||
/** | ||
* @param {String} ilk | ||
* - `markup` | ||
* - `styles` | ||
* - `scripts` | ||
* - `tests` | ||
* @returns {Promise<Array>} Get array of results when promise resolves. | ||
*/ | ||
analysisOf(ilk) { | ||
let audits = this.audits; | ||
let promise = new Promise((resolve, reject) => { | ||
glob(this.globs[ilk], (err, paths) => { | ||
if (err) reject(err); | ||
let results = paths.reduce((allResults, path) => { | ||
if (path.match(/bower_components|node_modules/)) { | ||
return allResults; | ||
} | ||
let file = fs.readFileSync(path, 'utf8'); | ||
// iterate over Current and LTS audit signatures | ||
audits.forEach((audit) => { // O(n) | ||
let lineNo = 0; | ||
file.split('\n').forEach((line) => { // O(n) | ||
lineNo++; | ||
audit.signatures[ilk].forEach((signature) => { // O(n) | ||
if (line.match(signature.pattern)) { | ||
allResults.push({ | ||
signature: signature, | ||
file: { | ||
path: path, | ||
line: line, | ||
lineNumber: lineNo | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
return allResults; | ||
}, []);//paths | ||
resolve(results); | ||
});//glob | ||
});//Promise() | ||
return promise; | ||
}//analysisOf(ilk) | ||
}//Auditor |
{ | ||
"name": "encore-auditor", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Source code analyzer for EncoreUI applications.", | ||
@@ -17,2 +17,3 @@ "main": "./lib/encore-auditor.js", | ||
"dependencies": { | ||
"chalk": "^1.1.3", | ||
"commander": "^2.9.0", | ||
@@ -28,16 +29,8 @@ "glob": "^7.0.3", | ||
"globs": { | ||
"markdown": [ | ||
"app/**/*.html" | ||
], | ||
"style": [ | ||
"app/**/*.less" | ||
], | ||
"scripts": [ | ||
"app/**/*.js" | ||
], | ||
"tests": [ | ||
"test/**/*.js" | ||
] | ||
"markup": "{app,src}/**/*.html", | ||
"styles": "{app,src}/**/*.less", | ||
"scripts": "{app,src}/**/*.js", | ||
"tests": "test/**/*.js" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
22961
9
486
4
2
1
+ Addedchalk@^1.1.3
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)