@zohodesk/codestandard-validator 0.0.6-exp-7 → 0.0.6-exp-8

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