@zohodesk/codestandard-validator 1.2.4-exp-2 → 1.2.4-exp-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 CHANGED
@@ -5,4 +5,9 @@
5
5
  * @fileoverview This script is a Node.js executable that imports and runs the module `runner` from the `../build/lib/` directory.
6
6
  */
7
7
 
8
- require("@zohodesk/codestandard-analytics/build/lib/runner")
8
+ (async function () {
9
+ const { initConfig, getConfigPathExecute } = require('../build/utils/General/Config');
10
+ await initConfig(getConfigPathExecute());
11
+ await require('../build/chunk/chunk_Restriction');
12
+ require('@zohodesk/codestandard-analytics/build/lib/runner');
13
+ })();
@@ -185,6 +185,7 @@ if (shouldEnable) {
185
185
  };
186
186
  try {
187
187
  await getGitChangesets(myCurrentBranch, targetRelease, remoteName);
188
+ process.env.CHUNK_SIZE = JSON.stringify(chunkSize);
188
189
  if (chunkSize.$modifieldLines <= chunk_size_env) {
189
190
  Logger.log(`${GREEN}Your Chunk was ${chunkSize.$modifieldLines} and remaining size ${chunk_size_env - chunkSize.$modifieldLines}${RESET}`);
190
191
  } else {
@@ -131,10 +131,7 @@ function findEslintErrors(file) {
131
131
  resolve([]);
132
132
  }
133
133
  }, {
134
- env: {
135
- ...process.env,
136
- CHUNK_SIZE: (globalThis === null || globalThis === void 0 ? void 0 : globalThis.chunkSize) ?? ''
137
- }
134
+ env: process.env
138
135
  });
139
136
  });
140
137
  } else {
@@ -28,8 +28,6 @@ const {
28
28
  initConfig,
29
29
  getConfigPathExecute
30
30
  } = require('../utils/General/Config');
31
- require("../chunk/chunk_Restriction");
32
- initConfig(getConfigPathExecute());
33
31
  async function hooks() {
34
32
  var jsonFilePath = path.join(__dirname, '..', '..', 'jsonUtils', 'fsUtils.json');
35
33
  let latestCommit = getLastCommitHash();
@@ -54,4 +52,8 @@ async function hooks() {
54
52
  require('./Precommit/pre-commit-default');
55
53
  }
56
54
  }
57
- hooks();
55
+ (async function () {
56
+ await initConfig(getConfigPathExecute());
57
+ await require("../chunk/chunk_Restriction");
58
+ hooks();
59
+ })();
@@ -18,23 +18,35 @@ const {
18
18
  executeMethodsThatMayThrowException
19
19
  } = require("../General/wrapperFunctionToExecuteAFunction.js");
20
20
 
21
+ /**
22
+ * Resolve a file from service-specific dir if it exists, otherwise fall back to common dir.
23
+ * @param {string} baseDir
24
+ * @param {string|undefined} repoName
25
+ * @param {string} fileName
26
+ * @param {*} [fallback] - fallback value if no common path desired (e.g. undefined for pluginVersion)
27
+ * @returns {string|undefined}
28
+ */
29
+ function resolveServiceOrCommon(baseDir, repoName, fileName, fallback) {
30
+ if (repoName) {
31
+ const servicePath = path.join(baseDir, 'services', repoName, fileName);
32
+ if (existsSync(servicePath)) return servicePath;
33
+ }
34
+ return fallback !== undefined ? fallback : path.join(baseDir, 'common', fileName);
35
+ }
36
+
21
37
  /**
22
38
  * @function getLintConfiguration - returns eslint configuration file from common linters repo
23
39
  * @returns {object} - containing properties of the eslint configuration file
24
40
  */
25
41
  function getServicePathElseCommon() {
26
42
  const repoName = getRepoName();
27
- const libraryInstalledLocation = getLibraryInstalledLocation();
28
- let commonConfigPath = path.join(libraryInstalledLocation, commonLinterRepoName, 'common', 'index.js');
29
- const _configurationPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'index.js') : commonConfigPath;
30
- let _pathOfServiceSpecificEslintConfigFile = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.eslintrc.js') : path.join(libraryInstalledLocation, commonLinterRepoName, 'common', '.eslintrc.js');
31
- let _pluginVersionPath = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, 'pluginVersion.js') : undefined;
32
- let _cssLintConfig = repoName && existsSync(path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.stylelintrc.js')) ? path.join(libraryInstalledLocation, commonLinterRepoName, 'services', repoName, '.stylelintrc.js') : path.join(libraryInstalledLocation, commonLinterRepoName, 'common', '.stylelintrc.js');
43
+ const baseDir = path.join(getLibraryInstalledLocation(), commonLinterRepoName);
33
44
  return {
34
- configurationPath: _configurationPath,
35
- pathOfServiceSpecificEslintConfigFile: _pathOfServiceSpecificEslintConfigFile,
36
- pluginVersionPath: _pluginVersionPath,
37
- pathOfServiceSpecificCssConfigFile: _cssLintConfig
45
+ configurationPath: resolveServiceOrCommon(baseDir, repoName, 'index.js'),
46
+ pathOfServiceSpecificEslintConfigFile: resolveServiceOrCommon(baseDir, repoName, '.eslintrc.js'),
47
+ pluginVersionPath: resolveServiceOrCommon(baseDir, repoName, 'pluginVersion.js', null) || undefined,
48
+ pathOfServiceSpecificCssConfigFile: resolveServiceOrCommon(baseDir, repoName, '.stylelintrc.js'),
49
+ initializationPath: resolveServiceOrCommon(baseDir, repoName, 'initializeScript.js')
38
50
  };
39
51
  }
40
52
  function getLintConfigurationUtil() {
@@ -1,12 +1,29 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require('path');
4
+ const {
5
+ getServicePathElseCommon
6
+ } = require('../ConfigFileUtils/getLintConfiguration');
7
+ const {
8
+ Logger
9
+ } = require('../Logger/Logger');
4
10
  function initConfig(actualConfigPath) {
5
11
  const config = getConfigObject(actualConfigPath);
6
12
  process.env.SONARQUBE_EXTERNAL = config.metric_token;
7
13
  process.env.SONARQUBE = config.meticHandler_api_token;
8
14
  process.env.ZGIT_TOKEN = config.token;
9
15
  process.env.TOOL_TOKEN = config.toolToken;
16
+ try {
17
+ const {
18
+ initializationPath
19
+ } = getServicePathElseCommon();
20
+ const {
21
+ intialize
22
+ } = require(initializationPath);
23
+ intialize();
24
+ } catch (error) {
25
+ Logger.log(Logger.FAILURE_TYPE, `Error while initialize configuration: ${error}`);
26
+ }
10
27
  }
11
28
  function getConfigPathPostInstall() {
12
29
  return path.resolve(process.cwd(), '..', '..', '..');
@@ -32,7 +32,10 @@ function getAllPlugins() {
32
32
  } else {
33
33
  serviceSpecificPlugins = [];
34
34
  }
35
- return [...commonPlugins, ...serviceSpecificPlugins];
35
+ if (!Array.isArray(commonPlugins) || !Array.isArray(serviceSpecificPlugins)) {
36
+ Logger.log(Logger.FAILURE_TYPE, 'Plugin details should be in an array format in pluginVersion.js file');
37
+ }
38
+ return Object.assign([], commonPlugins, serviceSpecificPlugins);
36
39
  }
37
40
 
38
41
  /**
package/changeLog.md CHANGED
@@ -47,3 +47,7 @@
47
47
 
48
48
  1. ProjectId api revamp
49
49
  2. code standard analytics bin bind to code standard validator bin
50
+
51
+ # 1.1.5
52
+
53
+ 1. Refactor configuration loading and linting process, update mandatory rules handling, and improve pre-commit hook functionality
@@ -1,3 +1,3 @@
1
- const MandatoryListRules = ["@zohodesk/fitnessfunction/chunk-size"]
1
+ const MandatoryListRules = JSON.parse(process.env.MANDARORY_RULES || '[]')
2
2
 
3
3
  module.exports = MandatoryListRules
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "1.2.4-exp-2",
3
+ "version": "1.2.4-exp-4",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "type": "commonjs",
18
18
  "dependencies": {
19
19
  "@zohodesk-private/client_deployment_tool": "0.0.5",
20
- "@zohodesk/codestandard-analytics": "1.1.4-exp-2",
20
+ "@zohodesk/codestandard-analytics": "1.1.5",
21
21
  "@stryker-mutator/core": "5.0.0",
22
22
  "eslint": "8.26.0",
23
23
  "marked": "9.1.6",