@zohodesk/codestandard-validator 1.1.3 → 1.1.4

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/bin/cliCI.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @author rajasekar 17710
5
+ * @fileoverview This script is a Node.js executable that imports and runs the module `runner` from the `../build/lib/` directory.
6
+ */
7
+
8
+ require("@zohodesk/codestandard-analytics/build/lib/runner")
@@ -102,14 +102,7 @@ async function runLintWorkflow(files, branch) {
102
102
  const execute = new Execution(EsLint, SonarQube, cliobj);
103
103
  await execute.executeLintHandler().finally(async () => {
104
104
  await execute.executeMetricHandler();
105
- /**
106
- * global.analytics.totalIssues = global.analytics.totalIssues + 1;
107
- global.analytics.status = "FAILURE";
108
- global.analytics.message = 'Issues are detected, please review and resolve the errors'
109
- */
110
- // const { issues, hasIssue, totalIssues } = fetchProjectIssuesViaCurl("projectName");
111
105
  });
112
- // Logger.log(Logger.INFO_TYPE,global.analytics)
113
106
  return global.analytics.status == 'FAILURE' ? true : false;
114
107
  }
115
108
  module.exports = {
@@ -17,9 +17,6 @@ const {
17
17
  const {
18
18
  Logger
19
19
  } = require('../../utils/Logger/Logger');
20
- const {
21
- checkIfPluginsAreInstalled
22
- } = require('../../utils/PluginsInstallation/checkIfPluginsAreInstalled');
23
20
  const {
24
21
  getBranchName
25
22
  } = require('../../utils/GitActions/gitActions');
@@ -189,15 +186,6 @@ async function calculateGitDiffForFile(branch_name, file) {
189
186
  });
190
187
  });
191
188
  }
192
- /**
193
- * @function {areAllPluginsInstalled} - method whether plugin is installed or not
194
- * @returns {Boolean} - return boolean based on plugin installed or not
195
- */
196
-
197
- function areAllPluginsInstalled() {
198
- let unInstalledPlugins = checkIfPluginsAreInstalled().uninstalledPlugins;
199
- return unInstalledPlugins.length === 0 ? true : false;
200
- }
201
189
 
202
190
  /**
203
191
  * @function {isOnlyWarningsPresentInFile} - method that checks if only eslint warnings are present in a file
@@ -226,143 +214,136 @@ async function preCommitHook_default() {
226
214
  Logger.log(Logger.INFO_TYPE, 'Looks like you have merged. So skipping pre commit check');
227
215
  process.exit(0);
228
216
  } catch (error) {
229
- if (areAllPluginsInstalled()) {
230
- let staged_files = [];
231
- let eslintConfigFiles = ['.eslintrc.js'];
232
- let exemptionFiles = [];
233
- let current_branch = '';
234
- let hasEslintErrorsInChangedLines = false;
235
- let hasEslintErrorsInFiles = false;
236
- let areFilesStaged = false;
237
- let shouldAbortCommit = false;
238
- try {
239
- current_branch = await getBranchName();
240
- } catch {
241
- Logger.log(Logger.INFO_TYPE, "Error fetching current branch");
242
- }
243
- try {
244
- staged_files = await getStagedFiles();
245
- if (!staged_files.length == 0) {
246
- const {
247
- JsFiles: staged_filesJS,
248
- CssFiles
249
- } = filterFiles(staged_files, eslintConfigFiles, true);
217
+ let staged_files = [];
218
+ let eslintConfigFiles = ['.eslintrc.js'];
219
+ let exemptionFiles = [];
220
+ let current_branch = '';
221
+ let hasEslintErrorsInChangedLines = false;
222
+ let hasEslintErrorsInFiles = false;
223
+ let areFilesStaged = false;
224
+ let shouldAbortCommit = false;
225
+ try {
226
+ current_branch = await getBranchName();
227
+ } catch {
228
+ Logger.log(Logger.INFO_TYPE, "Error fetching current branch");
229
+ }
230
+ try {
231
+ staged_files = await getStagedFiles();
232
+ if (!staged_files.length == 0) {
233
+ const {
234
+ JsFiles: staged_filesJS,
235
+ CssFiles
236
+ } = filterFiles(staged_files, eslintConfigFiles, true);
250
237
 
251
- // staged_filesJS = filterFiles(staged_filesJS,exemptionFiles) //this is the code for giving exemption to a file during pre commit
252
- // if(staged_filesJS.length === 0){
253
- // Logger.log(Logger.SUCCESS_TYPE,`Commit Successful`)
254
- // process.exit(0)
255
- // }
238
+ // staged_filesJS = filterFiles(staged_filesJS,exemptionFiles) //this is the code for giving exemption to a file during pre commit
239
+ // if(staged_filesJS.length === 0){
240
+ // Logger.log(Logger.SUCCESS_TYPE,`Commit Successful`)
241
+ // process.exit(0)
242
+ // }
256
243
 
257
- // CssFiles not Enabled For while
258
- areFilesStaged = true;
259
- var stagedFiles = [...staged_filesJS];
260
- for (let file in stagedFiles) {
261
- let currentFileName = stagedFiles[file];
262
- let changedLinesArray = [];
263
- let eslintErrorsInChangedLines = new Set();
264
- let isOnlyEslintWarningsPresentInFile = false;
265
- if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
266
- try {
267
- var errorsInFile = await lintFiles(stagedFiles[file]);
268
- // eslintErrorsInFile = impactBasedPrecommit == false ? filterWarningInFile(errorsInFile) : errorsInFile
269
- if (stagedFiles[file] && typeof stagedFiles[file] == 'string') {
270
- if (!errorsInFile.length == 0) {
271
- //Calculating changed lines in a file and storing them in respective arrays
272
- if (impactBasedPrecommit) {
273
- //git diff is computed and stored in an array
274
- let git_diff = await calculateGitDiffForFile(current_branch, stagedFiles[file]);
275
- changedLinesArray = git_diff.filter(line => line.startsWith('@@'));
276
- let changedLinesStartArray = [];
277
- let changedLinesEndArray = [];
278
- for (let number of changedLinesArray) {
279
- let changesStartLine = parseInt(number.split(' ')[2].split(',')[0]);
280
- changedLinesStartArray.push(changesStartLine);
281
- let changesEndLine = number.split(' ')[2].split(',')[1];
282
- if (changesEndLine === undefined) {
283
- changedLinesEndArray.push(changesStartLine);
284
- } else {
285
- changedLinesEndArray.push(changesStartLine + parseInt(changesEndLine) - 1);
286
- }
244
+ // CssFiles not Enabled For while
245
+ areFilesStaged = true;
246
+ var stagedFiles = [...staged_filesJS];
247
+ for (let file in stagedFiles) {
248
+ let currentFileName = stagedFiles[file];
249
+ let changedLinesArray = [];
250
+ let eslintErrorsInChangedLines = new Set();
251
+ let isOnlyEslintWarningsPresentInFile = false;
252
+ if (getSupportedLanguage().includes(path.extname(stagedFiles[file]))) {
253
+ try {
254
+ var errorsInFile = await lintFiles(stagedFiles[file]);
255
+ // eslintErrorsInFile = impactBasedPrecommit == false ? filterWarningInFile(errorsInFile) : errorsInFile
256
+ if (stagedFiles[file] && typeof stagedFiles[file] == 'string') {
257
+ if (!errorsInFile.length == 0) {
258
+ //Calculating changed lines in a file and storing them in respective arrays
259
+ if (impactBasedPrecommit) {
260
+ //git diff is computed and stored in an array
261
+ let git_diff = await calculateGitDiffForFile(current_branch, stagedFiles[file]);
262
+ changedLinesArray = git_diff.filter(line => line.startsWith('@@'));
263
+ let changedLinesStartArray = [];
264
+ let changedLinesEndArray = [];
265
+ for (let number of changedLinesArray) {
266
+ let changesStartLine = parseInt(number.split(' ')[2].split(',')[0]);
267
+ changedLinesStartArray.push(changesStartLine);
268
+ let changesEndLine = number.split(' ')[2].split(',')[1];
269
+ if (changesEndLine === undefined) {
270
+ changedLinesEndArray.push(changesStartLine);
271
+ } else {
272
+ changedLinesEndArray.push(changesStartLine + parseInt(changesEndLine) - 1);
287
273
  }
288
- for (let error = 1; error < errorsInFile.length - 2; error++) {
289
- //errorsInFile[error].trim() - 69:26 error => Do not hardcode content. Use I18N key instead no-hardcoding/no-hardcoding,
290
- //errorsInFile[error].trim().split(' ')[0] => 69:26
291
- //errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
274
+ }
275
+ for (let error = 1; error < errorsInFile.length - 2; error++) {
276
+ //errorsInFile[error].trim() - 69:26 error => Do not hardcode content. Use I18N key instead no-hardcoding/no-hardcoding,
277
+ //errorsInFile[error].trim().split(' ')[0] => 69:26
278
+ //errorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
292
279
 
293
- let eslintErrorLineNumber = errorsInFile[error].trim().split(' ')[0].split(':')[0];
294
- if (MandatoryListRules.some(ruleId => errorsInFile[error].trim().includes(ruleId))) {
280
+ let eslintErrorLineNumber = errorsInFile[error].trim().split(' ')[0].split(':')[0];
281
+ if (MandatoryListRules.some(ruleId => errorsInFile[error].trim().includes(ruleId))) {
282
+ eslintErrorsInChangedLines.add(errorsInFile[error]);
283
+ }
284
+ for (let lineNumber in changedLinesStartArray) {
285
+ if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
295
286
  eslintErrorsInChangedLines.add(errorsInFile[error]);
296
287
  }
297
- for (let lineNumber in changedLinesStartArray) {
298
- if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
299
- eslintErrorsInChangedLines.add(errorsInFile[error]);
300
- }
301
- }
302
288
  }
303
- if (eslintErrorsInChangedLines.size > 0) {
304
- isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
305
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
306
- for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
307
- Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
308
- }
309
- if (shouldWarningsAbortCommit) {
310
- hasEslintErrorsInChangedLines = true;
311
- shouldAbortCommit = true;
312
- } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
313
- hasEslintErrorsInChangedLines = false;
314
- } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
315
- hasEslintErrorsInChangedLines = true;
316
- shouldAbortCommit = true;
317
- }
289
+ }
290
+ if (eslintErrorsInChangedLines.size > 0) {
291
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(Array.from(eslintErrorsInChangedLines));
292
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
293
+ for (let eslintError of Array.from(eslintErrorsInChangedLines)) {
294
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
318
295
  }
319
- } else {
320
- if (errorsInFile.length > 0) {
321
- let startIndex = 1;
322
- let endIndex = errorsInFile.length - 2;
323
- let listOsEslintErrors = errorsInFile.slice(startIndex, endIndex);
324
- isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(listOsEslintErrors);
325
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
326
- for (let eslintError of listOsEslintErrors) {
327
- Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
328
- }
329
- if (shouldWarningsAbortCommit) {
330
- hasEslintErrorsInFiles = true;
331
- shouldAbortCommit = true;
332
- } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
333
- hasEslintErrorsInFiles = false;
334
- } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
335
- hasEslintErrorsInFiles = true;
336
- shouldAbortCommit = true;
337
- }
296
+ if (shouldWarningsAbortCommit) {
297
+ hasEslintErrorsInChangedLines = true;
298
+ shouldAbortCommit = true;
299
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
300
+ hasEslintErrorsInChangedLines = false;
301
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
302
+ hasEslintErrorsInChangedLines = true;
303
+ shouldAbortCommit = true;
304
+ }
305
+ }
306
+ } else {
307
+ if (errorsInFile.length > 0) {
308
+ let startIndex = 1;
309
+ let endIndex = errorsInFile.length - 2;
310
+ let listOsEslintErrors = errorsInFile.slice(startIndex, endIndex);
311
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(listOsEslintErrors);
312
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
313
+ for (let eslintError of listOsEslintErrors) {
314
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
315
+ }
316
+ if (shouldWarningsAbortCommit) {
317
+ hasEslintErrorsInFiles = true;
318
+ shouldAbortCommit = true;
319
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
320
+ hasEslintErrorsInFiles = false;
321
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
322
+ hasEslintErrorsInFiles = true;
323
+ shouldAbortCommit = true;
338
324
  }
339
325
  }
340
326
  }
341
327
  }
342
- } catch (err) {
343
- Logger.log(Logger.FAILURE_TYPE, err);
344
- Logger.log(Logger.FAILURE_TYPE, "Error in executing lint command");
345
328
  }
329
+ } catch (err) {
330
+ Logger.log(Logger.FAILURE_TYPE, err);
331
+ Logger.log(Logger.FAILURE_TYPE, "Error in executing lint command");
346
332
  }
347
333
  }
348
- } else if (staged_files.length === 0) {
349
- Logger.log(Logger.INFO_TYPE, 'No files have been staged. Stage your files before committing');
350
334
  }
351
- } catch {
352
- Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
353
- }
354
- if (shouldAbortCommit) {
355
- Logger.log(Logger.FAILURE_TYPE, `There are linter errors/warnings present. So commit is aborted.`);
356
- process.exit(1);
357
- } else if (shouldAbortCommit === false && staged_files.length !== 0) {
358
- Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
359
- process.exit(0);
335
+ } else if (staged_files.length === 0) {
336
+ Logger.log(Logger.INFO_TYPE, 'No files have been staged. Stage your files before committing');
360
337
  }
361
- } else {
362
- Logger.log(Logger.FAILURE_TYPE, 'Commit failed since some lint plugins are not installed');
363
- Logger.log(Logger.INFO_TYPE, `Kindly execute the command \x1b[37mnpx ZDPrecommit setupPlugins \x1b[33mfrom the location where package.json is present to install the plugins`);
364
- Logger.log(Logger.INFO_TYPE, 'Execute the command and kindly try committing again.');
338
+ } catch {
339
+ Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
340
+ }
341
+ if (shouldAbortCommit) {
342
+ Logger.log(Logger.FAILURE_TYPE, `There are linter errors/warnings present. So commit is aborted.`);
365
343
  process.exit(1);
344
+ } else if (shouldAbortCommit === false && staged_files.length !== 0) {
345
+ Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
346
+ process.exit(0);
366
347
  }
367
348
  }
368
349
  }
@@ -47,10 +47,10 @@ async function hooks() {
47
47
  } = getPluginsToInstall();
48
48
  await executeMethodsThatReturnBooleanValue('Some issue occurred in installing plugins', installPlugins, uninstalledPlugins);
49
49
  }
50
- if (process.env.CLIPRECOMMIT && Boolean(process.env.CLIPRECOMMIT) == true) {
51
- require('./Precommit/pre-commit-default');
52
- } else {
50
+ if (process.env.PUSHTOSONARQUBE && Boolean(process.env.PUSHTOSONARQUBE) == true) {
53
51
  require('./Precommit/commit');
52
+ } else {
53
+ require('./Precommit/pre-commit-default');
54
54
  }
55
55
  }
56
56
  hooks();
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.encrypt = exports.decrypt = void 0;
7
3
  const caesarCipher = (str, shift) => {
8
4
  return str.split("").map(char => {
9
5
  let code = char.charCodeAt();
@@ -16,6 +12,8 @@ const caesarCipher = (str, shift) => {
16
12
  }).join("");
17
13
  };
18
14
  const encrypt = (plaintext, shift) => caesarCipher(plaintext, shift);
19
- exports.encrypt = encrypt;
20
15
  const decrypt = (ciphertext, shift) => caesarCipher(ciphertext, 26 - shift);
21
- exports.decrypt = decrypt;
16
+ module.exports = {
17
+ encrypt,
18
+ decrypt
19
+ };
package/changeLog.md CHANGED
@@ -41,4 +41,9 @@
41
41
 
42
42
  # 1.1.3 - SonarQube Enable
43
43
 
44
- 1. Remote Installtion flow moved to before and handled process.exit removed
44
+ 1. Remote Installtion flow moved to before and handled process.exit removed
45
+
46
+ # 1.1.4 - Minor Bug Fixes
47
+
48
+ 1. ProjectId api revamp
49
+ 2. code standard analytics bin bind to code standard validator bin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,12 +11,13 @@
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "bin": {
14
- "ZDPrecommit": "./bin/cli.js"
14
+ "ZDPrecommit": "./bin/cli.js",
15
+ "ZDLintFramework": "./bin/cliCI.js"
15
16
  },
16
17
  "type": "commonjs",
17
18
  "dependencies": {
18
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
19
- "@zohodesk/codestandard-analytics": "1.1.4",
20
+ "@zohodesk/codestandard-analytics": "1.1.4-exp-2",
20
21
  "eslint": "8.26.0",
21
22
  "stylelint": "16.23.0"
22
23
  },