@zohodesk/codestandard-validator 1.0.0-exp-1 → 1.0.0-exp-2

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,6 +16,15 @@ const {
16
16
  const {
17
17
  runLintWorkflow
18
18
  } = require("./lint");
19
+ process.env.DECRYPT_SONARQUBE = 7;
20
+ process.env.DECRYPT_TOKEN = 12;
21
+ global.analytics = {
22
+ status: "SUCCESS",
23
+ sonarQubeStatus: false,
24
+ message: "No issues are found, your code adheres to the required standards.",
25
+ isExemptionApproved: false,
26
+ totalIssues: 0
27
+ };
19
28
  async function preCommitHook() {
20
29
  Logger.log(Logger.INFO_TYPE, "Executing pre commit hook...");
21
30
  Logger.log(Logger.INFO_TYPE, `working dir: ${process.cwd()}`);
@@ -2,45 +2,47 @@
2
2
 
3
3
  const {
4
4
  exec
5
- } = require("child_process");
5
+ } = require('child_process');
6
6
  const {
7
7
  promisify
8
- } = require("util");
9
- const fs = require("fs");
10
- const path = require("path");
8
+ } = require('util');
9
+ const fs = require('fs');
10
+ const path = require('path');
11
11
  const {
12
12
  getNodeModulesPath
13
- } = require("../../utils/General/getNodeModulesPath");
13
+ } = require('../../utils/General/getNodeModulesPath');
14
14
  const {
15
15
  getEslintExecutablePath
16
- } = require("../../utils/ConfigFileUtils/getEslintExecutablePath");
16
+ } = require('../../utils/ConfigFileUtils/getEslintExecutablePath');
17
17
  const {
18
18
  getRootDirectory
19
- } = require("../../utils/General/RootDirectoryUtils/getRootDirectory");
19
+ } = require('../../utils/General/RootDirectoryUtils/getRootDirectory');
20
20
  const {
21
21
  getSupportedLanguage
22
- } = require("../../utils/General/getGeneralInfo");
22
+ } = require('../../utils/General/getGeneralInfo');
23
23
  const {
24
24
  filterFileLevelErrors,
25
25
  filterErrorsByChangedLines,
26
26
  logErrors
27
- } = require("./errorhelpers");
27
+ } = require('./errorhelpers');
28
28
  const {
29
- Execution
30
- } = require("@zohodesk/codestandard-analytics");
29
+ Execution,
30
+ SonarQube,
31
+ EsLint
32
+ } = require('@zohodesk/codestandard-analytics');
31
33
  const {
32
34
  getBranchName
33
- } = require("../../utils/GitActions/gitActions");
35
+ } = require('../../utils/GitActions/gitActions');
34
36
  const {
35
37
  extractDiffHunks
36
- } = require("./utils");
38
+ } = require('./utils');
37
39
  const execAsync = promisify(exec);
38
40
  async function lintFiles(filePath) {
39
41
  const ext = path.extname(filePath);
40
- if ([".js", ".ts", ".tsx", ".jsx", ".properties"].includes(ext)) {
42
+ if (['.js', '.ts', '.tsx', '.jsx', '.properties'].includes(ext)) {
41
43
  return findEslintErrors(filePath);
42
44
  }
43
- if ([".css", ".scss"].includes(ext)) {
45
+ if (['.css', '.scss'].includes(ext)) {
44
46
  return findStyleLintErrors(filePath);
45
47
  }
46
48
  return [];
@@ -51,28 +53,28 @@ async function findEslintErrors(file) {
51
53
  const eslintConfig = `${nodeModulesPath}/.eslintrc.js`;
52
54
  var rulesArrayReport = [];
53
55
  if (!fs.existsSync(nodeModulesPath)) {
54
- Logger.log(Logger.INFO_TYPE, "node_modules not found");
56
+ Logger.log(Logger.INFO_TYPE, 'node_modules not found');
55
57
  return [];
56
58
  }
57
59
  if (!fs.existsSync(eslintPath)) {
58
- Logger.log(Logger.INFO_TYPE, "Eslint executable not found. Make sure eslint plugin is installed");
60
+ Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. Make sure eslint plugin is installed');
59
61
  return [];
60
62
  }
61
63
  return execAsync(`npx --ignore-existing "${eslintPath}" --config "${eslintConfig}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`).then(({
62
64
  stderr
63
- }) => stderr ? stderr.trim().split("\n") : []).catch(err => {
65
+ }) => stderr ? stderr.trim().split('\n') : []).catch(err => {
64
66
  Logger.log(Logger.FAILURE_TYPE, err);
65
- throw new Error("Error executing eslint command");
67
+ throw new Error('Error executing eslint command');
66
68
  });
67
69
  }
68
70
  function findStyleLintErrors(filePath) {
69
- const configFile = path.resolve(getNodeModulesPath(), ".stylelintrc.js");
71
+ const configFile = path.resolve(getNodeModulesPath(), '.stylelintrc.js');
70
72
  const absolutePath = path.join(getRootDirectory(), filePath);
71
73
  return execAsync(`npx stylelint ${absolutePath} --config ${configFile}`, {
72
74
  cwd: getNodeModulesPath()
73
75
  }).then(({
74
76
  stdout
75
- }) => stdout ? stdout.trim().split("\n") : []).catch(err => {
77
+ }) => stdout ? stdout.trim().split('\n') : []).catch(err => {
76
78
  Logger.log(Logger.FAILURE_TYPE, err);
77
79
  return [];
78
80
  });
@@ -111,12 +113,15 @@ async function runLintWorkflow(files, branch) {
111
113
  // shouldAbort ||= shouldWarningsAbortCommit || !isOnlyWarnings(filteredErrors);
112
114
  // }
113
115
  }
114
- const diffPath = path.resolve(getNodeModulesPath(), "diffBranch.json");
115
- fs.writeFileSync(diffPath, branchDiff);
116
- const execute = new Execution(EsLint, SonarQube, $cliObjects);
117
- await execute.executeLintHandler().finally(() => {
118
- execute.executeMetricHandler();
119
- });
116
+ const diffPath = path.resolve(getNodeModulesPath(), 'diffBranch.json');
117
+ fs.writeFileSync(diffPath, JSON.stringify(diffPath));
118
+ const cliobj = {
119
+ env: 'ci',
120
+ cmdExecuted: 'dev-ci'
121
+ };
122
+ const execute = new Execution(EsLint, SonarQube, cliobj);
123
+ await execute.executeLintHandler();
124
+ await execute.executeMetricHandler();
120
125
  return global.analytics.status == 'FAILURE' ? true : false;
121
126
  }
122
127
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.0.0-exp-1",
3
+ "version": "1.0.0-exp-2",
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-1",
18
+ "@zohodesk/codestandard-analytics":"1.0.2-exp-2",
19
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
20
20
  "eslint": "8.26.0",
21
21
  "stylelint":"16.23.0"