@sap/di.code-validation.core
Advanced tools
Comparing version 1.0.9 to 1.0.12
@@ -1,1 +0,1 @@ | ||
{"bin":{"validationframework":"bin/run.js"},"bugs":{"url":"https://github.com/DevX/CodeValidation/issues"},"config":{},"dependencies":{"optionator":"0.8.1"},"description":"Code validation","devDependencies":{"amdefine":"1.0.0","bump":"0.2.5","chai":"3.5.0","chai-string":"^1.3.0","debug":"^2.6.3","eslint":"^3.0.1","grunt":"^1.0.1","grunt-bump":"0.7.0","grunt-contrib-clean":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-istanbul-coverage":"^0.1.4","grunt-mocha-istanbul":"^5.0.2","grunt-mocha-test":"^0.13.2","gruntify-eslint":"^2.0.0","istanbul":"^0.4.5","mocha":"^3.1.2","mocha-junit-reporter":"^1.12.1","sinon":"1.17.2","whitesource":"0.3.13"},"engines":{"npm":">=3.0.0"},"homepage":"https://github.com/DevX/CodeValidation#readme","main":"./src/api.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/di.code-validation.core","optionalDependencies":{},"readme":"# di.code-validation.core \ncode validation controller for DI.\nreturning issues in code according to validators configured\n\n### install\n\nnpm install di.code-validation.core --save-dev\n\n### CodeValidation API\n\n```javascript\nexecuteForProject(projectPath, workspaceRootName, configuration, callbackFunction)\n```\n\n_basePath_ - full path for the validated folder location\n\n_options_ - an object to set additional options for execution and return values processing.\n\n_options.pathPrefix_ - validation issues paths are relative to the project path. _pathPrefix enable to set constant prefix to the returned path.\n\n_configuration_ - configuration of the validators to execute. object of type _ValidationConfig_\n\n_callbackFunction_ - callback of results. (TBD: add also failure for callback?)\n\n_ValidationConfig_ structure:\n```javascript\n {\n \"validators\" : {\n \"validator1\" : {\n \"extensions\" : ['.js', '.xsjs'],\n \"filters\": {\n \"levels\" :[\"error\", \"warning\", \"info\"]\n }\n },\n \"validator2\" : {\n \"extensions\" : ['.new'],\n \"filters\": {\n \"levels\" :[\"error\"]\n }\n }\n ....\n }\n }\n```\n\n_result_ structure:\n```javascript\n{\n \"validator_id\" : {\n \"issues\" : {\n \"relative_file_path\" : [\n {\n \"category\" : \"Possible Error\",\n \"checker\" : \"validator checker name\",\n \"column\" : 1,\n \"line\" : 14,\n \"message\" : \"some message\",\n \"path\" : \"relative_file_path\",\n \"ruleId\" : \"optional name of rule\",\n \"severity\" : \"error\"\n }\n ....\n ]\n }\n ....\n }\n}\n```\n\n#### validator API\n\nEach validator should implement following API:\n\n```javascript\n validateFiles(validationMetadata, fileResources)\n```\n\n _validationMetadata_ - contains following methods:\n \n getRootPath() - workspaceRootName\n \n getLevels() - array of levels of issues to return\n \n _fileResources_ - array of files to validate (TBD: enable validation by extension of regular expression)\n \n getPath() - returns the file full path\n \n getText() - returns the text in the file\n\n#### run validation from command line\n\nnode di.code-validation.core\\bin\\run.js \"project file location\" \"client workspace root path\"\n\n--c \"configuration file location\" - file with validation configuration. if not supplied defaults used.\n\nExample for configuration file:\n\n```javascript\n var configParam = { \n \"validators\" : { \n \"di.code-validation.js\" : { \n \"extensions\" : [\".js\", \".xsjs\"], \n \"filters\": { \n \"levels\" :[\"error\", \"warning\", \"info\"] \n } \n } \n } \n };\n module.exports = configParam;\n```\n\n--l \"log file\" - location of the outpul log file. default is the execution directory\n\n### default configuration:\n\n```javascript\n validators: {\n \"di.code-validation.js\": {\n extensions: [\".js\", \".xsjs\"]\n },\n \"di.code-validation.xml\": {\n extensions: [ \".xml\"]\n }\n }\n```\n\n","readmeFilename":"README.md","repository":{"type":"git","url":"git+https://github.com/DevX/CodeValidation.git"},"scripts":{"test":"mocha"},"version":"1.0.9","license":"SEE LICENSE IN developer-license-3.1.txt"} | ||
{"bin":{"validationframework":"bin/run.js"},"bugs":{"url":"https://github.com/DevX/CodeValidation/issues"},"config":{},"dependencies":{"optionator":"0.8.1"},"description":"Code validation","devDependencies":{"amdefine":"1.0.0","bump":"0.2.5","chai":"3.5.0","chai-string":"^1.3.0","debug":"^2.6.3","eslint":"^3.0.1","grunt":"^1.0.1","grunt-bump":"0.7.0","grunt-contrib-clean":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-istanbul-coverage":"^0.1.4","grunt-mocha-istanbul":"^5.0.2","grunt-mocha-test":"^0.13.2","gruntify-eslint":"^2.0.0","istanbul":"^0.4.5","mocha":"^3.1.2","mocha-junit-reporter":"^1.12.1","sinon":"1.17.2","whitesource":"0.3.13"},"engines":{"npm":">=3.0.0"},"homepage":"https://github.com/DevX/CodeValidation#readme","main":"./src/api.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/di.code-validation.core","optionalDependencies":{},"readme":"# di.code-validation.core \ncode validation controller for DI.\nreturning issues in code according to validators configured\n\n### install\n\nnpm install di.code-validation.core --save-dev\n\n### CodeValidation API\n\n```javascript\nexecuteForProject(projectPath, workspaceRootName, configuration, callbackFunction)\n```\n\n_basePath_ - full path for the validated folder location\n\n_options_ - an object to set additional options for execution and return values processing.\n\n_options.pathPrefix_ - validation issues paths are relative to the project path. _pathPrefix enable to set constant prefix to the returned path.\n\n_configuration_ - configuration of the validators to execute. object of type _ValidationConfig_\n\n_callbackFunction_ - callback of results. (TBD: add also failure for callback?)\n\n_ValidationConfig_ structure:\n```javascript\n {\n \"validators\" : {\n \"validator1\" : {\n \"extensions\" : ['.js', '.xsjs'],\n \"filters\": {\n \"levels\" :[\"error\", \"warning\", \"info\"]\n }\n },\n \"validator2\" : {\n \"extensions\" : ['.new'],\n \"filters\": {\n \"levels\" :[\"error\"]\n }\n }\n ....\n }\n }\n```\n\n_result_ structure:\n```javascript\n{\n \"validator_id\" : {\n \"issues\" : {\n \"relative_file_path\" : [\n {\n \"category\" : \"Possible Error\",\n \"checker\" : \"validator checker name\",\n \"column\" : 1,\n \"line\" : 14,\n \"message\" : \"some message\",\n \"path\" : \"relative_file_path\",\n \"ruleId\" : \"optional name of rule\",\n \"severity\" : \"error\"\n }\n ....\n ]\n }\n ....\n }\n}\n```\n\n#### validator API\n\nEach validator should implement following API:\n\n```javascript\n validateFiles(validationMetadata, fileResources)\n```\n\n _validationMetadata_ - contains following methods:\n \n getRootPath() - workspaceRootName\n \n getLevels() - array of levels of issues to return\n \n _fileResources_ - array of files to validate (TBD: enable validation by extension of regular expression)\n \n getPath() - returns the file full path\n \n getText() - returns the text in the file\n\n#### run validation from command line\n\nnode di.code-validation.core\\bin\\run.js \"project file location\" \"client workspace root path\"\n\n--c \"configuration file location\" - file with validation configuration. if not supplied defaults used.\n\nExample for configuration file:\n\n```javascript\n var configParam = { \n \"validators\" : { \n \"di.code-validation.js\" : { \n \"extensions\" : [\".js\", \".xsjs\"], \n \"filters\": { \n \"levels\" :[\"error\", \"warning\", \"info\"] \n } \n } \n } \n };\n module.exports = configParam;\n```\n\n--l \"log file\" - location of the outpul log file. default is the execution directory\n\n### default configuration:\n\n```javascript\n validators: {\n \"di.code-validation.js\": {\n extensions: [\".js\", \".xsjs\"]\n },\n \"di.code-validation.xml\": {\n extensions: [ \".xml\"]\n }\n }\n```\n\n","readmeFilename":"README.md","repository":{"type":"git","url":"git+https://github.com/DevX/CodeValidation.git"},"scripts":{"test":"mocha"},"version":"1.0.12","license":"SEE LICENSE IN developer-license-3.1.txt"} |
@@ -69,4 +69,55 @@ var path = require('path'), | ||
/** | ||
* return list of all files in directory according to extensions | ||
* listFilteredFilesSync('./rootDir', '.html') ==> ['./rootDir/src/a.html','./rootDir/src/build/index.html'] | ||
* @param {String} rootPath | ||
* @param {Object} options {extensions: ['.html', ...], ignoredPaths: ['projPath/dist', 'projPath/node_modules' ...]} | ||
* @return {Array} Result files with path string in an array | ||
*/ | ||
function listFilteredFilesSync(rootPath,options) { | ||
var paths = []; | ||
var extensions; | ||
var ignoredPaths = []; | ||
if (Array.isArray(options)) { | ||
extensions = options; | ||
} else { | ||
extensions = options ? options.extensions : undefined; | ||
ignoredPaths = options ? options.ignoredPaths || [] : []; | ||
} | ||
if (!fs.existsSync(rootPath)) { | ||
console.log("directory not found ", rootPath); | ||
return paths; | ||
} | ||
var files = fs.readdirSync(rootPath); | ||
files.forEach(function (file) { | ||
var nestedPath = path.join(rootPath, file); | ||
if (ignoredPaths.indexOf(nestedPath) >= 0) { | ||
return; | ||
} | ||
var stat = fs.statSync(nestedPath); | ||
if (stat && stat.isDirectory()) { | ||
var res = listFilteredFilesSync(nestedPath, options); | ||
paths = paths.concat(res); | ||
} else { | ||
if (!extensions) { | ||
paths.push(nestedPath); | ||
} else { | ||
extensions.forEach(function (filter) { | ||
if (path.extname(nestedPath) === filter) { | ||
paths.push(nestedPath); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
return paths; | ||
} | ||
module.exports = { | ||
listFilteredFiles:listFilteredFiles | ||
listFilteredFiles:listFilteredFiles, | ||
listFilteredFilesSync:listFilteredFilesSync | ||
}; |
@@ -77,24 +77,8 @@ var path = require("path"); | ||
validationProvidersCall[providerName](function (results) { | ||
var allIssues = {}; | ||
var result = results || {}; | ||
var issues = result.issues || []; | ||
//var status = result.status || "success"; | ||
//var messages = result.messages || []; | ||
issues.forEach(function (issue) { | ||
var filePath = issue.path; | ||
var resultPath = path.relative(projectPath, filePath); | ||
if (typeof options === 'string') { | ||
resultPath = path.join(options || "", resultPath); | ||
} else { | ||
resultPath = path.join(options && options.pathPrefix || "", resultPath); | ||
Promise.resolve(results).then(function(results){ | ||
resolveResults(projectPath, options, allResults, providerName, results); | ||
if (!--pendingValidations) { | ||
done(allResults); | ||
} | ||
issue.path = resultPath; | ||
allIssues[resultPath] = allIssues[resultPath] || []; | ||
allIssues[resultPath] = allIssues[resultPath].concat(issue); | ||
}); | ||
allResults[providerName] = {"issues": allIssues}; | ||
if (!--pendingValidations) { | ||
done(allResults); | ||
} | ||
}) | ||
}); | ||
@@ -108,2 +92,22 @@ } catch (e) { | ||
function resolveResults(projectPath, options, allResults, providerName, results){ | ||
var result = results || {}; | ||
var issues = result.issues || []; | ||
var allIssues = {}; | ||
issues.forEach(function (issue) { | ||
var filePath = issue.path; | ||
var resultPath = path.relative(projectPath, filePath); | ||
if (typeof options === 'string') { | ||
resultPath = path.join(options || "", resultPath); | ||
} else { | ||
resultPath = path.join(options && options.pathPrefix || "", resultPath); | ||
} | ||
issue.path = resultPath; | ||
allIssues[resultPath] = allIssues[resultPath] || []; | ||
allIssues[resultPath] = allIssues[resultPath].concat(issue); | ||
}); | ||
allResults[providerName] = {"issues": allIssues}; | ||
} | ||
function executeForProject(basePath, options, validationConfig, done) { | ||
@@ -117,7 +121,2 @@ var validationProviders = this.__loadValidators(validationConfig.getValidators()); | ||
__loadValidators: _loadValidators//public for testing purpose | ||
} | ||
} |
@@ -75,2 +75,63 @@ var expect = require('chai').expect; | ||
it('sync filters files from folder and its sub folders', function() { | ||
sandbox.stub(fs, 'existsSync').returns(true); | ||
sandbox.stub(fs, 'readdirSync', function (folderPath) { | ||
if (folderPath === 'root') | ||
return ['a.js', 'b.json', 'sub']; | ||
else if (folderPath === path.join('root', 'sub')) { | ||
return ['s.js']; | ||
} | ||
}); | ||
sandbox.stub(fs, 'statSync', function (folderPath) { | ||
return {'isDirectory': function() { | ||
return folderPath === 'root' || folderPath === path.join('root', 'sub'); | ||
}}; | ||
}); | ||
var paths = fileUtils.listFilteredFilesSync('root', ['.js']); | ||
expect(paths).to.exist; | ||
expect(paths).to.be.array; | ||
expect(paths).to.have.length(2); | ||
expect(paths).to.include(path.join('root', 'a.js')); | ||
expect(paths).to.include(path.join('root', 'sub', 's.js')); | ||
}); | ||
it('sync filters files from folder and its sub folders using options object', function() { | ||
sandbox.stub(fs, 'existsSync').returns(true); | ||
sandbox.stub(fs, 'readdirSync', function (folderPath) { | ||
if (folderPath === 'root') | ||
return ['a.js', 'b.json', 'sub']; | ||
else if (folderPath === path.join('root', 'sub')) { | ||
return ['s.js']; | ||
} | ||
}); | ||
sandbox.stub(fs, 'statSync', function (folderPath) { | ||
return {'isDirectory': function() { | ||
return folderPath === 'root' || folderPath === path.join('root', 'sub'); | ||
}}; | ||
}); | ||
var paths = fileUtils.listFilteredFilesSync('root', {extensions: ['.js']}); | ||
expect(paths).to.exist; | ||
expect(paths).to.be.array; | ||
expect(paths).to.have.length(2); | ||
expect(paths).to.include(path.join('root', 'a.js')); | ||
expect(paths).to.include(path.join('root', 'sub', 's.js')); | ||
}); | ||
it('sync all files from folder containing .js and .json files', function() { | ||
sandbox.stub(fs, 'existsSync').returns(true); | ||
sandbox.stub(fs, 'readdirSync', function (folderPath) { | ||
return ['a.js', 'b.json', 'c.js']; | ||
}); | ||
sandbox.stub(fs, 'statSync', function (folderPath) { | ||
return {'isDirectory': function() {return false;}}; | ||
}); | ||
var paths = fileUtils.listFilteredFilesSync('root'); | ||
expect(paths).to.exist; | ||
expect(paths).to.be.array; | ||
expect(paths).to.have.length(3); | ||
expect(paths).to.include(path.join('root', 'a.js')); | ||
expect(paths).to.include(path.join('root', 'c.js')); | ||
expect(paths).to.include(path.join('root', 'b.json')); | ||
}); | ||
afterEach(function () { | ||
@@ -77,0 +138,0 @@ sandbox.restore(); |
@@ -173,3 +173,3 @@ var chai = require('chai'); | ||
var pathPrefix = path.sep + projectName; | ||
var issues = validation.executeForProject(path.join(__dirname, "mock", projectName), pathPrefix, config, function (fullResult) { | ||
validation.executeForProject(path.join(__dirname, "mock", projectName), pathPrefix, config, function (fullResult) { | ||
expect(fullResult).to.be.object; | ||
@@ -220,3 +220,3 @@ expect(fullResult["dummyJsValidator1"]).not.to.be.empty; | ||
var pathPrefix = path.sep + projectName; | ||
var issues = validation.executeForProject(path.join(__dirname, "mock", projectName), pathPrefix, config, function (fullResult) { | ||
validation.executeForProject(path.join(__dirname, "mock", projectName), pathPrefix, config, function (fullResult) { | ||
expect(fullResult).to.be.object; | ||
@@ -223,0 +223,0 @@ expect(fullResult["dummyJsValidator1"]).not.to.be.empty; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
169356
1340
0
53