@zohodesk/codestandard-validator 1.0.0-exp-7 → 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,
@@ -6,9 +6,19 @@ const {
6
6
  const {
7
7
  execSync
8
8
  } = require('child_process');
9
+ const path = require("path");
10
+ const {
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
+ }
9
19
  async function calculateGitDiffForFile(branch, file) {
10
20
  try {
11
- const stdout = execSync(`git diff -U0 ${branch.trim()} ${file}`);
21
+ const stdout = execSync(`git diff -U0 ${branch.trim()} -- ${getAbsolutePath(getNodeModulesPath(), file)}`).toString();
12
22
  return stdout;
13
23
  } catch (err) {
14
24
  throw err;
@@ -59,7 +59,7 @@ async function findEslintErrors(file) {
59
59
  }
60
60
  return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
61
61
  stderr
62
- }) => stderr ? stderr.trim().split('\n') : []).catch(err => {
62
+ }) => stderr ? stderr.toString().trim().split('\n') : []).catch(err => {
63
63
  Logger.log(Logger.FAILURE_TYPE, err);
64
64
  throw new Error('Error executing eslint command');
65
65
  });
@@ -71,7 +71,7 @@ function findStyleLintErrors(filePath) {
71
71
  cwd: getNodeModulesPath()
72
72
  }).then(({
73
73
  stdout
74
- }) => stdout ? stdout.trim().split('\n') : []).catch(err => {
74
+ }) => stdout ? stdout.toString().trim().split('\n') : []).catch(err => {
75
75
  Logger.log(Logger.FAILURE_TYPE, err);
76
76
  return [];
77
77
  });
@@ -11,7 +11,7 @@ const {
11
11
  } = require("../../utils/PluginsInstallation/checkIfPluginsAreInstalled");
12
12
  async function isMergeCommit() {
13
13
  try {
14
- const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD");
14
+ const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD").toString();
15
15
  return Boolean(stdout.trim());
16
16
  } catch {
17
17
  return false;
@@ -19,7 +19,7 @@ async function isMergeCommit() {
19
19
  }
20
20
  async function getStagedFiles() {
21
21
  try {
22
- const stdout = await execSync("git diff --staged --name-only");
22
+ const stdout = await execSync("git diff --staged --name-only").toString();
23
23
  const files = stdout.trim().split("\n").filter(Boolean);
24
24
  return files.filter(file => fs.existsSync(path.resolve(getRootDirectory(), file)));
25
25
  } catch {
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
  };
@@ -78,7 +78,7 @@ async function fetchProjectIssuesViaCurl(componentKey) {
78
78
  _Logger.Logger.log(_Logger.Logger.INFO_TYPE, `\n Fetching issues (curl) for component: ${componentKey}`);
79
79
  const url = buildIssuesSearchUrl(componentKey);
80
80
  try {
81
- const token = 'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), process.env.DECRYPT_TOKEN);
81
+ const token = process.env.SONARQUBE; //'sqa_1f6675c05f63c4784dc741ce751efa0066d2693c' || decrypt(getAPIToken(), ); // sonarqube
82
82
  const command = `curl --tlsv1.2 -s -u "${token}:" "${url}"`;
83
83
  const output = execSync(command).toString();
84
84
  const json = JSON.parse(output.toString());
@@ -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) {
@@ -14,7 +14,7 @@ const {
14
14
  } = require('../General/getNodeModulesPath');
15
15
  const path = require('path');
16
16
  const {
17
- execSync
17
+ spawnSync
18
18
  } = require('child_process');
19
19
 
20
20
  /**
@@ -25,23 +25,44 @@ async function installPlugins(pluginsToBeInstalled) {
25
25
  if (pluginsToBeInstalled.length > 0) {
26
26
  let packageJsonBeforePluginsInstallation = getPackageJsonContentBeforeInstallingPlugins();
27
27
  Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
28
- const installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')} --legacy-peer-deps`;
29
- Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
30
- try {
31
- let stdout = await execSync(installCommand, {
32
- cwd: getNodeModulesPath(),
33
- shell: true
34
- });
35
- if (stdout) {
36
- Logger.logger(stdout);
37
- }
38
- Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
39
- return restorePackageJsonContent(packageJsonBeforePluginsInstallation);
40
- } catch (error) {
41
- Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins. Kindly retry the command");
42
- 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}`);
43
48
  return false;
44
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
+ // }
45
66
  } else {
46
67
  Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
47
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-7",
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"