@zohodesk/codestandard-validator 1.0.0-exp-5 → 1.0.0-exp-7
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 +9 -3
- package/build/hooks/Precommit/errorhelpers.js +2 -8
- package/build/hooks/Precommit/lint.js +8 -12
- package/build/hooks/Precommit/pre-commit-default.js +1 -1
- package/build/hooks/Precommit/utils.js +3 -13
- package/build/hooks/hook.js +1 -2
- package/build/utils/General/SonarQubeUtil.js +3 -8
- package/build/utils/HuskySetup/initializeHusky.js +2 -6
- package/build/utils/Logger/Logger.js +3 -0
- package/build/utils/PluginsInstallation/installPlugins.js +11 -11
- package/package.json +2 -2
|
@@ -26,10 +26,16 @@ global.analytics = {
|
|
|
26
26
|
totalIssues: 0
|
|
27
27
|
};
|
|
28
28
|
async function preCommitHook() {
|
|
29
|
-
Logger.log(Logger.INFO_TYPE, "Executing pre commit hook...");
|
|
29
|
+
Logger.log(Logger.INFO_TYPE, "\n Executing pre commit hook...");
|
|
30
30
|
Logger.log(Logger.INFO_TYPE, `working dir: ${process.cwd()}`);
|
|
31
|
-
if (await handleMergeCommit())
|
|
32
|
-
|
|
31
|
+
if (await handleMergeCommit()) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
if (!(await ensurePluginsInstalled())) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
;
|
|
33
39
|
const stagedFiles = await safeGetStagedFiles();
|
|
34
40
|
if (stagedFiles.length === 0) {
|
|
35
41
|
Logger.log(Logger.INFO_TYPE, "No staged files. Commit skipped.");
|
|
@@ -4,17 +4,11 @@ const {
|
|
|
4
4
|
Logger
|
|
5
5
|
} = require("../../utils/Logger/Logger");
|
|
6
6
|
const {
|
|
7
|
-
|
|
7
|
+
execSync
|
|
8
8
|
} = require('child_process');
|
|
9
|
-
const {
|
|
10
|
-
promisify
|
|
11
|
-
} = require('util');
|
|
12
|
-
const execAsync = promisify(exec);
|
|
13
9
|
async function calculateGitDiffForFile(branch, file) {
|
|
14
10
|
try {
|
|
15
|
-
const {
|
|
16
|
-
stdout
|
|
17
|
-
} = await execAsync(`git diff -U0 ${branch.trim()} ${file}`);
|
|
11
|
+
const stdout = execSync(`git diff -U0 ${branch.trim()} ${file}`);
|
|
18
12
|
return stdout;
|
|
19
13
|
} catch (err) {
|
|
20
14
|
throw err;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
execSync
|
|
5
5
|
} = require('child_process');
|
|
6
|
-
const {
|
|
7
|
-
promisify
|
|
8
|
-
} = require('util');
|
|
9
6
|
const fs = require('fs');
|
|
10
7
|
const path = require('path');
|
|
11
8
|
const {
|
|
@@ -37,10 +34,6 @@ const {
|
|
|
37
34
|
const {
|
|
38
35
|
Logger
|
|
39
36
|
} = require('../../utils/Logger/Logger');
|
|
40
|
-
const {
|
|
41
|
-
default: fetchProjectIssuesViaCurl
|
|
42
|
-
} = require('../../utils/General/SonarQubeUtil');
|
|
43
|
-
const execAsync = promisify(exec);
|
|
44
37
|
async function lintFiles(filePath) {
|
|
45
38
|
const ext = path.extname(filePath);
|
|
46
39
|
if (['.js', '.ts', '.tsx', '.jsx', '.properties'].includes(ext)) {
|
|
@@ -64,7 +57,7 @@ async function findEslintErrors(file) {
|
|
|
64
57
|
Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. Make sure eslint plugin is installed');
|
|
65
58
|
return [];
|
|
66
59
|
}
|
|
67
|
-
return
|
|
60
|
+
return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
|
|
68
61
|
stderr
|
|
69
62
|
}) => stderr ? stderr.trim().split('\n') : []).catch(err => {
|
|
70
63
|
Logger.log(Logger.FAILURE_TYPE, err);
|
|
@@ -74,7 +67,7 @@ async function findEslintErrors(file) {
|
|
|
74
67
|
function findStyleLintErrors(filePath) {
|
|
75
68
|
const configFile = path.resolve(getNodeModulesPath(), '.stylelintrc.js');
|
|
76
69
|
const absolutePath = path.join(getRootDirectory(), filePath);
|
|
77
|
-
return
|
|
70
|
+
return execSync(`npx stylelint ${absolutePath} --config ${configFile}`, {
|
|
78
71
|
cwd: getNodeModulesPath()
|
|
79
72
|
}).then(({
|
|
80
73
|
stdout
|
|
@@ -89,7 +82,10 @@ async function runLintWorkflow(files, branch) {
|
|
|
89
82
|
};
|
|
90
83
|
var branchName = getBranchName();
|
|
91
84
|
for (const file of files) {
|
|
92
|
-
if (!getSupportedLanguage().includes(path.extname(file)))
|
|
85
|
+
if (!getSupportedLanguage().includes(path.extname(file))) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
;
|
|
93
89
|
const changeset = extractDiffHunks(await calculateGitDiffForFile(branchName, file));
|
|
94
90
|
const diff = {
|
|
95
91
|
old_path: file,
|
|
@@ -114,7 +110,7 @@ async function runLintWorkflow(files, branch) {
|
|
|
114
110
|
*/
|
|
115
111
|
// const { issues, hasIssue, totalIssues } = fetchProjectIssuesViaCurl("projectName");
|
|
116
112
|
});
|
|
117
|
-
Logger.log(Logger.INFO_TYPE,
|
|
113
|
+
// Logger.log(Logger.INFO_TYPE,global.analytics)
|
|
118
114
|
return global.analytics.status == 'FAILURE' ? true : false;
|
|
119
115
|
}
|
|
120
116
|
module.exports = {
|
|
@@ -222,7 +222,7 @@ function isOnlyWarningsPresentInFile(eslintErrorsPresent) {
|
|
|
222
222
|
*/
|
|
223
223
|
|
|
224
224
|
async function preCommitHook_default() {
|
|
225
|
-
Logger.log(Logger.INFO_TYPE, 'Executing pre commit hook...');
|
|
225
|
+
Logger.log(Logger.INFO_TYPE, '\n Executing pre commit hook...');
|
|
226
226
|
Logger.log(Logger.INFO_TYPE, `working dir : ${process.cwd()}`);
|
|
227
227
|
try {
|
|
228
228
|
let isMerge = await isMergeCommit();
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
execSync
|
|
5
5
|
} = require("child_process");
|
|
6
|
-
const {
|
|
7
|
-
promisify
|
|
8
|
-
} = require("util");
|
|
9
|
-
const fs = require("fs");
|
|
10
|
-
const path = require("path");
|
|
11
6
|
const {
|
|
12
7
|
getRootDirectory
|
|
13
8
|
} = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
|
|
14
9
|
const {
|
|
15
10
|
checkIfPluginsAreInstalled
|
|
16
11
|
} = require("../../utils/PluginsInstallation/checkIfPluginsAreInstalled");
|
|
17
|
-
const execAsync = promisify(exec);
|
|
18
12
|
async function isMergeCommit() {
|
|
19
13
|
try {
|
|
20
|
-
const
|
|
21
|
-
stdout
|
|
22
|
-
} = await execAsync("git rev-parse -q --verify MERGE_HEAD");
|
|
14
|
+
const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD");
|
|
23
15
|
return Boolean(stdout.trim());
|
|
24
16
|
} catch {
|
|
25
17
|
return false;
|
|
@@ -27,9 +19,7 @@ async function isMergeCommit() {
|
|
|
27
19
|
}
|
|
28
20
|
async function getStagedFiles() {
|
|
29
21
|
try {
|
|
30
|
-
const
|
|
31
|
-
stdout
|
|
32
|
-
} = await execAsync("git diff --staged --name-only");
|
|
22
|
+
const stdout = await execSync("git diff --staged --name-only");
|
|
33
23
|
const files = stdout.trim().split("\n").filter(Boolean);
|
|
34
24
|
return files.filter(file => fs.existsSync(path.resolve(getRootDirectory(), file)));
|
|
35
25
|
} catch {
|
package/build/hooks/hook.js
CHANGED
|
@@ -35,8 +35,7 @@ async function hooks() {
|
|
|
35
35
|
} = getPluginsToInstall();
|
|
36
36
|
await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
if (process.env.defaultprecommit) {
|
|
38
|
+
if (process.env.CLIPRECOMMIT && Boolean(process.env.CLIPRECOMMIT) == true) {
|
|
40
39
|
require('./Precommit/pre-commit-default');
|
|
41
40
|
} else {
|
|
42
41
|
require('./Precommit/commit');
|
|
@@ -7,12 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
var _Logger = require("../Logger/Logger");
|
|
8
8
|
var _getGeneralInfo = require("./getGeneralInfo");
|
|
9
9
|
const {
|
|
10
|
-
|
|
10
|
+
execSync
|
|
11
11
|
} = require('child_process');
|
|
12
|
-
const {
|
|
13
|
-
promisify
|
|
14
|
-
} = require('util');
|
|
15
|
-
const execAsync = promisify(exec);
|
|
16
12
|
/**
|
|
17
13
|
* Constructs a URL for searching issues in SonarQube.
|
|
18
14
|
*
|
|
@@ -84,9 +80,8 @@ async function fetchProjectIssuesViaCurl(componentKey) {
|
|
|
84
80
|
try {
|
|
85
81
|
const token = 'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), process.env.DECRYPT_TOKEN);
|
|
86
82
|
const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const json = JSON.parse(output);
|
|
83
|
+
const output = execSync(command).toString();
|
|
84
|
+
const json = JSON.parse(output.toString());
|
|
90
85
|
const {
|
|
91
86
|
issues,
|
|
92
87
|
hasIssue,
|
|
@@ -12,12 +12,8 @@ const {
|
|
|
12
12
|
Logger
|
|
13
13
|
} = require('../Logger/Logger');
|
|
14
14
|
const {
|
|
15
|
-
|
|
15
|
+
execSync
|
|
16
16
|
} = require('child_process');
|
|
17
|
-
const {
|
|
18
|
-
promisify
|
|
19
|
-
} = require('util');
|
|
20
|
-
const execAsync = promisify(exec);
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
19
|
* @function initializeHusky - creates a .husky folder at the root of the project with the husky execution script file
|
|
@@ -27,7 +23,7 @@ async function initializeHusky() {
|
|
|
27
23
|
let isNavigationToRootDirectorySuccessful = navigateToRootDirectory(getRootDirectory());
|
|
28
24
|
if (isNavigationToRootDirectorySuccessful) {
|
|
29
25
|
try {
|
|
30
|
-
|
|
26
|
+
execSync('npx husky@7 install');
|
|
31
27
|
return true;
|
|
32
28
|
} catch (error) {
|
|
33
29
|
Logger.log(Logger.FAILURE_TYPE, error.toString());
|
|
@@ -14,12 +14,8 @@ const {
|
|
|
14
14
|
} = require('../General/getNodeModulesPath');
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const {
|
|
17
|
-
|
|
17
|
+
execSync
|
|
18
18
|
} = require('child_process');
|
|
19
|
-
const {
|
|
20
|
-
promisify
|
|
21
|
-
} = require('util');
|
|
22
|
-
const execAsync = promisify(exec);
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* @function installPlugins - installs uninstalled plugins for the project
|
|
@@ -31,15 +27,19 @@ async function installPlugins(pluginsToBeInstalled) {
|
|
|
31
27
|
Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
|
|
32
28
|
const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')} --legacy-peer-deps`;
|
|
33
29
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
try {
|
|
31
|
+
let stdout = await execSync(installCommand, {
|
|
32
|
+
cwd: getNodeModulesPath(),
|
|
33
|
+
shell: true
|
|
34
|
+
});
|
|
35
|
+
if (stdout) {
|
|
36
|
+
Logger.logger(stdout);
|
|
37
|
+
}
|
|
39
38
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
40
39
|
return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|
|
41
|
-
}
|
|
40
|
+
} catch (error) {
|
|
42
41
|
Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins. Kindly retry the command");
|
|
42
|
+
Logger.log(Logger.FAILURE_TYPE, error);
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
45
|
} else {
|
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-7",
|
|
4
4
|
"description": "library to enforce code standard using eslint",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
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-6",
|
|
19
19
|
"@zohodesk-private/client_deployment_tool": "0.0.5",
|
|
20
20
|
"eslint": "8.26.0",
|
|
21
21
|
"stylelint": "16.23.0"
|