@zohodesk/codestandard-validator 1.0.0-exp-7 → 1.0.0-exp-9

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,6 @@ const {
16
16
  const {
17
17
  runLintWorkflow
18
18
  } = require("./lint");
19
- process.env.DECRYPT_SONARQUBE = 7;
20
- process.env.DECRYPT_TOKEN = 12;
21
19
  global.analytics = {
22
20
  status: "SUCCESS",
23
21
  sonarQubeStatus: false,
@@ -6,9 +6,22 @@ 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
+ const {
14
+ getRootDirectory
15
+ } = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
16
+ function getAbsolutePath(p1, p2) {
17
+ if (path.isAbsolute(p2)) {
18
+ return path.normalize(p2);
19
+ }
20
+ return path.resolve(p1, p2);
21
+ }
9
22
  async function calculateGitDiffForFile(branch, file) {
10
23
  try {
11
- const stdout = execSync(`git diff -U0 ${branch.trim()} ${file}`);
24
+ const stdout = execSync(`git diff -U0 ${branch.trim()} -- ${getAbsolutePath(getNodeModulesPath(), path.resolve(getRootDirectory(), file))}`).toString();
12
25
  return stdout;
13
26
  } catch (err) {
14
27
  throw err;
@@ -48,7 +48,6 @@ async function findEslintErrors(file) {
48
48
  const nodeModulesPath = getNodeModulesPath();
49
49
  const eslintPath = getEslintExecutablePath();
50
50
  const eslintConfig = `${nodeModulesPath}/.eslintrc.js`;
51
- var rulesArrayReport = [];
52
51
  if (!fs.existsSync(nodeModulesPath)) {
53
52
  Logger.log(Logger.INFO_TYPE, 'node_modules not found');
54
53
  return [];
@@ -57,9 +56,9 @@ async function findEslintErrors(file) {
57
56
  Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. Make sure eslint plugin is installed');
58
57
  return [];
59
58
  }
60
- return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
59
+ return execSync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${path.resolve(getRootDirectory(), file)}`).then(({
61
60
  stderr
62
- }) => stderr ? stderr.trim().split('\n') : []).catch(err => {
61
+ }) => stderr ? stderr.toString().trim().split('\n') : []).catch(err => {
63
62
  Logger.log(Logger.FAILURE_TYPE, err);
64
63
  throw new Error('Error executing eslint command');
65
64
  });
@@ -71,7 +70,7 @@ function findStyleLintErrors(filePath) {
71
70
  cwd: getNodeModulesPath()
72
71
  }).then(({
73
72
  stdout
74
- }) => stdout ? stdout.trim().split('\n') : []).catch(err => {
73
+ }) => stdout ? stdout.toString().trim().split('\n') : []).catch(err => {
75
74
  Logger.log(Logger.FAILURE_TYPE, err);
76
75
  return [];
77
76
  });
@@ -123,7 +123,7 @@ function findEslintErrors(file) {
123
123
  if (isNodeModulesPresent) {
124
124
  if (isEslintExecutablePresent) {
125
125
  return new Promise((resolve, reject) => {
126
- exec(`npx --ignore-existing "${eslintExecutablePath}" --config "${eslintConfigurationFilePath}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPathOfProject}/node_modules" ${file}`, (error, stderr, stdout) => {
126
+ exec(`npx --ignore-existing "${eslintExecutablePath}" --config "${eslintConfigurationFilePath}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPathOfProject}/node_modules" ${path.resolve(getRootDirectory(), file)}`, (error, stderr, stdout) => {
127
127
  if (stderr) {
128
128
  resolve(stderr.trim().split('\n'));
129
129
  } else if (error) {
@@ -156,11 +156,7 @@ function findStyleLintErrors(filePath) {
156
156
  }, (error, stderr, stdout) => {
157
157
  if (stdout) {
158
158
  resolve(stdout.trim().split('\n'));
159
- }
160
- // if(stderr){
161
- // resolve(stderr.trim().split('\n'))
162
- // }
163
- else if (error) {
159
+ } else if (error) {
164
160
  Logger.log(Logger.FAILURE_TYPE, error);
165
161
  reject("Error executing stylelint command");
166
162
  } else {
@@ -181,7 +177,7 @@ function findStyleLintErrors(filePath) {
181
177
  * @returns {Promise<Array<string>>} - array of command line report as a string
182
178
  */
183
179
  async function calculateGitDiffForFile(branch_name, file) {
184
- let gitDiffCommand = `git diff -U0 ${branch_name.trim()} ${file}`;
180
+ let gitDiffCommand = `git diff -U0 ${branch_name.trim()} ${path.resolve(getRootDirectory(), file)}`;
185
181
  return new Promise((resolve, reject) => {
186
182
  exec(gitDiffCommand, (error, stderr) => {
187
183
  if (stderr) {
@@ -9,9 +9,11 @@ const {
9
9
  const {
10
10
  checkIfPluginsAreInstalled
11
11
  } = require("../../utils/PluginsInstallation/checkIfPluginsAreInstalled");
12
+ const fs = require("fs");
13
+ const path = require("path");
12
14
  async function isMergeCommit() {
13
15
  try {
14
- const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD");
16
+ const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD").toString();
15
17
  return Boolean(stdout.trim());
16
18
  } catch {
17
19
  return false;
@@ -19,7 +21,7 @@ async function isMergeCommit() {
19
21
  }
20
22
  async function getStagedFiles() {
21
23
  try {
22
- const stdout = await execSync("git diff --staged --name-only");
24
+ const stdout = await execSync("git diff --staged --name-only").toString();
23
25
  const files = stdout.trim().split("\n").filter(Boolean);
24
26
  return files.filter(file => fs.existsSync(path.resolve(getRootDirectory(), file)));
25
27
  } catch {
@@ -21,6 +21,10 @@ const path = require('path');
21
21
  const {
22
22
  Logger
23
23
  } = require('../utils/Logger/Logger');
24
+ const config = require(path.join(process.cwd(), 'lint.config.js'));
25
+ process.env.SONARQUBE_EXTERNAL = config.metric_token;
26
+ process.env.SONARQUBE = config.meticHandler_api_token;
27
+ process.env.ZGIT_TOKEN = config.token;
24
28
  async function hooks() {
25
29
  var jsonFilePath = path.join(__dirname, '..', '..', 'jsonUtils', 'fsUtils.json');
26
30
  if (!(getLastCommitHash() == getStoredCommitHash())) {
@@ -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: "YWRtaW46YWRtaW4yMDI1",
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
  };
@@ -54,7 +54,7 @@ function cloneViaCdt() {
54
54
 
55
55
  // Construct endpoint with credentials if in CI or automation
56
56
  const isAutomatedEnv = currentEnv === "CI" || currentEnv === "DEVAUTOMATION";
57
- const authenticatedEndpoint = isAutomatedEnv ? `https://${user}:${decrypt(token, 12)}@${endPoint}` : `https://${endPoint}`;
57
+ const authenticatedEndpoint = isAutomatedEnv ? `https://${user}:${process.env.ZGIT_TOKEN}@${endPoint}` : `https://${endPoint}`;
58
58
  const cloneCommand = ['npx cdt clone', `--clone:type=${type}`, `--clone:url=${authenticatedEndpoint}`, `--clone:branch=${branch}`, `--clone:cacheDir=${cacheDirectory}`, `--clone:proj:name=${commonLinterRepoName}`].join(' ');
59
59
 
60
60
  // Execute the CDT command
@@ -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/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-9",
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"