@zohodesk/codestandard-analytics
Advanced tools
Comparing version 0.0.1-exp-11 to 0.0.1-exp-12
@@ -13,3 +13,4 @@ "use strict"; | ||
var _getFileUtils = require("./getFileUtils"); | ||
var _fileUtils = require("../../utils/fileUtils"); | ||
// import { checkIfFileExists } from "../../utils/fileUtils"; | ||
/** | ||
@@ -16,0 +17,0 @@ * @function filterLintReportBasedOnImpactLine - Filter Report Based on Impact Line |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.getStagedFiles_preCommit = getStagedFiles_preCommit; | ||
exports.removeDiffFile = removeDiffFile; | ||
exports.resolvePath = resolvePath; | ||
@@ -21,2 +22,3 @@ var _path = _interopRequireDefault(require("path")); | ||
var _fileUtils = require("../../utils/fileUtils"); | ||
var _fs = require("fs"); | ||
/** | ||
@@ -31,3 +33,7 @@ * @function getFilesFromBranchDiff - filter file path From git diff json | ||
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); | ||
try { | ||
return _path.default.resolve(rootPath, diff === null || diff === void 0 ? void 0 : diff.new_path); | ||
} catch (error) { | ||
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, ` file does not exist. make sure that branch upto date ...`); | ||
} | ||
}); | ||
@@ -113,3 +119,7 @@ return filterFiles(diffFiles); | ||
if (env == 'ci') { | ||
const _branch_diff_json = branchDiffPath && (0, _fileUtils.checkIfFileExists)(branchDiffPath) ? require(resolvePath(branchDiffPath)) : [{}]; | ||
const _branch_diff_json = branchDiffPath && (0, _fileUtils.checkIfFileExists)(branchDiffPath) ? require(resolvePath(branchDiffPath)) : false; | ||
if (!_branch_diff_json) { | ||
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `branch diff file does not exists ...`); | ||
process.exit(0); | ||
} | ||
return { | ||
@@ -133,12 +143,23 @@ ...getStagedFiles_CI(_branch_diff_json), | ||
return lintFiles.reduce((files, currentFile) => { | ||
if (currentFile.includes('.feature')) { | ||
if (currentFile.includes('.feature') && (0, _fileUtils.checkIfFileExists)(currentFile)) { | ||
files.featureFiles.push(currentFile); | ||
} else { | ||
} | ||
if (currentFile.includes('.js') && (0, _fileUtils.checkIfFileExists)(currentFile)) { | ||
files.JsFiles.push(currentFile); | ||
} | ||
if (currentFile.includes('.css') && (0, _fileUtils.checkIfFileExists)(currentFile)) { | ||
files.CssFiles.push(currentFile); | ||
} | ||
return files; | ||
}, { | ||
featureFiles: [], | ||
JsFiles: [] | ||
JsFiles: [], | ||
CssFiles: [] | ||
}); | ||
} | ||
function removeDiffFile() { | ||
const { | ||
branchDiffPath | ||
} = (0, _fileUtils.getLintConfiguration)(); | ||
(0, _fs.unlinkSync)(branchDiffPath); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,3 +9,3 @@ value: true | ||
var _eslint = require("eslint"); | ||
var _path = _interopRequireWildcard(require("path")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _fileUtils = require("../../utils/fileUtils"); | ||
@@ -14,4 +15,2 @@ var _getFileUtils = require("./getFileUtils"); | ||
var _logger = require("../../utils/logger"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
/** | ||
@@ -42,3 +41,4 @@ * @function executeLintAnalysis - start lint analysis | ||
JsFiles, | ||
branch_diff_json | ||
branch_diff_json, | ||
CssFiles | ||
} = (0, _getFileUtils.getFiles)(env, dir, branchDiffPath); | ||
@@ -45,0 +45,0 @@ const filteredLintReport = await startLint(branch_diff_json, JsFiles, env, impactBased, ruleConfigurationPath); |
@@ -45,29 +45,29 @@ "use strict"; | ||
dir = null, | ||
diffPath = null | ||
diffPath = null, | ||
cmdExecuted | ||
} = cliArgument; | ||
const default_project = getProjectNameFrmGit(); | ||
var project_name = dir ? `${default_project}_dev` : diffPath ? `${default_project}_CI` : `${default_project}_dev_${timeSuffix}`; | ||
var project_name = dir ? `${default_project}_dev` : diffPath && cmdExecuted == 'lint-ci' ? `${default_project}_CI` : `${default_project}_dev_${timeSuffix}`; | ||
return project_name; | ||
} | ||
function getTestFiles(cliArgument) { | ||
return " "; | ||
} | ||
/** | ||
* @function getLintFiles - filter files based on cli argument | ||
* @param {Object} cliArgument - Object represent cli Argument | ||
* @returns {Array<string>} | ||
*/ | ||
function getLintFiles(cliArgument) { | ||
var { | ||
diffPath = false, | ||
dir = false | ||
} = cliArgument; | ||
const linterFilesDirectory = dir && (0, _fileUtils.checkIfFileExists)(dir) ? dir : false; | ||
if (linterFilesDirectory && !diffPath) { | ||
return (0, _fileUtils.getFilesPathFromRootDir)(linterFilesDirectory); | ||
} | ||
return (0, _getFileUtils.getFilesFromBranchDiff)(require((0, _getFileUtils.resolvePath)(diffPath))); | ||
} | ||
// function getTestFiles(cliArgument) { | ||
// return " "; | ||
// } | ||
// /** | ||
// * @function getLintFiles - filter files based on cli argument | ||
// * @param {Object} cliArgument - Object represent cli Argument | ||
// * @returns {Array<string>} | ||
// */ | ||
// function getLintFiles(cliArgument) { | ||
// var { diffPath = false, dir = false } = cliArgument; | ||
// const linterFilesDirectory = dir && checkIfFileExists(dir) ? dir : false | ||
// if (linterFilesDirectory && !diffPath) { | ||
// return getFilesPathFromRootDir(linterFilesDirectory); | ||
// } | ||
// return getFilesFromBranchDiff(require(resolvePath(diffPath))); | ||
// } | ||
/** | ||
@@ -74,0 +74,0 @@ * @function getSonarProperties - collect all sonar properties |
@@ -41,2 +41,3 @@ "use strict"; | ||
(0, _sonarReportSummary.writeSummaryOfLint)(cliParams); | ||
(0, _getFileUtils.removeDiffFile)(); | ||
_logger.Logger.cliLog(_logger.Logger.SUCCESS_TYPE, 'SonarQube analysis completed...'); | ||
@@ -43,0 +44,0 @@ _logger.Logger.cliLog(_logger.Logger.SUCCESS_TYPE, `Report ${code === 0 ? "successfully" : "failed"} sent to the server : Status - ${code === 0 ? "Success" : "Failure"}`); |
@@ -7,7 +7,7 @@ "use strict"; | ||
var _SonarQube = _interopRequireDefault(require("../core/handlers/libraryInterface/SonarQube")); | ||
var _helper = require("../setup/helper.js"); | ||
var _initialSetup = require("../setup/initialSetup"); | ||
var _cliArgsToObject = require("../utils/cliArgsToObject"); | ||
// import { executeLintAnalysis } from "../lint/eslint/runEslint"; | ||
// import { executeSonarAnalysis } from "../lint/sonar-dependencies/runSonar"; | ||
var _fileUtils = require("../utils/fileUtils.js"); | ||
var _request = require("../utils/request"); | ||
/** | ||
@@ -23,3 +23,3 @@ * | ||
reportStatus: true, | ||
pipelineStatus: 'passed', | ||
pipelineStatus: "passed", | ||
sonarQubeStatus: true | ||
@@ -31,4 +31,6 @@ }; | ||
{ | ||
(0, _fileUtils.checkConfigurationFileExist)(); | ||
const $cliObjects = (0, _cliArgsToObject.cliArgsToObject)(option); | ||
$cliObjects.env = 'dev'; | ||
$cliObjects.env = "dev"; | ||
$cliObjects.cmdExecuted = action; | ||
const execute = new _Execution.default(_Eslint.default, _SonarQube.default, $cliObjects); | ||
@@ -41,5 +43,9 @@ await execute.executeLintHandler().finally(() => { | ||
case "lint-ci": | ||
case "check-local": | ||
{ | ||
(0, _fileUtils.checkConfigurationFileExist)(); | ||
(0, _request.createBranchDiff)(); | ||
const $cliObjects = (0, _cliArgsToObject.cliArgsToObject)(option); | ||
$cliObjects.env = 'ci'; | ||
$cliObjects.env = "ci"; | ||
$cliObjects.cmdExecuted = action; | ||
const execute = new _Execution.default(_Eslint.default, _SonarQube.default, $cliObjects); | ||
@@ -53,8 +59,19 @@ await execute.executeLintHandler().finally(() => { | ||
{ | ||
// const $cliObjects = cliArgsToObject(option) | ||
(0, _initialSetup.setupDefaultConfiguration)(); | ||
break; | ||
} | ||
case "check": | ||
{ | ||
(0, _fileUtils.checkConfigurationFileExist)(); | ||
require("../core/eslint/ErrorBetweenBranches"); | ||
break; | ||
} | ||
case "help": | ||
{ | ||
(0, _helper.consoleHelperCommands)(); | ||
break; | ||
} | ||
default: | ||
{ | ||
(0, _helper.consoleHelperCommands)(); | ||
break; | ||
@@ -61,0 +78,0 @@ } |
@@ -20,3 +20,3 @@ "use strict"; | ||
const sampleConfigPath = _path.default.join(__dirname, "sampleLint.config.js"); | ||
if ((0, _fileUtils.checkIfFileExists)(configPath) && typeof require(configPath) == "object") { | ||
if ((0, _fileUtils.checkIfFileExists)(configPath) && checkBothConfigurationIsSame(configPath, sampleConfigPath)) { | ||
_logger.Logger.log(_logger.Logger.INFO_TYPE, `configuration file already exist`); | ||
@@ -28,2 +28,5 @@ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `configuration done .. `); | ||
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `configuration done .. `); | ||
} | ||
function checkBothConfigurationIsSame(configPath, sampleConfigPath) { | ||
return JSON.stringify(configPath) == JSON.stringify(sampleConfigPath); | ||
} |
@@ -12,2 +12,5 @@ const path = require("path"); | ||
* @property {string} password - The password for authentication with the SonarQube server. | ||
* @property {string} gitEndPoint - API EndPoint for Git Actions | ||
* @property {string} token - Encrypted Authentication Token | ||
* @property {string} compareBranch - Branch to compare diff | ||
*/ | ||
@@ -23,3 +26,6 @@ | ||
password: "developer", | ||
branchDiffPath:path.resolve(process.cwd(),"diffBranch.json") | ||
branchDiffPath:path.resolve(process.cwd(),"diffBranch.json"), | ||
gitEndPoint:"https://zgit.csez.zohocorpin.com", | ||
token:"w-OkG3f5OOM1Rkly8phZ", | ||
compareBranch:'release' | ||
}; |
@@ -7,2 +7,3 @@ "use strict"; | ||
}); | ||
exports.checkConfigurationFileExist = checkConfigurationFileExist; | ||
exports.checkIfFileExists = checkIfFileExists; | ||
@@ -16,5 +17,8 @@ exports.deleteFile = deleteFile; | ||
exports.writeFileContents = writeFileContents; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _fs = _interopRequireWildcard(require("fs")); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _getFileUtils = require("../core/eslint/getFileUtils"); | ||
var _logger = require("./logger"); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
/** | ||
@@ -145,4 +149,4 @@ * @function checkIfFileExists - checks if a file exists. | ||
* @function {isDirectory} - function checks given path is file or directory | ||
* @param {string} path - path of file to check | ||
* @returns {Boolean} | ||
* @param {string} path - path of file to check | ||
* @returns {Boolean} | ||
*/ | ||
@@ -152,2 +156,13 @@ | ||
return _fs.default.statSync(path).isDirectory(); | ||
} | ||
/** | ||
* @function checkConfigurationFileExist - check configuration present or not and console warn | ||
* @returns {void} | ||
*/ | ||
function checkConfigurationFileExist() { | ||
const isConfigPresent = (0, _fs.existsSync)(_path.default.resolve(process.cwd(), "lint.config.js")); | ||
isConfigPresent ? null : _logger.Logger.log(_logger.Logger.INFO_TYPE, `configuration file doesn't present kindly following command - npx ZDLintingFramework init`); | ||
return isConfigPresent; | ||
} |
{ | ||
"name": "@zohodesk/codestandard-analytics", | ||
"version": "0.0.1-exp-11", | ||
"version": "0.0.1-exp-12", | ||
"description": "linting tool", | ||
"main": "./build/index.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.25.6", | ||
"@zohodesk/codestandard-validator": "0.0.2", | ||
"eslint": "8.57.0" | ||
@@ -16,3 +14,3 @@ }, | ||
"chalk": "4.1.0", | ||
"commander": "12.1.0", | ||
"commander": "11.1.0", | ||
"prettier": "3.2.5" | ||
@@ -19,0 +17,0 @@ }, |
# Linter Analysis Tool | ||
## Overview | ||
This tool is designed to streamline the linting process for JavaScript projects using ESLint and SonarQube. It automates the configuration of ESLint and facilitates integration with your SonarQube server for comprehensive code analysis. | ||
## Configuration | ||
### ESLint | ||
ESLint configuration can be customized in the `.eslintrc.js` file. Refer to the ESLint documentation for available configuration options and rules. | ||
## SonarQube | ||
### Need to setup Sonar Jar in Java-jar Folder | ||
Configure your SonarQube server settings in the `getSonarProperties` file. Make sure to provide the correct server URL, authentication tokens, and project key. | ||
Configure your SonarQube server settings in the `lint.config.js` file. | ||
## Usage | ||
To lint your code using ESLint, run the following command: | ||
npx ZDLintingFramework lint | ||
## flags | ||
--diff - response of branch diff api | ||
--dir - directory to lint | ||
-** To run locally ** | ||
```bash | ||
npx npx ZDLintingFramework lint -- --dir=path/to/file | ||
``` | ||
--** To run CI ** | ||
```bash | ||
npx ZDLintingFramework lint-ci | ||
``` | ||
## flags | ||
- `--dir` - specify directory to lint |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
723379
2
33
1889
38
14
8
- Removed@zohodesk/codestandard-validator@0.0.2(transitive)