@zohodesk/codestandard-validator 1.0.0-exp-6 → 1.0.0-exp-8

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.
@@ -16,8 +16,10 @@ const {
16
16
  const {
17
17
  runLintWorkflow
18
18
  } = require("./lint");
19
- process.env.DECRYPT_SONARQUBE = 7;
20
- process.env.DECRYPT_TOKEN = 12;
19
+ process.env.SONARQUBE_EXTERNAL = 7; // sonarqube_external
20
+ process.env.SONARQUBE = 12;
21
+ process.env.ZGIT_TOKEN = 12; // sonarqube & zgit
22
+
21
23
  global.analytics = {
22
24
  status: "SUCCESS",
23
25
  sonarQubeStatus: false,
@@ -26,10 +28,16 @@ global.analytics = {
26
28
  totalIssues: 0
27
29
  };
28
30
  async function preCommitHook() {
29
- Logger.log(Logger.INFO_TYPE, "Executing pre commit hook...");
31
+ Logger.log(Logger.INFO_TYPE, "\n Executing pre commit hook...");
30
32
  Logger.log(Logger.INFO_TYPE, `working dir: ${process.cwd()}`);
31
- if (await handleMergeCommit()) return;
32
- if (!(await ensurePluginsInstalled())) return;
33
+ if (await handleMergeCommit()) {
34
+ return;
35
+ }
36
+ ;
37
+ if (!(await ensurePluginsInstalled())) {
38
+ return;
39
+ }
40
+ ;
33
41
  const stagedFiles = await safeGetStagedFiles();
34
42
  if (stagedFiles.length === 0) {
35
43
  Logger.log(Logger.INFO_TYPE, "No staged files. Commit skipped.");
@@ -4,17 +4,21 @@ const {
4
4
  Logger
5
5
  } = require("../../utils/Logger/Logger");
6
6
  const {
7
- exec
7
+ execSync
8
8
  } = require('child_process');
9
+ const path = require("path");
9
10
  const {
10
- promisify
11
- } = require('util');
12
- const execAsync = promisify(exec);
11
+ getNodeModulesPath
12
+ } = require("../../utils/General/getNodeModulesPath");
13
+ function getAbsolutePath(p1, p2) {
14
+ if (path.isAbsolute(p2)) {
15
+ return path.normalize(p2);
16
+ }
17
+ return path.resolve(p1, p2);
18
+ }
13
19
  async function calculateGitDiffForFile(branch, file) {
14
20
  try {
15
- const {
16
- stdout
17
- } = await execAsync(`git diff -U0 ${branch.trim()} ${file}`);
21
+ const stdout = execSync(`git diff -U0 ${branch.trim()} -- ${getAbsolutePath(getNodeModulesPath(), file)}`).toString();
18
22
  return stdout;
19
23
  } catch (err) {
20
24
  throw err;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  const {
4
- exec
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,8 +34,6 @@ const {
37
34
  const {
38
35
  Logger
39
36
  } = require('../../utils/Logger/Logger');
40
- // const { default: fetchProjectIssuesViaCurl } = require('../../utils/General/SonarQubeUtil');
41
- const execAsync = promisify(exec);
42
37
  async function lintFiles(filePath) {
43
38
  const ext = path.extname(filePath);
44
39
  if (['.js', '.ts', '.tsx', '.jsx', '.properties'].includes(ext)) {
@@ -62,9 +57,9 @@ async function findEslintErrors(file) {
62
57
  Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. Make sure eslint plugin is installed');
63
58
  return [];
64
59
  }
65
- return execAsync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
60
+ return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
66
61
  stderr
67
- }) => stderr ? stderr.trim().split('\n') : []).catch(err => {
62
+ }) => stderr ? stderr.toString().trim().split('\n') : []).catch(err => {
68
63
  Logger.log(Logger.FAILURE_TYPE, err);
69
64
  throw new Error('Error executing eslint command');
70
65
  });
@@ -72,11 +67,11 @@ async function findEslintErrors(file) {
72
67
  function findStyleLintErrors(filePath) {
73
68
  const configFile = path.resolve(getNodeModulesPath(), '.stylelintrc.js');
74
69
  const absolutePath = path.join(getRootDirectory(), filePath);
75
- return execAsync(`npx stylelint ${absolutePath} --config ${configFile}`, {
70
+ return execSync(`npx stylelint ${absolutePath} --config ${configFile}`, {
76
71
  cwd: getNodeModulesPath()
77
72
  }).then(({
78
73
  stdout
79
- }) => stdout ? stdout.trim().split('\n') : []).catch(err => {
74
+ }) => stdout ? stdout.toString().trim().split('\n') : []).catch(err => {
80
75
  Logger.log(Logger.FAILURE_TYPE, err);
81
76
  return [];
82
77
  });
@@ -87,7 +82,10 @@ async function runLintWorkflow(files, branch) {
87
82
  };
88
83
  var branchName = getBranchName();
89
84
  for (const file of files) {
90
- if (!getSupportedLanguage().includes(path.extname(file))) continue;
85
+ if (!getSupportedLanguage().includes(path.extname(file))) {
86
+ continue;
87
+ }
88
+ ;
91
89
  const changeset = extractDiffHunks(await calculateGitDiffForFile(branchName, file));
92
90
  const diff = {
93
91
  old_path: file,
@@ -112,7 +110,7 @@ async function runLintWorkflow(files, branch) {
112
110
  */
113
111
  // const { issues, hasIssue, totalIssues } = fetchProjectIssuesViaCurl("projectName");
114
112
  });
115
- Logger.log(Logger.INFO_TYPE, global.analytics);
113
+ // Logger.log(Logger.INFO_TYPE,global.analytics)
116
114
  return global.analytics.status == 'FAILURE' ? true : false;
117
115
  }
118
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
- exec
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").toString();
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").toString();
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 {
@@ -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
- console.log(process.env);
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');
package/build/lib/cli.js CHANGED
@@ -18,7 +18,13 @@ const {
18
18
  const {
19
19
  getPluginsToInstall
20
20
  } = require("../utils/PluginsInstallation/checkIfPluginsAreInstalled");
21
+ const path = require("path");
21
22
  const [,, action, ...options] = process.argv;
23
+ const config = require(path.resolve(process.cwd(), 'lint.config.js'))(function () {
24
+ process.env.SONARQUBE_EXTERNAL = config.metric_token;
25
+ process.env.SONARQUBE = config.meticHandler_api_token;
26
+ process.env.ZGIT_TOKEN = config.token;
27
+ })();
22
28
  async function run() {
23
29
  switch (action) {
24
30
  case "setup":
@@ -25,8 +25,8 @@ module.exports = {
25
25
  impactBased: true,
26
26
  lintReportPath: path.resolve(process.cwd(), "lint-report", "lintReport.json"),
27
27
  metricServerHost: "https://client-linters.zdesk.csez.zohocorpin.com",
28
- meticHandler_api_token: "KIDfmI46KIDfmI4kYPU1",
29
- metric_token: "zxh_371336m636584i54m662j6495h46228mkj6hihh8",
28
+ meticHandler_api_token: "DBWyfB46DBWyfB4dRIN1",
29
+ metric_token: "sqa_371336f636584b54f662c6495a46228fdc6abaa8",
30
30
  branchDiffPath: path.resolve(process.cwd(), "diffBranch.json"),
31
31
  gitEndPoint: "https://zgit.csez.zohocorpin.com",
32
32
  tsConfigurationPath: path.resolve(process.cwd(), 'tsconfig.json'),
@@ -34,7 +34,7 @@ module.exports = {
34
34
  impactBasedPrecommit: true,
35
35
  shouldWarningsAbortCommit: false,
36
36
  pushMetricsOnPreCommit: true,
37
- token: "w-OkG3f5OOM1Rkly8phZ",
37
+ token: "k-CyU3t5CCA1Fyzm8dvN",
38
38
  compareBranch: 'release',
39
39
  supportedExtensions: ['.js', '.jsx', '.ts', '.tsx', '.properties']
40
40
  };
@@ -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
- exec
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
  *
@@ -82,10 +78,10 @@ async function fetchProjectIssuesViaCurl(componentKey) {
82
78
  _Logger.Logger.log(_Logger.Logger.INFO_TYPE, `\n Fetching issues (curl) for component: ${componentKey}`);
83
79
  const url = buildIssuesSearchUrl(componentKey);
84
80
  try {
85
- const token = 'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), process.env.DECRYPT_TOKEN);
81
+ const token = process.env.SONARQUBE; //'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), ); // sonarqube
86
82
  const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
87
- const output = await execAsync(command).toString();
88
- const json = JSON.parse(output);
83
+ const output = execSync(command).toString();
84
+ const json = JSON.parse(output.toString());
89
85
  const {
90
86
  issues,
91
87
  hasIssue,
@@ -14,6 +14,9 @@ const {
14
14
  const {
15
15
  executeSynchronizedCommands
16
16
  } = require("../General/executeSyncCommands");
17
+ const {
18
+ getNodeModulesPath
19
+ } = require("../General/getNodeModulesPath");
17
20
 
18
21
  /**
19
22
  * @function configurePrecommitHook - creates the link to custom pre commit hook file and husky precommit file
@@ -26,7 +29,7 @@ function configurePrecommitHook() {
26
29
  let huskyPrecommitHookContent = `#!/bin/sh
27
30
  . "$(dirname "$0")/_/husky.sh"
28
31
 
29
- "${customPrecomitHookPath}"
32
+ cd "${getNodeModulesPath()}" && "${customPrecomitHookPath}"
30
33
  `;
31
34
  let isCustomPrecommitConfigurationSuccessful = executeSynchronizedCommands(writeFileSync, [huskyPrecommitPath, huskyPrecommitHookContent, 'utf-8'], '', 'Could not create and write pre-commit.sh inisde husky directory', false, true);
32
35
  if (isCustomPrecommitConfigurationSuccessful) {
@@ -12,12 +12,8 @@ const {
12
12
  Logger
13
13
  } = require('../Logger/Logger');
14
14
  const {
15
- exec
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
- await execAsync('npx husky@7 install');
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
- exec
17
+ spawnSync
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
@@ -29,28 +25,44 @@ async function installPlugins(pluginsToBeInstalled) {
29
25
  if (pluginsToBeInstalled.length > 0) {
30
26
  let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
31
27
  Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
32
- const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')} --legacy-peer-deps`;
33
- Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
34
- try {
35
- let {
36
- stdout,
37
- stderr
38
- } = await execAsync(installCommand, {
39
- cwd: getNodeModulesPath(),
40
- shell: true
41
- });
42
- if (stdout) {
43
- Logger.logger(stdout);
44
- } else if (stderr) {
45
- Logger.logger(stderr);
46
- }
47
- Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
48
- return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
49
- } catch (error) {
50
- Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins. Kindly retry the command");
51
- Logger.log(Logger.FAILURE_TYPE, error);
28
+ const args = ['install', '--save-dev', ...pluginsToBeInstalled, '--legacy-peer-deps'];
29
+ Logger.log(Logger.INFO_TYPE, `Install command being executed: npm ${args.join(' ')}`);
30
+ const result = spawnSync('npm', args, {
31
+ cwd: getNodeModulesPath(),
32
+ shell: false,
33
+ encoding: 'utf8'
34
+ });
35
+ if (result.stdout) {
36
+ Logger.logger(result.stdout);
37
+ }
38
+ if (result.stderr) {
39
+ Logger.log(Logger.INFO_TYPE, result.stderr);
40
+ }
41
+ if (result.error) {
42
+ Logger.log(Logger.FAILURE_TYPE, 'Unable to install plugins. Spawn error.');
43
+ Logger.log(Logger.FAILURE_TYPE, result.error);
44
+ return false;
45
+ }
46
+ if (result.status !== 0) {
47
+ Logger.log(Logger.FAILURE_TYPE, `npm exited with code ${result.status}`);
52
48
  return false;
53
49
  }
50
+ Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
51
+ 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
+ // }
54
66
  } else {
55
67
  Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
56
68
  return true;
package/hash.js ADDED
@@ -0,0 +1,30 @@
1
+ const caesarCipher = (str, shift) => {
2
+ return str
3
+ .split("")
4
+ .map((char) => {
5
+ let code = char.charCodeAt();
6
+ if (code >= 65 && code <= 90) {
7
+ return String.fromCharCode(((code - 65 + shift) % 26) + 65);
8
+ } else if (code >= 97 && code <= 122) {
9
+ return String.fromCharCode(((code - 97 + shift) % 26) + 97);
10
+ }
11
+ return char;
12
+ })
13
+ .join("");
14
+ };
15
+
16
+ const encrypt = (plaintext, shift) => caesarCipher(plaintext, shift);
17
+
18
+ const decrypt = (ciphertext, shift) => caesarCipher(ciphertext, 26 - shift);
19
+
20
+
21
+ const encode = (data) => btoa(data)
22
+
23
+
24
+ const decode = (encode_data) => atob(encode_data)
25
+
26
+ export { encrypt, decrypt,encode ,decode };
27
+
28
+ console.log(decrypt("KIDfmI46KIDfmI4kYPU1",7))
29
+ console.log(decrypt("zxh_371336m636584i54m662j6495h46228mkj6hihh8",7))
30
+ console.log(decrypt("w-OkG3f5OOM1Rkly8phZ",12))
package/index.js CHANGED
@@ -25,7 +25,7 @@ function config() {
25
25
  const rule = {
26
26
  meta: {
27
27
  type: "problem",
28
- docs: {
28
+ docs:{
29
29
  description: "Disallow the use of 'debugger' statements",
30
30
  category: "Possible Errors",
31
31
  recommended: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.0.0-exp-6",
3
+ "version": "1.0.0-exp-8",
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-6",
18
+ "@zohodesk/codestandard-analytics": "1.0.2-exp-12",
19
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
20
20
  "eslint": "8.26.0",
21
21
  "stylelint": "16.23.0"