@zohodesk/codestandard-validator 0.0.6-exp-7 → 0.0.6-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.
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
3
  const {
8
4
  exec
9
5
  } = require('child_process');
@@ -40,208 +36,274 @@ const {
40
36
  } = getConfigurationPrecommit();
41
37
 
42
38
  /**
43
- * Checks if the current commit is a merge commit
44
- * @returns {Promise<boolean>} True if it's a merge commit
39
+ * @function isMergeCommit - This method check whether it is merge or not
40
+ * @returns {Boolean} - return boolean based on latest merge changes
45
41
  */
46
42
  async function isMergeCommit() {
47
- return new Promise(resolve => {
48
- exec('git rev-parse -q --verify MERGE_HEAD', error => {
49
- resolve(!error);
43
+ return new Promise((resolve, reject) => {
44
+ exec('git rev-parse -q --verify MERGE_HEAD', (error, stderr, stdout) => {
45
+ if (error) {
46
+ reject(error.toString().trim());
47
+ } else if (stderr) {
48
+ resolve(stderr.trim());
49
+ } else if (stdout) {
50
+ resolve(stdout.trim());
51
+ }
50
52
  });
51
53
  });
52
54
  }
53
55
 
54
56
  /**
55
- * Gets staged files while filtering out deleted files
56
- * @returns {Promise<string[]>} Array of staged file paths
57
+ * @function {getStagedFiles} - methods return staged files
58
+ * @returns {Array<string>} - array of files
57
59
  */
60
+
58
61
  async function getStagedFiles() {
59
62
  return new Promise((resolve, reject) => {
60
- exec('git diff --staged --name-only', (error, stdout) => {
63
+ exec("git diff --staged --name-only", (error, stderr, stdout) => {
61
64
  if (error) {
62
- return reject("Couldn't fetch staged files");
65
+ if (error != null) reject("Couldn't fetch staged files");
66
+ } else if (stderr) {
67
+ resolve(filterDeltedFileFromStagedFiles(stderr.trim().split('\n')));
68
+ } else if (stdout.trim() === '') {
69
+ resolve(stdout.trim());
63
70
  }
64
- const files = stdout.trim().split('\n').filter(Boolean);
65
- resolve(filterDeletedFiles(files));
66
71
  });
67
72
  });
68
73
  }
69
74
 
70
75
  /**
71
- * Filters out deleted files from the staged files list
72
- * @param {string[]} files - Array of file paths
73
- * @returns {string[]} Filtered array of existing files
76
+ * @function {filterDeltedFileFromStagedFiles} - filter deleted staged files
77
+ * @param {Array<string>} files - staged files
78
+ * @returns
74
79
  */
75
- function filterDeletedFiles(files) {
80
+ function filterDeltedFileFromStagedFiles(files) {
76
81
  return files.filter(file => {
77
82
  const absolutePath = path.resolve(getRootDirectory(), file);
78
- return fs.existsSync(absolutePath);
83
+ if (fs.existsSync(absolutePath)) {
84
+ return true;
85
+ }
86
+ return false;
79
87
  });
80
88
  }
81
89
 
82
90
  /**
83
- * Runs ESLint on a specific file
84
- * @param {string} file - File path to lint
85
- * @returns {Promise<string[]>} ESLint output lines
91
+ * @function findEslintErrors - method Lint given file based on given configuration
92
+ * @param {*} file - path of file to lint
93
+ * @returns {Array<string>} - array of command line report as a string
86
94
  */
87
- async function runEslintOnFile(file) {
88
- const nodeModulesPath = getNodeModulesPath();
89
- const eslintPath = getEslintExecutablePath();
90
- const configPath = `${nodeModulesPath}/.eslintrc.js`;
91
- if (!fs.existsSync(nodeModulesPath)) {
95
+
96
+ async function findEslintErrors(file) {
97
+ let nodeModulesPathOfProject = `${getNodeModulesPath()}`;
98
+ let eslintExecutablePath = getEslintExecutablePath();
99
+ let eslintConfigurationFilePath = `${nodeModulesPathOfProject}/.eslintrc.js`;
100
+ let isEslintExecutablePresent = fs.existsSync(eslintExecutablePath) ? true : false;
101
+ let isNodeModulesPresent = fs.existsSync(nodeModulesPathOfProject);
102
+ if (isNodeModulesPresent) {
103
+ if (isEslintExecutablePresent) {
104
+ return new Promise((resolve, reject) => {
105
+ exec(`npx --ignore-existing "${eslintExecutablePath}" --config "${eslintConfigurationFilePath}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPathOfProject}/node_modules" ${file}`, (error, stderr, stdout) => {
106
+ if (stderr) {
107
+ resolve(stderr.trim().split('\n'));
108
+ } else if (error) {
109
+ Logger.log(Logger.FAILURE_TYPE, error);
110
+ reject("Error executing eslint command");
111
+ } else {
112
+ resolve([]);
113
+ }
114
+ });
115
+ });
116
+ } else {
117
+ Logger.log(Logger.INFO_TYPE, 'Eslint executable not found. make sure eslint plugin is installed');
118
+ }
119
+ } else {
92
120
  Logger.log(Logger.INFO_TYPE, 'node_modules not found');
93
- return [];
94
- }
95
- if (!fs.existsSync(eslintPath)) {
96
- Logger.log(Logger.INFO_TYPE, 'Eslint executable not found');
97
- return [];
98
121
  }
99
- return new Promise(resolve => {
100
- const command = `npx --ignore-existing "${eslintPath}" --config "${configPath}" --no-inline-config --resolve-plugins-relative-to="${nodeModulesPath}/node_modules" ${file}`;
101
- exec(command, (error, stderr) => {
102
- if (stderr) {
103
- resolve(stderr.trim().split('\n'));
104
- } else {
105
- resolve([]);
106
- }
107
- });
108
- });
109
122
  }
110
-
111
123
  /**
112
- * Computes git diff for a file against current branch
113
- * @param {string} branch - Current branch name
114
- * @param {string} file - File path
115
- * @returns {Promise<string[]>} Git diff output lines
124
+ * @function {calculateGitDiffForFile} - method calculate diff of file
125
+ * @param {*} branch_name - branch name
126
+ * @param {*} file - path of file
127
+ * @returns {Promise<Array<string>>} - array of command line report as a string
116
128
  */
117
- async function getGitDiff(branch, file) {
129
+ async function calculateGitDiffForFile(branch_name, file) {
130
+ let gitDiffCommand = `git diff -U0 ${branch_name.trim()} ${file}`;
118
131
  return new Promise((resolve, reject) => {
119
- exec(`git diff -U0 ${branch.trim()} ${file}`, (error, stderr) => {
120
- if (error) return reject(error);
121
- resolve(stderr ? stderr.trim().split('\n') : []);
132
+ exec(gitDiffCommand, (error, stderr) => {
133
+ if (stderr) {
134
+ resolve(stderr.trim().split('\n'));
135
+ } else if (error) {
136
+ reject(error);
137
+ }
122
138
  });
123
139
  });
124
140
  }
125
-
126
141
  /**
127
- * Extracts changed line ranges from git diff output
128
- * @param {string[]} diffLines - Git diff output
129
- * @returns {Array<{start: number, end: number}>} Array of changed line ranges
142
+ * @function {areAllPluginsInstalled} - method whether plugin is installed or not
143
+ * @returns {Boolean} - return boolean based on plugin installed or not
130
144
  */
131
- function parseChangedLines(diffLines) {
132
- return diffLines.filter(line => line.startsWith('@@')).map(line => {
133
- const parts = line.split(' ')[2].split(',');
134
- const start = parseInt(parts[0]);
135
- const end = parts[1] ? start + parseInt(parts[1]) - 1 : start;
136
- return {
137
- start,
138
- end
139
- };
140
- });
145
+
146
+ function areAllPluginsInstalled() {
147
+ let unInstalledPlugins = checkIfPluginsAreInstalled().uninstalledPlugins;
148
+ return unInstalledPlugins.length === 0 ? true : false;
141
149
  }
142
150
 
143
151
  /**
144
- * Filters ESLint errors to only include those in changed lines
145
- * @param {string[]} eslintErrors - ESLint output lines
146
- * @param {Array<{start: number, end: number}>} changedRanges - Changed line ranges
147
- * @returns {string[]} Filtered ESLint errors
152
+ * @function {isOnlyWarningsPresentInFile} - method that checks if only eslint warnings are present in a file
153
+ * @returns {Boolean} - returns boolean based on only warnings present or not in file
148
154
  */
149
- function filterErrorsToChangedLines(eslintErrors, changedRanges) {
150
- return eslintErrors.filter(error => {
151
- const match = error.match(/^(\d+):/);
152
- if (!match) return false;
153
- const line = parseInt(match[1]);
154
- return changedRanges.some(({
155
- start,
156
- end
157
- }) => line >= start && line <= end);
155
+ function isOnlyWarningsPresentInFile(eslintErrorsPresent) {
156
+ let severityOfEachErrorInFile = [];
157
+ eslintErrorsPresent.map(error => {
158
+ let partsInString = error.split(" ");
159
+ let severityOfError = partsInString.find(word => word === 'error' || word === 'warning');
160
+ severityOfEachErrorInFile.push(severityOfError);
158
161
  });
162
+ return !severityOfEachErrorInFile.includes('error');
159
163
  }
160
164
 
161
165
  /**
162
- * Checks if ESLint output contains only warnings
163
- * @param {string[]} eslintErrors - ESLint output lines
164
- * @returns {boolean} True if only warnings are present
166
+ * @function {preCommitHook} - method execute pre commit hook
167
+ * @returns {void}
165
168
  */
166
- function hasOnlyWarnings(eslintErrors) {
167
- return eslintErrors.every(error => error.includes('warning'));
168
- }
169
169
 
170
- /**
171
- * Processes a file based on impact-based precommit configuration
172
- * @param {string} file - File path to process
173
- * @param {string} branch - Current branch name
174
- * @returns {Promise<boolean>} True if errors should abort commit
175
- */
176
- async function processFile(file, branch) {
177
- if (!getSupportedLanguage().includes(path.extname(file))) return false;
170
+ async function preCommitHook() {
171
+ Logger.log(Logger.INFO_TYPE, 'Executing pre commit hook...');
172
+ Logger.log(Logger.INFO_TYPE, `working dir : ${process.cwd()}`);
178
173
  try {
179
- const eslintOutput = await runEslintOnFile(file);
180
- if (eslintOutput.length < 3) return false; // No meaningful errors
174
+ let isMerge = await isMergeCommit();
175
+ Logger.log(Logger.INFO_TYPE, 'Looks like you have merged. So skipping pre commit check');
176
+ process.exit(0);
177
+ } catch (error) {
178
+ if (areAllPluginsInstalled()) {
179
+ let staged_files = [];
180
+ let eslintConfigFiles = ['.eslintrc.js'];
181
+ let exemptionFiles = [];
182
+ let current_branch = '';
183
+ let hasEslintErrorsInChangedLines = false;
184
+ let hasEslintErrorsInFiles = false;
185
+ let areFilesStaged = false;
186
+ let shouldAbortCommit = false;
187
+ try {
188
+ current_branch = await getBranchName();
189
+ } catch {
190
+ Logger.log(Logger.INFO_TYPE, "Error fetching current branch");
191
+ }
192
+ try {
193
+ staged_files = await getStagedFiles();
194
+ if (!staged_files.length == 0) {
195
+ staged_files = filterFiles(staged_files, eslintConfigFiles, true);
196
+
197
+ // staged_files = filterFiles(staged_files,exemptionFiles) //this is the code for giving exemption to a file during pre commit
198
+ // if(staged_files.length === 0){
199
+ // Logger.log(Logger.SUCCESS_TYPE,`Commit Successful`)
200
+ // process.exit(0)
201
+ // }
202
+ areFilesStaged = true;
203
+ for (let file in staged_files) {
204
+ let currentFileName = staged_files[file];
205
+ let changedLinesArray = [];
206
+ let eslintErrorsInChangedLines = [];
207
+ let isOnlyEslintWarningsPresentInFile = false;
208
+ if (getSupportedLanguage().includes(path.extname(staged_files[file]))) {
209
+ try {
210
+ var eslintErrorsInFile = await findEslintErrors(staged_files[file]);
211
+ // eslintErrorsInFile = impactBasedPrecommit == false ? filterWarningInFile(eslintErrorsInFile) : eslintErrorsInFile
212
+ if (staged_files[file] && typeof staged_files[file] == 'string') {
213
+ if (!eslintErrorsInFile.length == 0) {
214
+ //Calculating changed lines in a file and storing them in respective arrays
215
+ if (impactBasedPrecommit) {
216
+ //git diff is computed and stored in an array
217
+ let git_diff = await calculateGitDiffForFile(current_branch, staged_files[file]);
218
+ changedLinesArray = git_diff.filter(line => line.startsWith('@@'));
219
+ let changedLinesStartArray = [];
220
+ let changedLinesEndArray = [];
221
+ for (let number of changedLinesArray) {
222
+ let changesStartLine = parseInt(number.split(' ')[2].split(',')[0]);
223
+ changedLinesStartArray.push(changesStartLine);
224
+ let changesEndLine = number.split(' ')[2].split(',')[1];
225
+ if (changesEndLine === undefined) {
226
+ changedLinesEndArray.push(changesStartLine);
227
+ } else {
228
+ changedLinesEndArray.push(changesStartLine + parseInt(changesEndLine) - 1);
229
+ }
230
+ }
231
+ for (let error = 1; error < eslintErrorsInFile.length - 2; error++) {
232
+ //eslintErrorsInFile[error].trim() - 69:26 error => Do not hardcode content. Use I18N key instead no-hardcoding/no-hardcoding,
233
+ //eslintErrorsInFile[error].trim().split(' ')[0] => 69:26
234
+ //eslintErrorsInFile[error].trim().split(' ')[0].split(':')[0] => 69
181
235
 
182
- const errors = eslintOutput.slice(1, -2);
183
- if (!impactBasedPrecommit) {
184
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${file}\x1b[0m`);
185
- errors.forEach(err => Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${err.trimEnd()}\x1b[0m`));
186
- if (!shouldWarningsAbortCommit && hasOnlyWarnings(errors)) {
187
- return false;
236
+ let eslintErrorLineNumber = eslintErrorsInFile[error].trim().split(' ')[0].split(':')[0];
237
+ for (let lineNumber in changedLinesStartArray) {
238
+ if (eslintErrorLineNumber >= changedLinesStartArray[lineNumber] && eslintErrorLineNumber <= changedLinesEndArray[lineNumber]) {
239
+ eslintErrorsInChangedLines.push(eslintErrorsInFile[error]);
240
+ }
241
+ }
242
+ }
243
+ if (eslintErrorsInChangedLines.length > 0) {
244
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(eslintErrorsInChangedLines);
245
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
246
+ for (let eslintError of eslintErrorsInChangedLines) {
247
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
248
+ }
249
+ if (shouldWarningsAbortCommit) {
250
+ hasEslintErrorsInChangedLines = true;
251
+ shouldAbortCommit = true;
252
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
253
+ hasEslintErrorsInChangedLines = false;
254
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
255
+ hasEslintErrorsInChangedLines = true;
256
+ shouldAbortCommit = true;
257
+ }
258
+ }
259
+ } else {
260
+ if (eslintErrorsInFile.length > 0) {
261
+ let startIndex = 1;
262
+ let endIndex = eslintErrorsInFile.length - 2;
263
+ let listOsEslintErrors = eslintErrorsInFile.slice(startIndex, endIndex);
264
+ isOnlyEslintWarningsPresentInFile = isOnlyWarningsPresentInFile(listOsEslintErrors);
265
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${currentFileName}\x1b[0m`);
266
+ for (let eslintError of listOsEslintErrors) {
267
+ Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${eslintError.trimEnd()}\x1b[0m`);
268
+ }
269
+ if (shouldWarningsAbortCommit) {
270
+ hasEslintErrorsInFiles = true;
271
+ shouldAbortCommit = true;
272
+ } else if (!shouldWarningsAbortCommit && isOnlyEslintWarningsPresentInFile) {
273
+ hasEslintErrorsInFiles = false;
274
+ } else if (!shouldWarningsAbortCommit && !isOnlyEslintWarningsPresentInFile) {
275
+ hasEslintErrorsInFiles = true;
276
+ shouldAbortCommit = true;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+ } catch (err) {
283
+ Logger.log(Logger.FAILURE_TYPE, err);
284
+ Logger.log(Logger.FAILURE_TYPE, "Error in executing eslint command");
285
+ }
286
+ }
287
+ }
288
+ } else if (staged_files.length === 0) {
289
+ Logger.log(Logger.INFO_TYPE, 'No files have been staged. Stage your files before committing');
290
+ }
291
+ } catch {
292
+ Logger.log(Logger.INFO_TYPE, 'Error executing pre commit hook');
188
293
  }
189
- return true;
190
- }
191
- const diffOutput = await getGitDiff(branch, file);
192
- const changedRanges = parseChangedLines(diffOutput);
193
- const changedLineErrors = filterErrorsToChangedLines(errors, changedRanges);
194
- if (changedLineErrors.length > 0) {
195
- Logger.log(Logger.FAILURE_TYPE, `\x1b[1m${file}\x1b[0m`);
196
- changedLineErrors.forEach(err => Logger.log(Logger.FAILURE_TYPE, `\x1b[37m${err.trimEnd()}\x1b[0m`));
197
- if (!shouldWarningsAbortCommit && hasOnlyWarnings(changedLineErrors)) {
198
- return false;
294
+ if (shouldAbortCommit) {
295
+ Logger.log(Logger.FAILURE_TYPE, `There are eslint errors/warnings present. So commit is aborted.`);
296
+ process.exit(1);
297
+ } else if (shouldAbortCommit === false && staged_files.length !== 0) {
298
+ Logger.log(Logger.SUCCESS_TYPE, `Commit Successful`);
299
+ process.exit(0);
199
300
  }
200
- return true;
201
- }
202
- } catch (error) {
203
- Logger.log(Logger.FAILURE_TYPE, `Error processing ${file}: ${error}`);
204
- }
205
- return false;
206
- }
207
-
208
- /**
209
- * Main pre-push hook execution logic
210
- */
211
- async function preCommitCheck() {
212
- Logger.log(Logger.INFO_TYPE, 'Executing pre commit hook...');
213
- if (await isMergeCommit()) {
214
- Logger.log(Logger.INFO_TYPE, 'Merge commit detected. Skipping checks.');
215
- process.exit(0);
216
- }
217
- const pluginsStatus = checkIfPluginsAreInstalled();
218
- if (pluginsStatus.uninstalledPlugins.length > 0) {
219
- Logger.log(Logger.FAILURE_TYPE, 'Commit failed: Required plugins missing');
220
- Logger.log(Logger.INFO_TYPE, 'Run: npx ZDPrecommit setupPlugins');
221
- process.exit(1);
222
- }
223
- try {
224
- const stagedFiles = await getStagedFiles();
225
- if (stagedFiles.length === 0) {
226
- Logger.log(Logger.INFO_TYPE, 'No staged files found');
227
- process.exit(0);
228
- }
229
- const filteredFiles = filterFiles(stagedFiles, ['.eslintrc.js'], true);
230
- const currentBranch = await getBranchName();
231
- let shouldAbort = false;
232
- for (const file of filteredFiles) {
233
- const fileShouldAbort = await processFile(file, currentBranch);
234
- if (fileShouldAbort) shouldAbort = true;
235
- }
236
- if (shouldAbort) {
237
- Logger.log(Logger.FAILURE_TYPE, 'Commit aborted due to ESLint issues');
301
+ } else {
302
+ Logger.log(Logger.FAILURE_TYPE, 'Commit failed since some eslint plugins are not installed');
303
+ 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`);
304
+ Logger.log(Logger.INFO_TYPE, 'Execute the command and kindly try committing again.');
238
305
  process.exit(1);
239
306
  }
240
- Logger.log(Logger.SUCCESS_TYPE, 'Commit successful');
241
- process.exit(0);
242
- } catch (error) {
243
- Logger.log(Logger.FAILURE_TYPE, `Pre-commit hook failed: ${error}`);
244
- process.exit(1);
245
307
  }
246
308
  }
247
- var _default = exports.default = preCommitCheck;
309
+ preCommitHook();
@@ -19,9 +19,6 @@ const {
19
19
  const {
20
20
  arePluginsInstalled
21
21
  } = require("../../utils/PluginsInstallation/arePluginsInstalled");
22
- const {
23
- default: preCommitCheck
24
- } = require("./lint");
25
22
  async function validateRemotePackages() {
26
23
  try {
27
24
  if (!(getStoredCommitHash() == getLastCommitHash())) {
@@ -36,5 +33,5 @@ async function validateRemotePackages() {
36
33
  }
37
34
  (async function () {
38
35
  await validateRemotePackages();
39
- await preCommitCheck();
36
+ require('./lint');
40
37
  })();
@@ -16,14 +16,13 @@ const {
16
16
  function createVersionControlFile(uninstalledPlugins) {
17
17
  Logger.log(Logger.INFO_TYPE, `Rule Plugin Versions are Noted in pluginVersionControl.js`);
18
18
  const versionfilePath = path.join(getNodeModulesPath(), 'node_modules', '@zohodesk', 'codestandard-validator', 'pluginVersionControl.js');
19
- if (existsSync(versionfilePath)) {
20
- writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
21
- return JSON.stringify({
22
- plugin: `${plugin}`,
23
- time: `${new Date()}`
24
- });
25
- }).join(',')}]`);
26
- }
19
+ existsSync(versionfilePath) && writeFileSync(versionfilePath, '');
20
+ writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
21
+ return JSON.stringify({
22
+ plugin: `${plugin}`,
23
+ time: `${new Date()}`
24
+ });
25
+ }).join(',')}]`);
27
26
  }
28
27
  module.exports = {
29
28
  createVersionControlFile
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  const {
4
- readdirSync,
5
4
  existsSync
6
5
  } = require('fs');
7
6
  const path = require('path');
8
- const {
9
- getNodeModulesPath
10
- } = require('../General/getNodeModulesPath');
11
7
  const {
12
8
  Logger
13
9
  } = require('../Logger/Logger');
14
10
  const {
15
11
  getLibraryInstalledLocation
16
12
  } = require('../General/getLibraryInstalledLocation');
17
- const {
18
- executeSynchronizedCommands
19
- } = require('../General/executeSyncCommands');
20
13
  const {
21
14
  endPoint,
22
15
  commonLinterRepoName
@@ -27,32 +20,6 @@ const {
27
20
  const {
28
21
  getServicePathElseCommon
29
22
  } = require('../EslintConfigFileUtils/getLintConfiguration');
30
- function getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, devDependencies) {
31
- let pluginsInNodeModules = executeSynchronizedCommands(readdirSync, [path.join(getNodeModulesPath(), 'node_modules')], '', 'Unable to get the plugins inside node_modules', true, false);
32
- let pluginsToBeInstalled = [];
33
- pluginsForCurrentRepo.filter(plugin => {
34
- if (plugin.packageName.startsWith('@')) {
35
- let scope = plugin.packageName.split('/')[0];
36
- let pluginName = plugin.packageName.split('/')[1];
37
- let scopedPlugins = executeSynchronizedCommands(readdirSync, [path.join(getNodeModulesPath(), 'node_modules', scope)], '', 'Unable to get the plugins inside the scope inside node_modules', true, false);
38
- let isPluginInstalled = scopedPlugins.includes(pluginName) ? true : false;
39
- if (!isPluginInstalled) {
40
- pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
41
- }
42
- } else {
43
- let isPluginInstalled = pluginsInNodeModules.includes(plugin.packageName) ? true : false;
44
- if (!isPluginInstalled) {
45
- pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
46
- }
47
- }
48
- if (pluginNamesOfDevDependencyPlugins.includes(plugin.packageName)) {
49
- if (plugin.version !== devDependencies[plugin.packageName]) {
50
- pluginsToBeInstalled.push(`${plugin.packageName}@${plugin.version}`);
51
- }
52
- }
53
- });
54
- return pluginsToBeInstalled;
55
- }
56
23
  function getAllPlugins() {
57
24
  let serviceSpecificPlugins = [];
58
25
  const pathToCommonPluginsFile = path.join(getLibraryInstalledLocation(), commonLinterRepoName, 'common', 'pluginVersion.js');
@@ -79,29 +46,6 @@ function checkIfPluginsAreInstalled() {
79
46
  noPluginMessage: '',
80
47
  uninstalledPlugins: []
81
48
  };
82
- // let pluginsIndevDependencies = {}
83
- // let pluginNamesOfDevDependencyPlugins = []
84
- // let arePluginsPresentIndevDependencies = false
85
- // var arePluginsPresentForCurrentRepo = false
86
-
87
- // if(existsSync(path.join(getNodeModulesPath(),'package.json'))){
88
- // let packageJsonContent = require(path.join(getNodeModulesPath(),'package.json'))
89
- // pluginsIndevDependencies = packageJsonContent.devDependencies
90
-
91
- // if(pluginsIndevDependencies !== undefined){
92
- // arePluginsPresentIndevDependencies = true
93
- // pluginNamesOfDevDependencyPlugins = Object.keys(pluginsIndevDependencies)
94
- // }
95
- // else if(pluginsIndevDependencies === undefined){
96
- // Logger.log(Logger.INFO_TYPE,'No devDependencies present!')
97
- // }
98
- // }
99
- // else{
100
- // arePluginsPresentIndevDependencies = false
101
- // }
102
-
103
- // arePluginsPresentForCurrentRepo = pluginsForCurrentRepo.length !== 0 ? true : false
104
-
105
49
  uninstalledPlugins = pluginsForCurrentRepo.map(plugin => {
106
50
  const {
107
51
  packageName,
@@ -117,7 +61,6 @@ function checkIfPluginsAreInstalled() {
117
61
  return `${packageName}@${version}`;
118
62
  }).filter(Boolean);
119
63
  if (uninstalledPlugins.length > 0) {
120
- // uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
121
64
  plugin.noPluginMessage = '';
122
65
  plugin.uninstalledPlugins = uninstalledPlugins;
123
66
  return plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "0.0.6-exp-7",
3
+ "version": "0.0.6-exp-9",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {