@zohodesk/codestandard-validator 0.0.2-exp-10 → 0.0.2-exp-12
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.
|
@@ -28,6 +28,9 @@ const {
|
|
|
28
28
|
getConfigurationPrecommit,
|
|
29
29
|
getSupportedLanguage
|
|
30
30
|
} = require('../../utils/General/getGeneralInfo');
|
|
31
|
+
const {
|
|
32
|
+
getRootDirectory
|
|
33
|
+
} = require('../../utils/General/RootDirectoryUtils/getRootDirectory');
|
|
31
34
|
const {
|
|
32
35
|
impactBasedPrecommit,
|
|
33
36
|
shouldWarningsAbortCommit
|
|
@@ -62,7 +65,7 @@ async function getStagedFiles() {
|
|
|
62
65
|
if (error) {
|
|
63
66
|
if (error != null) reject("Couldn't fetch staged files");
|
|
64
67
|
} else if (stderr) {
|
|
65
|
-
resolve(stderr.trim().split('\n'));
|
|
68
|
+
resolve(filterDeltedFileFromStagedFiles(stderr.trim().split('\n')));
|
|
66
69
|
} else if (stdout.trim() === '') {
|
|
67
70
|
resolve(stdout.trim());
|
|
68
71
|
}
|
|
@@ -70,6 +73,21 @@ async function getStagedFiles() {
|
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @function {filterDeltedFileFromStagedFiles} - filter deleted staged files
|
|
78
|
+
* @param {Array<string>} files - staged files
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
function filterDeltedFileFromStagedFiles(files) {
|
|
82
|
+
return files.filter(file => {
|
|
83
|
+
const absolutePath = path.resolve(getRootDirectory(), file);
|
|
84
|
+
if (fs.existsSync(absolutePath)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
73
91
|
/**
|
|
74
92
|
* @function findEslintErrors - method Lint given file based on given configuration
|
|
75
93
|
* @param {*} file - path of file to lint
|
|
@@ -275,17 +293,9 @@ async function preCommitHook() {
|
|
|
275
293
|
Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
|
|
276
294
|
}
|
|
277
295
|
if (shouldAbortCommit) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
} else if (hasEslintErrorsInFiles && areFilesStaged) {
|
|
282
|
-
Logger.log(Logger.FAILURE_TYPE, `There are eslint errors present. So commit is aborted`);
|
|
283
|
-
process.exit(1);
|
|
284
|
-
} else if (!hasEslintErrorsInFiles && !hasEslintErrorsInChangedLines && areFilesStaged) {
|
|
285
|
-
Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
|
|
286
|
-
process.exit(0);
|
|
287
|
-
}
|
|
288
|
-
} else if (!shouldAbortCommit && areFilesStaged) {
|
|
296
|
+
Logger.log(Logger.FAILURE_TYPE, `There are eslint errors present. So commit is aborted. If possible try to fix the eslint warnings also.`);
|
|
297
|
+
process.exit(1);
|
|
298
|
+
} else {
|
|
289
299
|
Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
|
|
290
300
|
process.exit(0);
|
|
291
301
|
}
|
|
@@ -14,6 +14,7 @@ const path = require("path");
|
|
|
14
14
|
* @property {string} tsConfigurationPath - The path of the ts configuration Path
|
|
15
15
|
* @property {number} projectId - project id of repository
|
|
16
16
|
* @property {boolean} impactBasedPrecommit - Indicates if the linting is impact-based in pre commit
|
|
17
|
+
* @property {boolean} shouldWarningsAbortCommit - Indicates if eslint warnings should abort the commit
|
|
17
18
|
* @property {string} token - Encrypted Authentication Token
|
|
18
19
|
* @property {string} compareBranch - Branch to compare diff
|
|
19
20
|
*/
|
|
@@ -16,13 +16,16 @@ const {
|
|
|
16
16
|
const {
|
|
17
17
|
executeSynchronizedCommands
|
|
18
18
|
} = require('../General/executeSyncCommands');
|
|
19
|
-
|
|
19
|
+
var {
|
|
20
20
|
type,
|
|
21
21
|
endPoint,
|
|
22
22
|
branch,
|
|
23
23
|
cacheDirectory,
|
|
24
24
|
commonLinterRepoName
|
|
25
25
|
} = require('../../../jsonUtils/commonLinterRepoDetails');
|
|
26
|
+
const {
|
|
27
|
+
cliArgsToObject
|
|
28
|
+
} = require("../General/getGeneralInfo");
|
|
26
29
|
/**
|
|
27
30
|
* @function cloneViaCdt - Using the "clint development tool" clones the common linter_configuration repo into precommit library
|
|
28
31
|
* @returns {boolean} - indicating the success or failure of the cloning process
|
|
@@ -30,7 +33,14 @@ const {
|
|
|
30
33
|
|
|
31
34
|
function cloneViaCdt() {
|
|
32
35
|
removeFolder(getDeleteDirPath());
|
|
33
|
-
const
|
|
36
|
+
const cliArgs = cliArgsToObject(process.argv);
|
|
37
|
+
const userName = cliArgs.lintUsername || undefined;
|
|
38
|
+
const token = cliArgs.lintToken || undefined;
|
|
39
|
+
var absoluteEndPoint = `https://${endPoint}`;
|
|
40
|
+
if (userName && token) {
|
|
41
|
+
absoluteEndPoint = `https://${userName}:${token}@${endPoint}`;
|
|
42
|
+
}
|
|
43
|
+
var commandToCloneCommonConfigRepo = `npx cdt clone --clone:type=${type} --clone:url=${absoluteEndPoint} --clone:branch=${branch} --clone:cacheDir=${cacheDirectory} --clone:proj:name=${commonLinterRepoName}`;
|
|
34
44
|
let isCommonConfigurationClonedSuccessfully = executeSynchronizedCommands(execSync, [commandToCloneCommonConfigRepo, {
|
|
35
45
|
cwd: getClonedDirPath()
|
|
36
46
|
}], `Lint Configuration Cloned Successfully - ${getRepoName() || 'common'}`, 'Could not clone the linters common repo', false, true);
|
|
@@ -58,9 +58,33 @@ function getSupportedLanguage() {
|
|
|
58
58
|
_language.push('.tsx');
|
|
59
59
|
return _language;
|
|
60
60
|
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @function cliArgsToObject - convert cli argument to object
|
|
64
|
+
* @param {Array<string>} cliArgs - cli argument from enduser
|
|
65
|
+
* @param {any} isKeyNeedToBeAdded - option
|
|
66
|
+
* @returns {Object}
|
|
67
|
+
*/
|
|
68
|
+
function cliArgsToObject(cliArgs, isKeyNeedToBeAdded = null) {
|
|
69
|
+
const processEnv = {};
|
|
70
|
+
cliArgs.forEach(option => {
|
|
71
|
+
if (/^--./.test(option)) {
|
|
72
|
+
const equIndex = option.indexOf('=');
|
|
73
|
+
let key = option.slice(2, equIndex);
|
|
74
|
+
let value = option.slice(equIndex + 1);
|
|
75
|
+
if (equIndex === -1) {
|
|
76
|
+
key = option.slice(2);
|
|
77
|
+
value = true;
|
|
78
|
+
}
|
|
79
|
+
processEnv[key] = value;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return processEnv;
|
|
83
|
+
}
|
|
61
84
|
module.exports = {
|
|
62
85
|
getSupportedLanguage,
|
|
63
86
|
getTimeStampInfo,
|
|
64
87
|
getEnv,
|
|
65
|
-
getConfigurationPrecommit
|
|
88
|
+
getConfigurationPrecommit,
|
|
89
|
+
cliArgsToObject
|
|
66
90
|
};
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
12
|
-
endPoint: "
|
|
12
|
+
endPoint: "zgit.csez.zohocorpin.com/code_standard/client_linter/linter_configuration.git",
|
|
13
13
|
branch: "master",
|
|
14
14
|
cacheDirectory: "./",
|
|
15
15
|
commonLinterRepoName: "configuration",
|
|
16
|
-
type: "git"
|
|
16
|
+
type: "git",
|
|
17
17
|
};
|