@zohodesk/codestandard-validator 1.0.0-exp-9 → 1.0.0-exp-11
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/pre-commit-default.js +9 -5
- package/build/lib/postinstall.js +8 -1
- package/build/utils/General/SonarQubeUtil.js +2 -2
- package/build/utils/PluginsInstallation/installPlugins.js +3 -16
- package/index.js +3 -53
- package/jsonUtils/MandatoryListRules.js +3 -0
- package/package.json +2 -2
|
@@ -30,6 +30,7 @@ const {
|
|
|
30
30
|
const {
|
|
31
31
|
getRootDirectory
|
|
32
32
|
} = require('../../utils/General/RootDirectoryUtils/getRootDirectory');
|
|
33
|
+
const MandatoryListRules = require('../../../jsonUtils/MandatoryListRules');
|
|
33
34
|
const {
|
|
34
35
|
impactBasedPrecommit,
|
|
35
36
|
shouldWarningsAbortCommit
|
|
@@ -259,7 +260,7 @@ async function preCommitHook_default() {
|
|
|
259
260
|
for (let file in stagedFiles) {
|
|
260
261
|
let currentFileName = stagedFiles[file];
|
|
261
262
|
let changedLinesArray = [];
|
|
262
|
-
let eslintErrorsInChangedLines =
|
|
263
|
+
let eslintErrorsInChangedLines = new Set();
|
|
263
264
|
let isOnlyEslintWarningsPresentInFile = false;
|
|
264
265
|
if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
|
|
265
266
|
try {
|
|
@@ -290,16 +291,19 @@ async function preCommitHook_default() {
|
|
|
290
291
|
//errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
|
|
291
292
|
|
|
292
293
|
let eslintErrorLineNumber = errorsInFile[error].trim().split(' ')[0].split(':')[0];
|
|
294
|
+
if (MandatoryListRules.some(ruleId => errorsInFile[error].trim().includes(ruleId))) {
|
|
295
|
+
eslintErrorsInChangedLines.add(errorsInFile[error]);
|
|
296
|
+
}
|
|
293
297
|
for (let lineNumber in changedLinesStartArray) {
|
|
294
298
|
if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
|
|
295
|
-
eslintErrorsInChangedLines.
|
|
299
|
+
eslintErrorsInChangedLines.add(errorsInFile[error]);
|
|
296
300
|
}
|
|
297
301
|
}
|
|
298
302
|
}
|
|
299
|
-
if (eslintErrorsInChangedLines.
|
|
300
|
-
isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(eslintErrorsInChangedLines);
|
|
303
|
+
if (eslintErrorsInChangedLines.size > 0) {
|
|
304
|
+
isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
|
|
301
305
|
Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
|
|
302
|
-
for (let eslintError of eslintErrorsInChangedLines) {
|
|
306
|
+
for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
|
|
303
307
|
Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
|
|
304
308
|
}
|
|
305
309
|
if (shouldWarningsAbortCommit) {
|
package/build/lib/postinstall.js
CHANGED
|
@@ -24,6 +24,13 @@ const {
|
|
|
24
24
|
const {
|
|
25
25
|
writeFsPaths
|
|
26
26
|
} = require("../utils/General/writeProjectDetailsToJson");
|
|
27
|
+
const {
|
|
28
|
+
getNodeModulesPath
|
|
29
|
+
} = require("../utils/General/getNodeModulesPath");
|
|
30
|
+
const config = require(path.join(getNodeModulesPath(), 'lint.config.js'));
|
|
31
|
+
process.env.SONARQUBE_EXTERNAL = config.metric_token;
|
|
32
|
+
process.env.SONARQUBE = config.meticHandler_api_token;
|
|
33
|
+
process.env.ZGIT_TOKEN = config.token;
|
|
27
34
|
|
|
28
35
|
/**
|
|
29
36
|
* @function {postInstall} - This methods setup husky and configuration for executing project
|
|
@@ -36,7 +43,7 @@ async function postInstall() {
|
|
|
36
43
|
await executeMethodsThatReturnBooleanValue("Make sure zgit.csez.zohocorpin.com is accessible", cloneViaCdt, null);
|
|
37
44
|
await executeMethodsThatReturnBooleanValue("Some issue occurred in creating eslint config file.", createConfigFile, null);
|
|
38
45
|
Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup successfull");
|
|
39
|
-
arePluginsInstalled();
|
|
46
|
+
// arePluginsInstalled();
|
|
40
47
|
} catch (error) {
|
|
41
48
|
Logger.log(Logger.FAILURE_TYPE, `Kindly retry npm install. & ${error.message}`);
|
|
42
49
|
}
|
|
@@ -18,9 +18,9 @@ const {
|
|
|
18
18
|
|
|
19
19
|
function buildIssuesSearchUrl(componentKey) {
|
|
20
20
|
const {
|
|
21
|
-
metricServerHost
|
|
21
|
+
metricServerHost = "https://client-linters.zdesk.csez.zohocorpin.com"
|
|
22
22
|
} = (0, _getGeneralInfo.getConfigurationPrecommit)();
|
|
23
|
-
const base = `${
|
|
23
|
+
const base = `${metricServerHost}/api/issues/search`;
|
|
24
24
|
const params = new URLSearchParams({
|
|
25
25
|
componentKeys: componentKey,
|
|
26
26
|
s: 'FILE_LINE',
|
|
@@ -14,7 +14,8 @@ const {
|
|
|
14
14
|
} = require('../General/getNodeModulesPath');
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const {
|
|
17
|
-
spawnSync
|
|
17
|
+
spawnSync,
|
|
18
|
+
spawn
|
|
18
19
|
} = require('child_process');
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -24,7 +25,7 @@ const {
|
|
|
24
25
|
async function installPlugins(pluginsToBeInstalled) {
|
|
25
26
|
if (pluginsToBeInstalled.length > 0) {
|
|
26
27
|
let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
|
|
27
|
-
Logger.log(Logger.
|
|
28
|
+
Logger.log(Logger.SUCCESS_TYPE, 'Installing rule plugins; this may take some time.');
|
|
28
29
|
const args = ['install', '--save-dev', ...pluginsToBeInstalled, '--legacy-peer-deps'];
|
|
29
30
|
Logger.log(Logger.INFO_TYPE, `Install command being executed: npm ${args.join(' ')}`);
|
|
30
31
|
const result = spawnSync('npm', args, {
|
|
@@ -49,20 +50,6 @@ async function installPlugins(pluginsToBeInstalled) {
|
|
|
49
50
|
}
|
|
50
51
|
Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
|
|
51
52
|
return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
|
|
52
|
-
// const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')} --legacy-peer-deps`
|
|
53
|
-
// Logger.log(Logger.INFO_TYPE,`Install command being executed: ${installCommand}`)
|
|
54
|
-
// try{
|
|
55
|
-
// let stdout = execSync(installCommand,{cwd:getNodeModulesPath(),shell:true}).toString()
|
|
56
|
-
// if(stdout){
|
|
57
|
-
// Logger.logger(stdout)
|
|
58
|
-
// }
|
|
59
|
-
// Logger.log(Logger.SUCCESS_TYPE,'Plugins installation successful')
|
|
60
|
-
// return restorePackageJsonContent(packageJsonBeforePluginsInstallation)
|
|
61
|
-
// } catch(error) {
|
|
62
|
-
// Logger.log(Logger.FAILURE_TYPE,"Unable to install plugins. Kindly retry the command")
|
|
63
|
-
// Logger.log(Logger.FAILURE_TYPE,error)
|
|
64
|
-
// return false
|
|
65
|
-
// }
|
|
66
53
|
} else {
|
|
67
54
|
Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
|
|
68
55
|
return true;
|
package/index.js
CHANGED
|
@@ -1,60 +1,10 @@
|
|
|
1
1
|
const { getLintConfigurationUtil } = require("./build/utils/ConfigFileUtils/getLintConfiguration");
|
|
2
2
|
const { rulesConfig, plugins, extendPlugins } = getLintConfigurationUtil();
|
|
3
3
|
|
|
4
|
+
|
|
5
|
+
|
|
4
6
|
module.exports = {
|
|
5
7
|
rulesConfig,
|
|
6
8
|
plugins,
|
|
7
9
|
extendPlugins
|
|
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
|
-
}])
|
|
10
|
+
};
|
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-11",
|
|
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-14",
|
|
19
19
|
"@zohodesk-private/client_deployment_tool": "0.0.5",
|
|
20
20
|
"eslint": "8.26.0",
|
|
21
21
|
"stylelint": "16.23.0"
|