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

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,10 +16,6 @@ const {
16
16
  const {
17
17
  runLintWorkflow
18
18
  } = require("./lint");
19
- process.env.SONARQUBE_EXTERNAL = 7; // sonarqube_external
20
- process.env.SONARQUBE = 12;
21
- process.env.ZGIT_TOKEN = 12; // sonarqube & zgit
22
-
23
19
  global.analytics = {
24
20
  status: "SUCCESS",
25
21
  sonarQubeStatus: false,
@@ -10,6 +10,9 @@ const path = require("path");
10
10
  const {
11
11
  getNodeModulesPath
12
12
  } = require("../../utils/General/getNodeModulesPath");
13
+ const {
14
+ getRootDirectory
15
+ } = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
13
16
  function getAbsolutePath(p1, p2) {
14
17
  if (path.isAbsolute(p2)) {
15
18
  return path.normalize(p2);
@@ -18,7 +21,7 @@ function getAbsolutePath(p1, p2) {
18
21
  }
19
22
  async function calculateGitDiffForFile(branch, file) {
20
23
  try {
21
- const stdout = execSync(`git diff -U0 ${branch.trim()} -- ${getAbsolutePath(getNodeModulesPath(), file)}`).toString();
24
+ const stdout = execSync(`git diff -U0 ${branch.trim()} -- ${getAbsolutePath(getNodeModulesPath(), path.resolve(getRootDirectory(), file))}`).toString();
22
25
  return stdout;
23
26
  } catch (err) {
24
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,7 +56,7 @@ 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
61
  }) => stderr ? stderr.toString().trim().split('\n') : []).catch(err => {
63
62
  Logger.log(Logger.FAILURE_TYPE, err);
@@ -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
@@ -123,7 +124,7 @@ function findEslintErrors(file) {
123
124
  if (isNodeModulesPresent) {
124
125
  if (isEslintExecutablePresent) {
125
126
  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) => {
127
+ 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
128
  if (stderr) {
128
129
  resolve(stderr.trim().split('\n'));
129
130
  } else if (error) {
@@ -156,11 +157,7 @@ function findStyleLintErrors(filePath) {
156
157
  }, (error, stderr, stdout) => {
157
158
  if (stdout) {
158
159
  resolve(stdout.trim().split('\n'));
159
- }
160
- // if(stderr){
161
- // resolve(stderr.trim().split('\n'))
162
- // }
163
- else if (error) {
160
+ } else if (error) {
164
161
  Logger.log(Logger.FAILURE_TYPE, error);
165
162
  reject("Error executing stylelint command");
166
163
  } else {
@@ -181,7 +178,7 @@ function findStyleLintErrors(filePath) {
181
178
  * @returns {Promise<Array<string>>} - array of command line report as a string
182
179
  */
183
180
  async function calculateGitDiffForFile(branch_name, file) {
184
- let gitDiffCommand = `git diff -U0 ${branch_name.trim()} ${file}`;
181
+ let gitDiffCommand = `git diff -U0 ${branch_name.trim()} ${path.resolve(getRootDirectory(), file)}`;
185
182
  return new Promise((resolve, reject) => {
186
183
  exec(gitDiffCommand, (error, stderr) => {
187
184
  if (stderr) {
@@ -263,7 +260,7 @@ async function preCommitHook_default() {
263
260
  for (let file in stagedFiles) {
264
261
  let currentFileName = stagedFiles[file];
265
262
  let changedLinesArray = [];
266
- let eslintErrorsInChangedLines = [];
263
+ let eslintErrorsInChangedLines = new Set();
267
264
  let isOnlyEslintWarningsPresentInFile = false;
268
265
  if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
269
266
  try {
@@ -294,16 +291,19 @@ async function preCommitHook_default() {
294
291
  //errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
295
292
 
296
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
+ }
297
297
  for (let lineNumber in changedLinesStartArray) {
298
298
  if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
299
- eslintErrorsInChangedLines.push(errorsInFile[error]);
299
+ eslintErrorsInChangedLines.add(errorsInFile[error]);
300
300
  }
301
301
  }
302
302
  }
303
- if (eslintErrorsInChangedLines.length > 0) {
304
- isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(eslintErrorsInChangedLines);
303
+ if (eslintErrorsInChangedLines.size > 0) {
304
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
305
305
  Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
306
- for (let eslintError of eslintErrorsInChangedLines) {
306
+ for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
307
307
  Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
308
308
  }
309
309
  if (shouldWarningsAbortCommit) {
@@ -9,6 +9,8 @@ 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
16
  const stdout = await execSync("git rev-parse -q --verify MERGE_HEAD").toString();
@@ -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())) {
package/build/lib/cli.js CHANGED
@@ -18,13 +18,7 @@ const {
18
18
  const {
19
19
  getPluginsToInstall
20
20
  } = require("../utils/PluginsInstallation/checkIfPluginsAreInstalled");
21
- const path = require("path");
22
21
  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
- })();
28
22
  async function run() {
29
23
  switch (action) {
30
24
  case "setup":
@@ -36,7 +36,7 @@ async function postInstall() {
36
36
  await executeMethodsThatReturnBooleanValue("Make sure zgit.csez.zohocorpin.com is accessible", cloneViaCdt, null);
37
37
  await executeMethodsThatReturnBooleanValue("Some issue occurred in creating eslint config file.", createConfigFile, null);
38
38
  Logger.log(Logger.SUCCESS_TYPE, "Pre commit setup successfull");
39
- arePluginsInstalled();
39
+ // arePluginsInstalled();
40
40
  } catch (error) {
41
41
  Logger.log(Logger.FAILURE_TYPE, `Kindly retry npm install. & ${error.message}`);
42
42
  }
@@ -25,7 +25,7 @@ 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: "DBWyfB46DBWyfB4dRIN1",
28
+ meticHandler_api_token: "YWRtaW46YWRtaW4yMDI1",
29
29
  metric_token: "sqa_371336f636584b54f662c6495a46228fdc6abaa8",
30
30
  branchDiffPath: path.resolve(process.cwd(), "diffBranch.json"),
31
31
  gitEndPoint: "https://zgit.csez.zohocorpin.com",
@@ -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
@@ -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 = `${"https://client-linters.zdesk.csez.zohocorpin.com" || metricServerHost}/api/issues/search`;
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.INFO_TYPE, 'Installing plugins ....');
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;
@@ -0,0 +1,3 @@
1
+ const MandatoryListRules = [ "@zohodesk/fitnessfunction/chunk-size"]
2
+
3
+ module.exports = MandatoryListRules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.0.0-exp-8",
3
+ "version": "1.0.0-exp-10",
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-12",
18
+ "@zohodesk/codestandard-analytics": "1.0.2-exp-13",
19
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
20
20
  "eslint": "8.26.0",
21
21
  "stylelint": "16.23.0"
package/hash.js DELETED
@@ -1,30 +0,0 @@
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))