@zohodesk/codestandard-validator 1.0.0-exp-2 → 1.0.0-exp-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/hooks/Precommit/commit.js +2 -2
- package/build/hooks/Precommit/errorhelpers.js +18 -7
- package/build/hooks/Precommit/lint.js +24 -30
- package/build/hooks/Precommit/pre-commit-default.js +369 -0
- package/build/hooks/Precommit/pre-commit.js +359 -353
- package/build/hooks/hook.js +15 -10
- package/build/utils/General/SonarQubeUtil.js +108 -0
- package/build/utils/PluginsInstallation/installPlugins.js +3 -10
- package/index.js +52 -0
- package/package.json +3 -3
package/build/hooks/hook.js
CHANGED
|
@@ -4,23 +4,23 @@ const {
|
|
|
4
4
|
getLastCommitHash,
|
|
5
5
|
getStoredCommitHash,
|
|
6
6
|
updateJsonFile
|
|
7
|
-
} = require(
|
|
7
|
+
} = require('../utils/General/getGeneralInfo');
|
|
8
8
|
const {
|
|
9
9
|
executeMethodsThatReturnBooleanValue
|
|
10
|
-
} = require(
|
|
10
|
+
} = require('../utils/General/wrapperFunctionToExecuteAFunction');
|
|
11
11
|
const {
|
|
12
12
|
cloneViaCdt
|
|
13
|
-
} = require(
|
|
13
|
+
} = require('../utils/CloneCommonLinterRepo/cloneViaCdt');
|
|
14
14
|
const {
|
|
15
15
|
getPluginsToInstall
|
|
16
|
-
} = require(
|
|
16
|
+
} = require('../utils/PluginsInstallation/checkIfPluginsAreInstalled');
|
|
17
17
|
const {
|
|
18
18
|
installPlugins
|
|
19
|
-
} = require(
|
|
20
|
-
const path = require(
|
|
19
|
+
} = require('../utils/PluginsInstallation/installPlugins');
|
|
20
|
+
const path = require('path');
|
|
21
21
|
const {
|
|
22
22
|
Logger
|
|
23
|
-
} = require(
|
|
23
|
+
} = require('../utils/Logger/Logger');
|
|
24
24
|
async function hooks() {
|
|
25
25
|
var jsonFilePath = path.join(__dirname, '..', '..', 'jsonUtils', 'fsUtils.json');
|
|
26
26
|
if (!(getLastCommitHash() == getStoredCommitHash())) {
|
|
@@ -29,12 +29,17 @@ async function hooks() {
|
|
|
29
29
|
return data;
|
|
30
30
|
});
|
|
31
31
|
Logger.log(Logger.INFO_TYPE, `Some rules and plugins are being fetched from a remote source and installed...`);
|
|
32
|
-
await executeMethodsThatReturnBooleanValue(
|
|
32
|
+
await executeMethodsThatReturnBooleanValue('Make sure zgit.csez.zohocorpin.com is accessible', cloneViaCdt, null);
|
|
33
33
|
const {
|
|
34
34
|
uninstalledPlugins
|
|
35
35
|
} = getPluginsToInstall();
|
|
36
|
-
await executeMethodsThatReturnBooleanValue(
|
|
36
|
+
await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
|
|
37
|
+
}
|
|
38
|
+
console.log(process.env);
|
|
39
|
+
if (process.env.defaultprecommit) {
|
|
40
|
+
require('./Precommit/pre-commit-default');
|
|
41
|
+
} else {
|
|
42
|
+
require('./Precommit/commit');
|
|
37
43
|
}
|
|
38
|
-
require('./Precommit/commit');
|
|
39
44
|
}
|
|
40
45
|
hooks();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Logger = require("../Logger/Logger");
|
|
8
|
+
var _getGeneralInfo = require("./getGeneralInfo");
|
|
9
|
+
var _child_process = require("child_process");
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a URL for searching issues in SonarQube.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} componentKey - The key of the component to search issues for.
|
|
14
|
+
* @returns {string} The fully constructed URL for the SonarQube issues search API.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function buildIssuesSearchUrl(componentKey) {
|
|
18
|
+
const {
|
|
19
|
+
metricServerHost
|
|
20
|
+
} = (0, _getGeneralInfo.getConfigurationPrecommit)();
|
|
21
|
+
const base = `${"https://client-linters.zdesk.csez.zohocorpin.com" || metricServerHost}/api/issues/search`;
|
|
22
|
+
const params = new URLSearchParams({
|
|
23
|
+
componentKeys: componentKey,
|
|
24
|
+
s: 'FILE_LINE',
|
|
25
|
+
resolved: 'false',
|
|
26
|
+
ps: '100',
|
|
27
|
+
facets: 'severities,types',
|
|
28
|
+
additionalFields: '_all',
|
|
29
|
+
timeZone: 'Asia/Calcutta'
|
|
30
|
+
});
|
|
31
|
+
return `${base}?${params.toString()}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extract minimal issue info from SonarQube issues JSON.
|
|
36
|
+
*/
|
|
37
|
+
function extractIssues(json) {
|
|
38
|
+
var hasIssue = false;
|
|
39
|
+
var totalIssues = json.issues.length;
|
|
40
|
+
if (!json || !Array.isArray(json.issues)) return [];
|
|
41
|
+
return {
|
|
42
|
+
issues: json.issues.map(i => {
|
|
43
|
+
if (i.severity == 'MAJOR') {
|
|
44
|
+
hasIssue = true;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
key: i.key,
|
|
48
|
+
component: i.component,
|
|
49
|
+
severity: i.severity,
|
|
50
|
+
type: i.type,
|
|
51
|
+
message: i.message,
|
|
52
|
+
line: i.line,
|
|
53
|
+
rule: i.rule,
|
|
54
|
+
status: i.status
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
hasIssue,
|
|
58
|
+
totalIssues
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Fetches project issues for a given component key using a cURL command.
|
|
64
|
+
*
|
|
65
|
+
* This function constructs a URL to search for issues, decrypts an API token,
|
|
66
|
+
* and executes a cURL command to retrieve the issues in JSON format. It then
|
|
67
|
+
* extracts and returns the issues along with the raw JSON response.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} componentKey - The key of the component for which issues are to be fetched.
|
|
70
|
+
* @returns {Object} An object containing:
|
|
71
|
+
* - {Object|null} raw: The raw JSON response from the API, or null if an error occurred.
|
|
72
|
+
* - {Array} issues: An array of extracted issues, or an empty array if an error occurred.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
function fetchProjectIssuesViaCurl(componentKey) {
|
|
76
|
+
_Logger.Logger.log(_Logger.Logger.INFO_TYPE, `\n Fetching issues (curl) for component: ${componentKey}`);
|
|
77
|
+
const url = buildIssuesSearchUrl(componentKey);
|
|
78
|
+
try {
|
|
79
|
+
const token = 'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), process.env.DECRYPT_TOKEN);
|
|
80
|
+
const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
|
|
81
|
+
console.log("command", command);
|
|
82
|
+
const output = (0, _child_process.execSync)(command).toString();
|
|
83
|
+
const json = JSON.parse(output);
|
|
84
|
+
const {
|
|
85
|
+
issues,
|
|
86
|
+
hasIssue,
|
|
87
|
+
totalIssues
|
|
88
|
+
} = extractIssues(json);
|
|
89
|
+
_Logger.Logger.log(_Logger.Logger.INFO_TYPE, `Retrieved ${issues.length} issues.`);
|
|
90
|
+
return {
|
|
91
|
+
raw: json,
|
|
92
|
+
issues,
|
|
93
|
+
hasIssue,
|
|
94
|
+
totalIssues
|
|
95
|
+
};
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_Logger.Logger.log(_Logger.Logger.FAILURE_TYPE, 'Issue fetching project issues (curl)');
|
|
98
|
+
_Logger.Logger.log(_Logger.Logger.FAILURE_TYPE, err);
|
|
99
|
+
return {
|
|
100
|
+
raw: null,
|
|
101
|
+
issues: [],
|
|
102
|
+
hasIssue: true,
|
|
103
|
+
totalIssues: 0
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
console.log(fetchProjectIssuesViaCurl('zohogc_client_master_rajasekar.hm_Dev-report'));
|
|
108
|
+
var _default = exports.default = fetchProjectIssuesViaCurl;
|
|
@@ -15,6 +15,7 @@ const {
|
|
|
15
15
|
const {
|
|
16
16
|
getNodeModulesPath
|
|
17
17
|
} = require('../General/getNodeModulesPath');
|
|
18
|
+
const path = require('path');
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
@@ -32,15 +33,7 @@ function installPlugins(pluginsToBeInstalled) {
|
|
|
32
33
|
}], '', 'Some issue occured while installing plugins', false, true);
|
|
33
34
|
if (arePluginsInstalledSuccessfully) {
|
|
34
35
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
35
|
-
|
|
36
|
-
// if(isPackageJsonRestored){
|
|
37
|
-
// createVersionControlFile(pluginsToBeInstalled)
|
|
38
|
-
// return true
|
|
39
|
-
// }
|
|
40
|
-
// else{
|
|
41
|
-
// Logger.log(Logger.FAILURE_TYPE,'Unable to restore package.json content')
|
|
42
|
-
// return false
|
|
43
|
-
// }
|
|
36
|
+
return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|
|
44
37
|
} else {
|
|
45
38
|
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins. Kindly retry the command");
|
|
46
39
|
return false;
|
|
@@ -66,7 +59,7 @@ function getPackageJsonContentBeforeInstallingPlugins() {
|
|
|
66
59
|
* @returns {Boolean} - indicating the success or failure of restoring package.json content
|
|
67
60
|
*/
|
|
68
61
|
function restorePackageJsonContent(packageJsonContentBeforePluginsInstallation) {
|
|
69
|
-
let packageJsonFilePath =
|
|
62
|
+
let packageJsonFilePath = path.join(getNodeModulesPath(), 'package.json');
|
|
70
63
|
let isPackageJsonRestored = executeSynchronizedCommands(writeFileSync, [packageJsonFilePath, JSON.stringify(packageJsonContentBeforePluginsInstallation, null, 2)], 'Package.json content restored successfully', 'Unable to restore package.json content', false, true);
|
|
71
64
|
return isPackageJsonRestored;
|
|
72
65
|
}
|
package/index.js
CHANGED
|
@@ -6,3 +6,55 @@ module.exports = {
|
|
|
6
6
|
plugins,
|
|
7
7
|
extendPlugins
|
|
8
8
|
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
function config() {
|
|
13
|
+
return {
|
|
14
|
+
addConfig(conf){
|
|
15
|
+
return conf
|
|
16
|
+
},
|
|
17
|
+
addRule(){
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const rule = {
|
|
26
|
+
meta: {
|
|
27
|
+
type: "problem",
|
|
28
|
+
docs: {
|
|
29
|
+
description: "Disallow the use of 'debugger' statements",
|
|
30
|
+
category: "Possible Errors",
|
|
31
|
+
recommended: true,
|
|
32
|
+
},
|
|
33
|
+
schema: [], // No options for this rule
|
|
34
|
+
messages: {
|
|
35
|
+
noDebugger: "Unexpected 'debugger' statement.",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
create(){
|
|
39
|
+
return {
|
|
40
|
+
DebuggerStatement(node) {
|
|
41
|
+
context.report({
|
|
42
|
+
node,
|
|
43
|
+
messageId: "noDebugger",
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const { addConfig, addRule } = config()
|
|
52
|
+
|
|
53
|
+
addRule([{name:"dummyrule",conf:rule}])
|
|
54
|
+
|
|
55
|
+
addConfig([{
|
|
56
|
+
files: ["config/*.js"],
|
|
57
|
+
rules: {
|
|
58
|
+
"no-console": "off",
|
|
59
|
+
},
|
|
60
|
+
}])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/codestandard-validator",
|
|
3
|
-
"version": "1.0.0-exp-
|
|
3
|
+
"version": "1.0.0-exp-4",
|
|
4
4
|
"description": "library to enforce code standard using eslint",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"type": "commonjs",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@zohodesk/codestandard-analytics":"1.0.2-exp-
|
|
18
|
+
"@zohodesk/codestandard-analytics": "1.0.2-exp-3",
|
|
19
19
|
"@zohodesk-private/client_deployment_tool": "0.0.5",
|
|
20
20
|
"eslint": "8.26.0",
|
|
21
|
-
"stylelint":"16.23.0"
|
|
21
|
+
"stylelint": "16.23.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/core": "7.24.7",
|