Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zohodesk/codestandard-analytics

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zohodesk/codestandard-analytics - npm Package Compare versions

Comparing version 0.0.1-exp-1 to 0.0.1-exp-2

build/core/sonar-dependencies/java-jar/sonar-scanner.jar

2

build/core/eslint/filterReports.js

@@ -33,3 +33,3 @@ "use strict";

// To set pipeline status
message["severity"] == 2 ? global.reportStatus = false : null;
message["severity"] == 2 ? global.analytics.reportStatus = false : null;
return true;

@@ -36,0 +36,0 @@ }

@@ -8,3 +8,4 @@ "use strict";

exports.constructConfigPath = constructConfigPath;
exports.filterJsFiles = filterJsFiles;
exports.filterFiles = filterFiles;
exports.getFiles = getFiles;
exports.getFilesFromBranchDiff = getFilesFromBranchDiff;

@@ -28,5 +29,6 @@ exports.getLintReportPath = getLintReportPath;

const rootPath = getRootGitPath();
return diffJson === null || diffJson === void 0 ? void 0 : diffJson.diffs.map(diff => {
const diffFiles = diffJson === null || diffJson === void 0 ? void 0 : diffJson.diffs.map(diff => {
return _path.default.resolve(rootPath, diff === null || diff === void 0 ? void 0 : diff.new_path);
});
return filterFiles(diffFiles);
}

@@ -81,4 +83,3 @@

}
const filteredDiffFiles = getFilesFromBranchDiff(branch_diff_json);
return filteredDiffFiles;
return getFilesFromBranchDiff(branch_diff_json);
}

@@ -98,25 +99,23 @@

// /**
// * @function getConfigurationFilePath - get lint configuration path based on cli command
// * @returns {string}
// */
// function getConfigurationFilePath() {
// const configPath = constructConfigPath();
// const eslintConfigPath = path.resolve(process.cwd(), ".eslintrc.js");
// if (checkIfFileExists(configPath)) {
// return configPath;
// }
// if (!checkIfFileExists(configPath) && !checkIfFileExists(eslintConfigPath)) {
// Logger.log(
// Logger.FAILURE_TYPE,
// `configuration file or eslint configuration files is not exist`
// );
// process.exit(0);
// }
// if (checkIfFileExists(eslintConfigPath)) {
// return eslintConfigPath;
// }
// }
/**
*
* @function getFiles - method returns a js and feature and branchDiff based on env
* @param {string} env - gives running env
* @param {string} dir - path of directory or file
* @param {path} branchDiffPath - path of branch diff json
* @returns {{JsFiles:[],featureFiles:[],branch_diff_json:[]}}
*/
function getFiles(env, dir, branchDiffPath = false) {
if (env == 'dev') {
const listOfFiles = dir && (0, _fileUtils.checkIfFileExists)(dir) ? dir : false;
return (0, _fileUtils.getFilesPathFromRootDir)(listOfFiles, []);
}
if (env == 'ci') {
const _branch_diff_json = branchDiffPath && (0, _fileUtils.checkIfFileExists)(branchDiffPath) ? require(resolvePath(branchDiffPath)) : [{}];
return {
...getStagedFiles_CI(_branch_diff_json),
branch_diff_json: _branch_diff_json
};
}
}
function constructConfigPath() {

@@ -127,3 +126,3 @@ return _path.default.resolve(process.cwd(), "lint.config.js");

/**
* @function filterJsFiles - filter javascript files. omit feature files
* @function filterFiles - filter javascript files. omit feature files
* @param {Array<String>} lintFiles - linter files as Array

@@ -133,9 +132,14 @@ * @returns {Array<String>}

function filterJsFiles(lintFiles) {
return lintFiles.filter(file => {
if (file.includes('.feature')) {
return false;
function filterFiles(lintFiles) {
return lintFiles.reduce((files, currentFile) => {
if (currentFile.includes('.feature')) {
files.featureFiles.push(currentFile);
} else {
files.JsFiles.push(currentFile);
}
return true;
return files;
}, {
featureFiles: [],
JsFiles: []
});
}

@@ -22,6 +22,5 @@ "use strict";

async function executeLintAnalysis(cliParams) {
global.reportStatus = true;
_logger.Logger.start('Start linting ...');
const {
diffPath = null,
var {
env,
dir = false

@@ -32,13 +31,15 @@ } = cliParams;

impactBased,
lintDirectory
branchDiffPath
} = (0, _fileUtils.getLintConfiguration)();
const linterFilesDirectory = dir && (0, _fileUtils.checkIfFileExists)(dir) ? dir : lintDirectory;
if (diffPath && linterFilesDirectory) {
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `\n Either give diff path or directory to lint file`);
if (env == 'ci' && dir || env == 'dev' && !dir) {
let errorMessage = env == 'ci' ? 'expected valid configuration' : env == 'dir' ? 'expected --dir path in cli' : 'issue in configuration';
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `\n running in ${env} mode. ${errorMessage}`);
process.exit(0);
}
const reportPath = (0, _getFileUtils.getLintReportPath)();
const branch_diff_json = !linterFilesDirectory && diffPath ? require((0, _getFileUtils.resolvePath)(diffPath)) : false;
var toLintFiles = linterFilesDirectory ? (0, _fileUtils.getFilesPathFromRootDir)(linterFilesDirectory) : branch_diff_json ? (0, _getFileUtils.getStagedFiles_CI)(branch_diff_json) : null;
const filteredLintReport = await startLint(branch_diff_json, toLintFiles, linterFilesDirectory, impactBased, ruleConfigurationPath);
var {
JsFiles,
branch_diff_json
} = (0, _getFileUtils.getFiles)(env, dir, branchDiffPath);
const filteredLintReport = await startLint(branch_diff_json, JsFiles, env, impactBased, ruleConfigurationPath);
_logger.Logger.stop();

@@ -61,15 +62,14 @@ _logger.Logger.cliLog(_logger.Logger.SUCCESS_TYPE, `Linting analysis completed successfully...`);

async function startLint(branchDiff = null, toLintFiles, linterFilesDirectory, impactBased, ruleConfigurationPath) {
async function startLint(branchDiff = null, toLintFiles, env, impactBased, ruleConfigurationPath) {
var eslint = createLint(ruleConfigurationPath);
var rulesArrayReport = [];
var LintFiles = (0, _getFileUtils.filterJsFiles)(toLintFiles);
return await new Promise(async resolve => {
if (linterFilesDirectory && LintFiles.length) {
rulesArrayReport = await eslint.lintFiles(LintFiles);
if (env == 'dev' && toLintFiles.length) {
rulesArrayReport = await eslint.lintFiles(toLintFiles);
}
if (branchDiff) {
if (env == 'ci' && branchDiff) {
const filterJsonMap = (0, _filterReports.filterDiffJson)(branchDiff);
for (let i = 0; i < LintFiles.length; i++) {
var singleFileReport = (await eslint.lintFiles(LintFiles[i])).pop();
if (impactBased === "true") {
for (let i = 0; i < toLintFiles.length; i++) {
var singleFileReport = (await eslint.lintFiles(toLintFiles[i])).pop();
if (impactBased === true) {
const {

@@ -76,0 +76,0 @@ filePath

@@ -33,3 +33,2 @@ "use strict";

if (currentDiffLine.startsWith("@")) {
// console.log('currentDiffLine',currentDiffLine)
isRemovedLineAdded = false;

@@ -46,8 +45,4 @@ if (tempDiffLinesArr.size > 0 && addedContent !== removedContent) {

let lineNos = currentDiffLine.split("@@")[1].trim().split(" ");
// console.log('lineNos',lineNos)
let removedLineDetail = lineNos[0].replace(/-/g, "").split(",");
// console.log('removedLineDetail',removedLineDetail)
let addedLineDetail = lineNos[1].replace(/\+/g, "").split(",");
// console.log('addedLineDetail',addedLineDetail)
addLineFrom = parseInt(addedLineDetail[0]);

@@ -57,9 +52,4 @@ removeLineFrom = parseInt(removedLineDetail[0]) + addedLineSubtractor;

} else {
// console.log('currentDiffLine - else',currentDiffLine)
let isLineChanged = (currentDiffLine.startsWith("+") || currentDiffLine.startsWith("-") && !isRemovedLineAdded) && currentDiffLine.trim().length > 1;
let currentDiffContent = currentDiffLine.substring(1).trim();
// console.log('addedLineSubtractor-else',addedLineSubtractor)
// console.log('removedContent-else',removedContent)
// console.log('addedContent-else',addedContent)
if (currentDiffLine.startsWith("-")) {

@@ -79,7 +69,5 @@ addedLineSubtractor--;

isRemovedLineAdded = !isRemovedLineAdded && currentDiffLine.startsWith("-") && currentDiffLine.trim().length > 1 || isRemovedLineAdded && currentDiffLine.startsWith("-");
// console.log('isRemovedLineAdded',isRemovedLineAdded)
}
}
}
// console.log('tempDiffLinesArr',tempDiffLinesArr)
if (tempDiffLinesArr.size > 0 && addedContent !== removedContent) {

@@ -86,0 +74,0 @@ tempDiffLinesArr.forEach(line => diffLinesArr.push(line));

@@ -12,2 +12,3 @@ "use strict";

constructor(lintHandler, metricsHandler, cliArguments) {
this._cliArguments = cliArguments;
this.lint = new lintHandler(cliArguments);

@@ -14,0 +15,0 @@ this.metric = new metricsHandler(cliArguments);

@@ -44,9 +44,7 @@ "use strict";

const {
repo = null,
branch = null,
username = null,
dir = null
dir = null,
diffPath = null
} = cliArgument;
const default_project = getProjectNameFrmGit();
var project_name = dir ? `${default_project}_dev_${timeSuffix}` : repo && branch && username ? `${repo}_${branch}_${username}` : `${default_project}_ci`;
var project_name = dir ? `${default_project}_dev` : diffPath ? `${default_project}_CI` : `${default_project}_dev_${timeSuffix}`;
return project_name;

@@ -58,3 +56,3 @@ }

/**
* @function getLintFiles_ci - filter files based on cli argument
* @function getLintFiles - filter files based on cli argument
* @param {Object} cliArgument - Object represent cli Argument

@@ -64,3 +62,3 @@ * @returns {Array<string>}

function getLintFiles_ci(cliArgument) {
function getLintFiles(cliArgument) {
var {

@@ -70,4 +68,5 @@ diffPath = false,

} = cliArgument;
if (dir && !diffPath) {
return (0, _fileUtils.getFilesPathFromRootDir)(dir);
const linterFilesDirectory = dir && (0, _fileUtils.checkIfFileExists)(dir) ? dir : false;
if (linterFilesDirectory && !diffPath) {
return (0, _fileUtils.getFilesPathFromRootDir)(linterFilesDirectory);
}

@@ -84,2 +83,13 @@ return (0, _getFileUtils.getFilesFromBranchDiff)(require((0, _getFileUtils.resolvePath)(diffPath)));

function getSonarProperties(cliObjects) {
const {
env,
dir
} = cliObjects;
const {
branchDiffPath
} = (0, _fileUtils.getLintConfiguration)();
const {
JsFiles,
featureFiles
} = (0, _getFileUtils.getFiles)(env, dir, branchDiffPath);
const sonarqube_host_url = getSonarHostUrl();

@@ -92,4 +102,4 @@ const sonar_scanner_path = (0, _rootPath.getSonarJarPath)();

var project_name = getProjectName(cliObjects);
var resultFilesPath = getTestFiles(cliObjects);
var source_directories = getLintFiles_ci(cliObjects);
var resultFilesPath = featureFiles;
var source_directories = JsFiles;
const command = ["-jar", sonar_scanner_path, `-Dsonar.host.url=${sonarqube_host_url}`, `-Dsonar.projectKey=${project_name}`, `-Dsonar.login=${Dlogin}`, `-Dsonar.password=${Dpassword}`, `-Dsonar.sources=${source_directories}`, `-Dsonar.tests=${resultFilesPath}`, "-Dsonar.language=js", `-Dsonar.working.directory=${getSonarArtifactsDir()}`, `-Dsonar.eslint.reportPaths=${(0, _getFileUtils.getLintReportPath)()}`, "-Dsonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info"];

@@ -96,0 +106,0 @@ return command;

@@ -23,4 +23,3 @@ "use strict";

_logger.Logger.createLogFile();
const cliObjects = cliParams;
const command = (0, _getSonarProperties.getSonarProperties)(cliObjects);
const command = (0, _getSonarProperties.getSonarProperties)(cliParams);
const child_process = (0, _child_process.spawn)("java", command);

@@ -40,2 +39,3 @@ _logger.Logger.start('Sending report to SonarQube ...');

child_process.on("close", code => {
code === 0 ? global.analytics.sonarQubeStatus = false : null;
_logger.Logger.stop();

@@ -46,5 +46,5 @@ (0, _sonarReportSummary.writeSummaryOfLint)(cliParams);

code === 0 ? _logger.Logger.cliLog(_logger.Logger.PATH_TYPE, `Report URL - ${(0, _sonarReportSummary.getSummaryOfLint)(cliParams).reportUrl}`) : null;
global.reportStatus ? _logger.Logger.cliLog(_logger.Logger.INFO_TYPE, `JSON report Path - ${(0, _getFileUtils.getLintReportPath)()}`) : null;
global.analytics.reportStatus ? _logger.Logger.cliLog(_logger.Logger.INFO_TYPE, `JSON report Path - ${(0, _getFileUtils.getLintReportPath)()}`) : null;
code === 0 ? _logger.Logger.cliLog(_logger.Logger.INFO_TYPE, `SonarQube Artifacts Path - ${(0, _getSonarProperties.getSonarArtifactsDir)()}`) : null;
});
}

@@ -21,10 +21,10 @@ "use strict";

function getSummaryOfLint(cliParams) {
var $projectName = (0, _getSonarProperties.getProjectName)(cliParams);
const {
lintJsonPath = null
} = cliParams;
var $projectName = (0, _getSonarProperties.getProjectName)(cliParams);
sonar_hostURL
} = (0, _fileUtils.getLintConfiguration)();
return {
projectName: $projectName,
reportUrl: `https://serverlinter-np.zohodesk.csez.zohocorpin.com/project/issues?id=${$projectName}&resolved=false`,
jsonReportPath: lintJsonPath || (0, _getFileUtils.getLintReportPath)().toString()
reportUrl: global.analytics.sonarQubeStatus === false ? `${sonar_hostURL}/project/issues?id=${$projectName}&resolved=false` : sonar_hostURL,
jsonReportPath: (0, _getFileUtils.getLintReportPath)().toString()
};

@@ -40,10 +40,9 @@ }

function getLintStatus(impactBased) {
if (global.reportStatus || !impactBased) {
if (impactBased == false) {
return {
status: reportStatus
reportStatus: true,
pipelineStatus: 'passed'
};
}
return {
status: reportStatus
};
return global.analytics;
}

@@ -60,3 +59,3 @@

impactBased
} = cliParams;
} = (0, _fileUtils.getLintConfiguration)();
(0, _fileUtils.writeFileContents)(_path.default.resolve(process.cwd(), "lint-report", "lint-summary.json"), JSON.stringify({

@@ -63,0 +62,0 @@ ...getSummaryOfLint(cliParams),

@@ -20,2 +20,7 @@ "use strict";

async function startLinterAnalysis() {
global.analytics = {
reportStatus: true,
pipelineStatus: 'passed',
sonarQubeStatus: true
};
const [,, action, ...option] = process.argv;

@@ -26,2 +31,3 @@ switch (action) {

const $cliObjects = (0, _cliArgsToObject.cliArgsToObject)(option);
$cliObjects.env = 'dev';
const execute = new _Execution.default(_Eslint.default, _SonarQube.default, $cliObjects);

@@ -31,7 +37,14 @@ await execute.executeLintHandler().finally(() => {

});
// await executeLintAnalysis($cliObjects).finally(() => {
// executeSonarAnalysis($cliObjects);
// });
break;
}
case "lint-ci":
{
const $cliObjects = (0, _cliArgsToObject.cliArgsToObject)(option);
$cliObjects.env = 'ci';
const execute = new _Execution.default(_Eslint.default, _SonarQube.default, $cliObjects);
await execute.executeLintHandler().finally(() => {
execute.executeMetricHandler();
});
break;
}
case "init":

@@ -38,0 +51,0 @@ {

@@ -1,10 +0,12 @@

import { constructConfigPath } from "../core/eslint/getFileUtils";
import {
checkIfFileExists,
readFileContents,
writeFileContents,
} from "../utils/fileUtils";
import { Logger } from "../utils/logger";
import path from "path";
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setupDefaultConfiguration = setupDefaultConfiguration;
var _getFileUtils = require("../core/eslint/getFileUtils");
var _fileUtils = require("../utils/fileUtils");
var _logger = require("../utils/logger");
var _path = _interopRequireDefault(require("path"));
/**

@@ -16,13 +18,11 @@ * @function setupDefaultConfiguration - starts initial setup configuration

function setupDefaultConfiguration() {
const configPath = constructConfigPath();
const sampleConfigPath = path.join(__dirname, "sampleLint.config.js");
if (checkIfFileExists(configPath) && typeof require(configPath) == "object") {
Logger.log(Logger.INFO_TYPE, `configuration file already exist`);
Logger.log(Logger.SUCCESS_TYPE, `configuration done .. `);
const configPath = (0, _getFileUtils.constructConfigPath)();
const sampleConfigPath = _path.default.join(__dirname, "sampleLint.config.js");
if ((0, _fileUtils.checkIfFileExists)(configPath) && typeof require(configPath) == "object") {
_logger.Logger.log(_logger.Logger.INFO_TYPE, `configuration file already exist`);
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `configuration done .. `);
process.exit(0);
}
writeFileContents(configPath, readFileContents(sampleConfigPath));
Logger.log(Logger.SUCCESS_TYPE, `configuration done .. `);
}
export { setupDefaultConfiguration };
(0, _fileUtils.writeFileContents)(configPath, (0, _fileUtils.readFileContents)(sampleConfigPath));
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `configuration done .. `);
}

@@ -8,3 +8,2 @@ const path = require("path");

* @property {boolean} impactBased - Indicates if the linting is impact-based.
* @property {string} lintDirectory - The directory path where the linting will occur.
* @property {string} lintReportPath - The path to the lint report JSON file.

@@ -16,15 +15,11 @@ * @property {string} sonar_host_URL - The URL of the SonarQube server.

/**
* Linting configuration settings.
* @type {LintConfiguration}
*/
module.exports = {
ruleConfigurationPath: path.resolve(process.cwd(), ".eslintrc.js"),
impactBased: false,
lintDirectory: path.resolve(process.cwd()),
impactBased: true,
lintReportPath: path.resolve(process.cwd(), "lint-report", "lintReport.json"),
sonar_host_URL: "https://serverlinter-np.zohodesk.csez.zohocorpin.com/",
sonar_hostURL: "https://serverlinter-np.zohodesk.csez.zohocorpin.com",
loginName: "developer",
password: "developer",
branchDiffPath:path.resolve(process.cwd(),"diffBranch.json")
};

@@ -128,3 +128,3 @@ "use strict";

});
return (0, _getFileUtils.filterJsFiles)(files);
return (0, _getFileUtils.filterFiles)(files);
}

@@ -131,0 +131,0 @@

@@ -15,4 +15,5 @@ "use strict";

*/
function getSonarJarPath() {
const jarPath = _path.default.resolve(__dirname, "..", "lint", "sonar-dependencies", "java-jar", "sonar-scanner-cli-4.8.0.2856.jar");
const jarPath = _path.default.resolve(__dirname, "..", "core", "sonar-dependencies", "java-jar", "sonar-scanner.jar");
if ((0, _fileUtils.checkIfFileExists)(jarPath)) {

@@ -19,0 +20,0 @@ return jarPath;

{
"name": "@zohodesk/codestandard-analytics",
"version": "0.0.1-exp-1",
"version": "0.0.1-exp-2",
"description": "linting tool",
"main": "./build/index.js",
"dependencies": {
"@zohodesk/codestandard-validator": "0.0.2",
"eslint": "8.57.0"

@@ -28,9 +29,4 @@ },

},
"husky": {
"hooks": {
"pre-commit": "echo testing linting"
}
},
"author": "",
"license": "ISC"
}

@@ -19,4 +19,3 @@ # Linter Analysis Tool

## flags
--repo - repos name
--branch - branch name
--username - username
--diff - response of branch diff api
--dir - directory to lint

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc