@zohodesk/codestandard-validator 0.0.0-exp-1

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.
Files changed (54) hide show
  1. package/.babelrc +19 -0
  2. package/README.md +3 -0
  3. package/bin/cli.js +3 -0
  4. package/bin/execute.js +3 -0
  5. package/bin/postinstall.js +3 -0
  6. package/build/grafana-config/grafana-config.js +16 -0
  7. package/build/grafana-config/grfanaAPI.js +72 -0
  8. package/build/hooks/Precommit/filterUtils.js +42 -0
  9. package/build/hooks/Precommit/pre-commit.js +235 -0
  10. package/build/lib/cli.js +47 -0
  11. package/build/lib/postinstall.js +44 -0
  12. package/build/setup/initialSetup.js +60 -0
  13. package/build/utils/CloneCommonLinterRepo/HelperFunctions/helpers.js +16 -0
  14. package/build/utils/CloneCommonLinterRepo/cloneViaCdt.js +41 -0
  15. package/build/utils/EslintConfigFileUtils/createEslintConfigFile.js +54 -0
  16. package/build/utils/EslintConfigFileUtils/getEslintExecutablePath.js +24 -0
  17. package/build/utils/EslintConfigFileUtils/getLintConfiguration.js +52 -0
  18. package/build/utils/ExtensionInstallation/installEslintExtension.js +25 -0
  19. package/build/utils/FileAndFolderOperations/deleteFile.js +28 -0
  20. package/build/utils/FileAndFolderOperations/filterFiles.js +41 -0
  21. package/build/utils/FileAndFolderOperations/getFileContent.js +23 -0
  22. package/build/utils/FileAndFolderOperations/grantExecutionPermission.js +35 -0
  23. package/build/utils/FileAndFolderOperations/removeFolder.js +37 -0
  24. package/build/utils/General/RootDirectoryUtils/getRootDirectory.js +23 -0
  25. package/build/utils/General/RootDirectoryUtils/navigateToRootDirectory.js +25 -0
  26. package/build/utils/General/executeSyncCommands.js +40 -0
  27. package/build/utils/General/getGeneralInfo.js +31 -0
  28. package/build/utils/General/getLibraryInstalledLocation.js +18 -0
  29. package/build/utils/General/getNodeModulesPath.js +14 -0
  30. package/build/utils/General/wrapperFunctionToExecuteAFunction.js +39 -0
  31. package/build/utils/General/writeProjectDetailsToJson.js +18 -0
  32. package/build/utils/GitActions/gitActions.js +88 -0
  33. package/build/utils/HuskySetup/configurePrecommitHook.js +39 -0
  34. package/build/utils/HuskySetup/initializeHusky.js +35 -0
  35. package/build/utils/HuskySetup/setupHusky.js +76 -0
  36. package/build/utils/Logger/Logger.js +26 -0
  37. package/build/utils/PluginsInstallation/arePluginsInstalled.js +15 -0
  38. package/build/utils/PluginsInstallation/checkIfPluginsAreInstalled.js +112 -0
  39. package/build/utils/PluginsInstallation/installPlugins.js +91 -0
  40. package/build/utils/PluginsInstallation/printUninstalledPlugins.js +27 -0
  41. package/build/utils/PrecommitUsingGitSetup/update-git-precommithook.js +37 -0
  42. package/changeLog.md +7 -0
  43. package/configuration/common/.eslintrc.js +18 -0
  44. package/configuration/common/index.js +9 -0
  45. package/configuration/common/pluginVersion.js +7 -0
  46. package/configuration/common/rule_configuration/configurations.js +9 -0
  47. package/configuration/services/desk_client_app/.eslintrc.js +18 -0
  48. package/configuration/services/desk_client_app/index.js +16 -0
  49. package/configuration/services/desk_client_app/pluginVersion.js +17 -0
  50. package/configuration/services/desk_client_app/rule_configuration/architectureRules/bestPracticeRules.js +9 -0
  51. package/configuration/services/desk_client_app/rule_configuration/i18nRules/noHardcodingRuleExcludes.js +32 -0
  52. package/index.js +8 -0
  53. package/jsonUtils/commonLinterRepoDetails.js +17 -0
  54. package/package.json +27 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ /* eslint-disable no-console */
4
+ const {
5
+ execSync
6
+ } = require('child_process');
7
+ const {
8
+ readdirSync
9
+ } = require('fs');
10
+ const path = require('path');
11
+ const initializeHusky = require('./initializeHusky');
12
+ const configurePrecommitHook = require('./configurePrecommitHook');
13
+ const {
14
+ getNodeModulesPath
15
+ } = require('../General/getNodeModulesPath');
16
+ const {
17
+ executeSynchronizedCommands
18
+ } = require('../General/executeSyncCommands');
19
+ const {
20
+ Logger
21
+ } = require('../Logger/Logger');
22
+ let isCustomPrecommitConfigurationSuccessful = false;
23
+
24
+ /**
25
+ * @function setupHusky - to setup custom precommit hook using husky plugin
26
+ * @returns {boolean} - indicating whether entire custom precommit hook setup using husky process is success or failure
27
+ */
28
+ function setupHusky() {
29
+ let isHuskyPackageInstalled = installHuskyPackage();
30
+ if (isHuskyPackageInstalled) {
31
+ let isHuskyInitializedSuccessfully = initializeHusky();
32
+ if (isHuskyInitializedSuccessfully) {
33
+ Logger.log(Logger.SUCCESS_TYPE, 'Husky installation successful');
34
+ isCustomPrecommitConfigurationSuccessful = configurePrecommitHook();
35
+ if (isCustomPrecommitConfigurationSuccessful) {
36
+ Logger.log(Logger.SUCCESS_TYPE, 'Custom pre commit hook setup was successful');
37
+ return true;
38
+ } else {
39
+ Logger.log(Logger.FAILURE_TYPE, 'Couldn\'t configure custom pre commit hook');
40
+ return false;
41
+ }
42
+ } else {
43
+ return false;
44
+ }
45
+ } else {
46
+ Logger.log(Logger.FAILURE_TYPE, 'Some issue in installing husky package.');
47
+ return false;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * @function installHuskyPackage - installs husky package if not installed for the project
53
+ * @returns {boolean} - indicating if husky package installed successfully or not
54
+ */
55
+ function installHuskyPackage() {
56
+ const nodeModulesPathOfProject = path.join(getNodeModulesPath(), 'node_modules');
57
+ let pluginsInNodeModules = executeSynchronizedCommands(readdirSync, [nodeModulesPathOfProject], '', 'Unable to get directories in node_modules when checking if husky is installed', true, false);
58
+ let husky = {
59
+ packageName: 'husky',
60
+ version: '^7.0.4'
61
+ };
62
+ let isHuskyInstalled = pluginsInNodeModules.includes(husky.packageName) ? true : false;
63
+ if (!isHuskyInstalled) {
64
+ Logger.log(Logger.INFO_TYPE, 'Installing husky package ....');
65
+ let installCommand = `npm install ${husky.packageName}@${husky.version} --save-dev`;
66
+ let isHuskyPackageInstalled = executeSynchronizedCommands(execSync, [installCommand, {
67
+ stdio: 'inherit'
68
+ }], 'Husky package Installed Successfully', 'Unable to install husky package', false, true);
69
+ return isHuskyPackageInstalled;
70
+ }
71
+ Logger.log(Logger.SUCCESS_TYPE, 'Husky package already installed!');
72
+ return true;
73
+ }
74
+ module.exports = {
75
+ setupHusky
76
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ class LoggerImpl {
4
+ constructor() {
5
+ this.SUCCESS_TYPE = "success";
6
+ this.FAILURE_TYPE = "failure";
7
+ this.INFO_TYPE = "info";
8
+ this.colors = {
9
+ success: ["\x1b[36m", "\x1b[0m"],
10
+ failure: ["\x1b[31m", "\x1b[0m"],
11
+ info: ["\x1b[33m", "\x1b[0m"]
12
+ };
13
+ this.consoleLogger = console;
14
+ }
15
+ error(err) {
16
+ this.consoleLogger.error(err);
17
+ }
18
+ catchInfo(InfoMessage) {
19
+ precommit_log.set(timeStamp, InfoMessage);
20
+ }
21
+ log(type, message) {
22
+ const color = this.colors[type];
23
+ this.consoleLogger.log(`${color[0]}${message}${color[1]}`);
24
+ }
25
+ }
26
+ module.exports.Logger = new LoggerImpl();
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ const {
4
+ checkIfPluginsAreInstalled
5
+ } = require('./checkIfPluginsAreInstalled');
6
+ const {
7
+ printUninstalledPlugins
8
+ } = require('./printUninstalledPlugins');
9
+ function arePluginsInstalled() {
10
+ let uninstalledPlugins = checkIfPluginsAreInstalled();
11
+ printUninstalledPlugins(uninstalledPlugins);
12
+ }
13
+ module.exports = {
14
+ arePluginsInstalled
15
+ };
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ const {
4
+ readdirSync,
5
+ existsSync
6
+ } = require('fs');
7
+ const path = require('path');
8
+ const {
9
+ getNodeModulesPath
10
+ } = require('../General/getNodeModulesPath');
11
+ const {
12
+ Logger
13
+ } = require('../Logger/Logger');
14
+ const {
15
+ getLibraryInstalledLocation
16
+ } = require('../General/getLibraryInstalledLocation');
17
+ const {
18
+ executeSynchronizedCommands
19
+ } = require('../General/executeSyncCommands');
20
+ const {
21
+ endPoint,
22
+ commonLinterRepoName
23
+ } = require('../../../jsonUtils/commonLinterRepoDetails');
24
+ const {
25
+ executeMethodsThatMayThrowException
26
+ } = require('../General/wrapperFunctionToExecuteAFunction');
27
+ const {
28
+ getServicePathElseCommon
29
+ } = 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
+ function getAllPlugins() {
57
+ let serviceSpecificPlugins = [];
58
+ const pathToCommonPluginsFile = path.join(getLibraryInstalledLocation(), commonLinterRepoName, 'common', 'pluginVersion.js');
59
+ let commonPlugins = executeMethodsThatMayThrowException([], 'Make sure there is a pluginVersion.js file in common folder under configuration folder', require, pathToCommonPluginsFile);
60
+ const {
61
+ pluginVersionPath: serviceSpecificPluginsFile
62
+ } = getServicePathElseCommon();
63
+ if (serviceSpecificPluginsFile !== undefined) {
64
+ serviceSpecificPlugins = executeMethodsThatMayThrowException([], `Kindly Ensure that Configuration is setup in Configuration repo \n ${endPoint}`, require, serviceSpecificPluginsFile);
65
+ } else {
66
+ serviceSpecificPlugins = [];
67
+ }
68
+ return [...commonPlugins, ...serviceSpecificPlugins];
69
+ }
70
+
71
+ /**
72
+ * @function checkIfPluginsAreInstalled - to check if all plugins present in the common linter_configuration repository has been installed or not
73
+ * @returns {Object} - contains two properties namely a string which says no plugins present for the repository or an empty string and an array containing plugins to be installed
74
+ */
75
+ function checkIfPluginsAreInstalled() {
76
+ const pluginsForCurrentRepo = getAllPlugins();
77
+ let uninstalledPlugins = [];
78
+ let plugin = {
79
+ noPluginMessage: '',
80
+ uninstalledPlugins: []
81
+ };
82
+ let pluginsIndevDependencies = {};
83
+ let pluginNamesOfDevDependencyPlugins = [];
84
+ let arePluginsPresentIndevDependencies = false;
85
+ let arePluginsPresentForCurrentRepo = false;
86
+ if (existsSync(path.join(getNodeModulesPath(), 'package.json'))) {
87
+ let packageJsonContent = require(path.join(getNodeModulesPath(), 'package.json'));
88
+ pluginsIndevDependencies = packageJsonContent.devDependencies;
89
+ if (pluginsIndevDependencies !== undefined) {
90
+ arePluginsPresentIndevDependencies = true;
91
+ pluginNamesOfDevDependencyPlugins = Object.keys(pluginsIndevDependencies);
92
+ } else if (pluginsIndevDependencies === undefined) {
93
+ Logger.log(Logger.INFO_TYPE, 'No devDependencies present!');
94
+ }
95
+ } else {
96
+ arePluginsPresentIndevDependencies = false;
97
+ }
98
+ arePluginsPresentForCurrentRepo = pluginsForCurrentRepo.length !== 0 ? true : false;
99
+ if (arePluginsPresentForCurrentRepo || arePluginsPresentIndevDependencies) {
100
+ uninstalledPlugins = getUnInstalledPlugins(pluginsForCurrentRepo, pluginNamesOfDevDependencyPlugins, pluginsIndevDependencies);
101
+ plugin.noPluginMessage = '';
102
+ plugin.uninstalledPlugins = uninstalledPlugins;
103
+ return plugin;
104
+ } else {
105
+ plugin.noPluginMessage = 'No plugins present for the repository';
106
+ plugin.uninstalledPlugins = [];
107
+ return plugin;
108
+ }
109
+ }
110
+ module.exports = {
111
+ checkIfPluginsAreInstalled
112
+ };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ const {
4
+ execSync
5
+ } = require('child_process');
6
+ const {
7
+ checkIfPluginsAreInstalled
8
+ } = require('./checkIfPluginsAreInstalled');
9
+ const {
10
+ executeSynchronizedCommands
11
+ } = require('../General/executeSyncCommands');
12
+ const {
13
+ Logger
14
+ } = require('../Logger/Logger');
15
+
16
+ /**
17
+ * @function installPlugins - installs uninstalled plugins for the project
18
+ * @returns {boolean} - indicating if plugins to be installed are installed successfully or not
19
+ */
20
+ function installPlugins() {
21
+ let uninstalledPlugins = checkIfPluginsAreInstalled();
22
+ let pluginsToBeInstalled = uninstalledPlugins.uninstalledPlugins;
23
+ if (pluginsToBeInstalled.length > 0) {
24
+ let installCommand = `npm install --save-dev ${pluginsToBeInstalled.join(' ')}`;
25
+ Logger.log(Logger.INFO_TYPE, 'Installing plugins ....');
26
+ Logger.log(Logger.INFO_TYPE, `Install command being executed: ${installCommand}`);
27
+ let arePluginsInstalledSuccessfully = executeSynchronizedCommands(execSync, [installCommand, {
28
+ stdio: 'inherit'
29
+ }], '', 'Some issue occured while installing plugins', false, true);
30
+ if (arePluginsInstalledSuccessfully) {
31
+ Logger.log(Logger.SUCCESS_TYPE, 'Plugins installation successful');
32
+ return true;
33
+ } else {
34
+ Logger.log(Logger.FAILURE_TYPE, "Unable to install plugins.Kindly retry the command");
35
+ return false;
36
+ }
37
+ } else {
38
+ Logger.log(Logger.INFO_TYPE, 'Plugins are already installed');
39
+ return true;
40
+ }
41
+ }
42
+
43
+ // function appendInstalledPluginsToPackageJson(pluginsToBeAppendedInPackageJson){
44
+ // let packageJsonFilePath = `${nodeModulesPathOfProject}/package.json`
45
+ // let packageJsonContent = require(packageJsonFilePath)
46
+ // let devDependencies = packageJsonContent.devDependencies
47
+ // let pluginsToBeAddedInDevDependencies = {}
48
+
49
+ // executeSynchronizedCommands(process.chdir,[nodeModulesPathOfProject],'','Unable to navigate to node_modules path when trying to revert changes in package.json',false,false)
50
+
51
+ // let gitDiffOutput = executeSynchronizedCommands(execSync,['git diff --name-only'],'','Unable to execute git diff command while checking if package.json is changed',true,false).toString().trim()
52
+ // let isPackageJsonChanged = gitDiffOutput.includes('package.json') ? true : false
53
+
54
+ // if(isPackageJsonChanged){
55
+ // let packageJsonChangesRevertCommand = `git checkout "${packageJsonFilePath}"`
56
+ // isPackageJsonChangesRevertedSuccessfully = executeSynchronizedCommands(execSync,[packageJsonChangesRevertCommand,{stdio:'inherit'}],'Changes in package.json reverted successfully','Unable to revert the changes in package.json file',false,true)
57
+
58
+ // if(isPackageJsonChangesRevertedSuccessfully){
59
+ // pluginsToBeAppendedInPackageJson.map(uninstalledPlugin => {
60
+ // if(uninstalledPlugin.startsWith('@')){
61
+ // let indexOfAtCharacter = uninstalledPlugin.indexOf('@')
62
+ // let indexOfSecondOccurenceOfAtCharacter = uninstalledPlugin.indexOf('@',indexOfAtCharacter + 1)
63
+ // let unInstalledPluginName = uninstalledPlugin.slice(0,indexOfSecondOccurenceOfAtCharacter)
64
+ // let unInstalledPluginVersion = uninstalledPlugin.slice(indexOfSecondOccurenceOfAtCharacter + 1)
65
+ // pluginsToBeAddedInDevDependencies[unInstalledPluginName] = unInstalledPluginVersion
66
+ // }
67
+ // else{
68
+ // pluginsToBeAddedInDevDependencies[uninstalledPlugin.split('@')[0]] = uninstalledPlugin.split('@')[1]
69
+ // }
70
+ // })
71
+ // let updatedPluginsIndevDependencies = {
72
+ // ...devDependencies,
73
+ // ...pluginsToBeAddedInDevDependencies
74
+ // }
75
+ // packageJsonContent.devDependencies = updatedPluginsIndevDependencies
76
+
77
+ // let modifiedPackageJson = {
78
+ // ...packageJsonContent,
79
+ // }
80
+ // let isPluginsAddedInPackageJson = executeSynchronizedCommands(writeFileSync,[packageJsonFilePath,JSON.stringify(modifiedPackageJson,null,2)],'Newly installed plugins successfully added to package.json','Unable to append installed plugins to package.json',false,true)
81
+ // return isPluginsAddedInPackageJson
82
+ // }
83
+ // else{
84
+ // return true
85
+ // }
86
+ // }
87
+ // }
88
+
89
+ module.exports = {
90
+ installPlugins
91
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ const {
4
+ Logger
5
+ } = require("../Logger/Logger");
6
+
7
+ /**
8
+ * @function printUninstalledPlugins - to notify the user regarding plugins for the repository has been installed or not
9
+ * @param {Array} uninstalledPlugins - contains list of uninstalled plugins for the project
10
+ */
11
+ function printUninstalledPlugins(uninstalledPlugins) {
12
+ let commandToInstallPlugins = 'npx ZDPrecommit setupPlugins';
13
+ if (uninstalledPlugins.uninstalledPlugins.length !== 0) {
14
+ Logger.log(Logger.INFO_TYPE, 'The following plugins are not installed:');
15
+ uninstalledPlugins.uninstalledPlugins.map(plugin => {
16
+ Logger.log(Logger.INFO_TYPE, `"${plugin}"`);
17
+ });
18
+ Logger.log(Logger.FAILURE_TYPE, `Kindly execute the command \x1b[37m"${commandToInstallPlugins}\x1b[0m" \x1b[31mfrom the location where package.json of the repo is present to install the plugins`);
19
+ } else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() === '') {
20
+ Logger.log(Logger.INFO_TYPE, 'Plugins are installed already');
21
+ } else if (uninstalledPlugins.uninstalledPlugins.length === 0 && uninstalledPlugins.noPluginMessage.trim() !== '') {
22
+ Logger.log(Logger.INFO_TYPE, 'No plugins present for the repository');
23
+ }
24
+ }
25
+ module.exports = {
26
+ printUninstalledPlugins
27
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ const {
4
+ existsSync
5
+ } = require("fs");
6
+ const {
7
+ getRootDirectory
8
+ } = require('../General/RootDirectoryUtils/getRootDirectory');
9
+ const {
10
+ getNodeModulesPath
11
+ } = require('../General/getNodeModulesPath');
12
+ const path = require('path');
13
+ const fs = require('fs');
14
+ function getCustomPrecommitHookPath() {
15
+ return path.resolve(getNodeModulesPath(), "node_modules", "@zohodesk", "codestandard-validator", "bin", "execute.js");
16
+ }
17
+
18
+ /**
19
+ * @function updateGitFile - updates default precommit hook provided by git with the custom precommit hook file
20
+ * @returns {null}
21
+ */
22
+ function updateGitFile() {
23
+ const preCommit_File_Path_Default = path.resolve(getRootDirectory(), '.git', 'hooks', 'pre-commit.sample');
24
+ let preCommit_File_Path = path.join(path.dirname(preCommit_File_Path_Default), 'pre-commit');
25
+ if (existsSync(preCommit_File_Path_Default)) {
26
+ fs.writeFileSync(preCommit_File_Path_Default, `#!/bin/sh${getCustomPrecommitHookPath()}`);
27
+ fs.renameSync(preCommit_File_Path_Default, preCommit_File_Path);
28
+ return;
29
+ }
30
+ if (existsSync(preCommit_File_Path)) {
31
+ fs.appendFileSync(preCommit_File_Path, `\n${getCustomPrecommitHookPath()}`);
32
+ return;
33
+ }
34
+ }
35
+ module.exports = {
36
+ updateGitFile
37
+ };
package/changeLog.md ADDED
@@ -0,0 +1,7 @@
1
+ # Code standard library
2
+
3
+ # 0.0.0
4
+ 1. Sets up a custom precommit hook using husky
5
+ 2. clones the common linter configuration repository in developer branch
6
+ 3. Based on the cloned configuration folder creates a eslint config file
7
+ 4. Checks for eslint rule violations in the staged files(Impact based) and aborts/allows commit accordingly
@@ -0,0 +1,18 @@
1
+ const { rulesConfig, plugins, extendPlugins } = require("@zohodesk/codestandard-validator"); //no i18n
2
+ const [off, , error] = ["off", "warn", "error"];
3
+ module.exports = {
4
+ env: {
5
+ browser: true,
6
+ es2021: true,
7
+ },
8
+ extends: extendPlugins,
9
+ parserOptions: {
10
+ ecmaFeatures: {
11
+ jsx: true,
12
+ },
13
+ ecmaVersion: 12,
14
+ sourceType: "module",
15
+ },
16
+ plugins: plugins,
17
+ overrides: rulesConfig
18
+ };
@@ -0,0 +1,9 @@
1
+ const { zsecurityRules } = require('./rule_configuration/configurations')
2
+ const $plugins = require('./pluginVersion')
3
+
4
+
5
+ module.exports = {
6
+ rulesConfig : Object.assign([],[...zsecurityRules]),
7
+ plugins:$plugins.map((plugin) => plugin?.plugin).filter(item => item !== undefined) ,
8
+ extendPlugins:$plugins.map((plugin) => plugin?.extend).filter(item => item !== undefined)
9
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = [
2
+ {
3
+ packageName: "@zohodesk/eslint-plugin-zsecurity",
4
+ version: "0.0.1-beta.4",
5
+ plugin: "@zohodesk/zsecurity"
6
+ }
7
+ ];
@@ -0,0 +1,9 @@
1
+ module.exports.zsecurityRules = [
2
+ {
3
+ files: ["src/**/*.js"],
4
+ rules: {
5
+ "@zohodesk/zsecurity/no-unsecure-html": 'error',
6
+ "@zohodesk/zsecurity/no-protocol-check": 'error',
7
+ },
8
+ },
9
+ ];
@@ -0,0 +1,18 @@
1
+ const { rulesConfig, plugins, extendPlugins } = require("@zohodesk/codestandard-validator"); //no i18n
2
+ const [off, , error] = ["off", "warn", "error"];
3
+ module.exports = {
4
+ env: {
5
+ browser: true,
6
+ es2021: true,
7
+ },
8
+ extends: extendPlugins,
9
+ parserOptions: {
10
+ ecmaFeatures: {
11
+ jsx: true,
12
+ },
13
+ ecmaVersion: 12,
14
+ sourceType: "module",
15
+ },
16
+ plugins: plugins,
17
+ overrides: rulesConfig
18
+ };
@@ -0,0 +1,16 @@
1
+ const { plugins , rulesConfig} = require('../../common/index')
2
+ const { architectureRules } = require("./rule_configuration/architectureRules/bestPracticeRules")
3
+ const { i18Configuration } = require("./rule_configuration/i18nRules/noHardcodingRuleExcludes")
4
+ const $plugins = [...require('./pluginVersion'), ...plugins ]
5
+
6
+
7
+ module.exports = {
8
+ rulesConfig : Object.assign([],[...architectureRules,...i18Configuration,...rulesConfig]) ,
9
+ plugins:$plugins.map((plugin) => plugin?.plugin).filter(item => item !== undefined) ,
10
+ extendPlugins:$plugins.map((plugin) => plugin?.extend).filter(item => item !== undefined)
11
+ }
12
+
13
+
14
+
15
+
16
+
@@ -0,0 +1,17 @@
1
+ module.exports = [
2
+ {
3
+ packageName: "@zohodesk/eslint-plugin-architecturerules",
4
+ version: "0.0.2-exp-4",
5
+ plugin: "@zohodesk/architecturerules",
6
+ },
7
+ {
8
+ packageName: "@zohodesk/eslint-plugin-no-hardcoding",
9
+ version: "1.0.2",
10
+ plugin: "@zohodesk/no-hardcoding",
11
+ },
12
+ {
13
+ packageName: "@zohodesk/eslint-config-acceptancetest",
14
+ version: "0.0.3",
15
+ extend: "@zohodesk/eslint-config-acceptancetest",
16
+ }
17
+ ];
@@ -0,0 +1,9 @@
1
+ module.exports.architectureRules = [
2
+ {
3
+ files: ['src/**/*.js'],
4
+ rules: {
5
+ '@zohodesk/architecturerules/no-unused-vars' : 'warn',
6
+ '@zohodesk/architecturerules/no-comments-rule':'warn'
7
+ }
8
+ }
9
+ ]
@@ -0,0 +1,32 @@
1
+ let noHardcodingRuleExcludes = {
2
+ objectKeys:["dataId","data-id","data-test-id","size","iconSize","iconName","align","alignBox","palette","scroll","boxSize","boxPosition","type","moduleName","apiname","apiName","id","target","tagName","module","folderName","componentGroup","hoverType","tabIndex","aria-Label","aria-label","ariaLabel","d","className","rel","heading","column","row","transform","color","condition","fieldName","animationStyle","textBoxVariant","searchBoxSize","src","display","href","width","height","enctype","target","left","top","position","location","backgroundColor","visibility","cursor","lineHeight","border","readOnly","textAlign","scrolling","class","padding","overflow","textBoxSize","right","top","bottom","left","fieldType","regex","searchModuleFieldName","searchConditionValue","logoName","_id"],
3
+ props:["dataId","data-id","data-test-id","size","iconSize","iconName","align","alignBox","palette","scroll","boxSize","boxPosition","type","moduleName","apiname","apiName","id","target","tagName","module","folderName","componentGroup","hoverType","tabIndex","aria-Label","aria-label","ariaLabel","d","className","rel","heading","column","row","transform","color","condition","fieldName","animationStyle","textBoxVariant","searchBoxSize","src","display","href","width","height","enctype","target","left","top","position","location","backgroundColor","visibility","cursor","lineHeight","border","readOnly","textAlign","scrolling","class","padding","overflow","textBoxSize","right","top","bottom","left","fieldType","logoName","_id"],
4
+ methods:["findIdex","findIndex","includes","getFieldIndex","oneOf","oneOfType","bind","getFieldLabel","addEventListener","removeEventListener","replace","split","indexOf","set","selectn","getAdditionalProperty","reject","sendResponse","resolve","mapStateToProps","setAttribute","updateError","concat","createElement","getproperty","addElement","getElementsByName","match","lastIndexOf","setRequestHeader","getParameter","getAttribute","RegExp","substring","equals","log","debug","addClass","open","find","setTimeout","attachEvent","addEventListener","removeAttribute","parseInt","replace","setInterval","getObj","detachEvent","removeEventListener","css","animate","bind","ajaxNew","set_cookie","getElementById","ajax","find","createTextNode","parents","removeClass","toggleClass","write","get_cookie","parseFromString","Error","error","querySelector","getDeptBasedData","timeEnd","time","deskCustomError"],
5
+ allowedTags:["svg"],
6
+ keys:["Product Category","Product Owner","Product Information","Summarize information","and then","and finally","Support Manager","Newbie Agent","Light Agent","All Accounts","All Contacts","All Cases","Open Cases","Closed Cases","My Cases","All Products","Published Solutions","Open Tasks","All Published Solutions","My Draft Solutions","My Review Solutions","Today+Overdue Tasks","Overdue Cases","My Overdue Cases","Spam Cases","Requests for review","Customer Responded Requests","Customer Responded Time","Unassigned Open Requests","Unassigned Open Cases","SLAViolated Requests","My Open Requests","My Accounts","My Contacts","My Products","All Solutions","My Solutions","All Tasks","My Open Tasks","Todays Tasks","Unpublished Solutions","Overdue Tasks","Tomorrows Tasks","All Contracts","Expired Contracts","My Contracts","My Tasks","Completed Tasks","Missed Chats","All Missed Calls","My Missed Calls","Accounts Unmapped with CRM","Accounts Mapped with CRM","Contacts Unmapped with CRM","Contacts Mapped with CRM","Agent Notification","Contact Notification","Contact Created Time","Public Email Templates","Request has been assigned to you","Request for review","Request moved to the Department","Team Notification","Secondary Contacts Notification","Created By","Created Time","Modified Time","Last Activity Time","Unsubscribed Mode","Unsubscribed Time","Reports To","Date of Birth","New Request Created","Your request has been closed","Requestor has replied to the request","Comment Added for the Request","Comment is deleted from a ticket","Comment is edited in a ticket","Resolution Updated for the Request","Notify support reps on new request","Notify Agent when a comment is deleted for their ticket","Notify Agent when a comment is edited from their ticket","Acknowledge contact on receiving a new ticket","Notify agent on assigning a task","Notify agents when a ticket is moved to their department","Notify all agents when a new ticket is created","Notify contact when a comment is added","Notify contact when a comment is deleted","Notify contact when a comment is edited","Notify contact when a resolution is added","Task has been assigned to you","Remind Task Owner on Set Time","Popular Articles","Remind At","User Information","To Address","Account Name","Contact Information",
7
+ "All Requests","Product Code","Product Name","Unit Price","Due Date","Case Number","Not Started","In Progress","Waiting on someone else","On Hold","Contact Name","Last Week","Current Week","Last Month","Current Month","Previous FY","Current FY","Next FY","Previous FQ","Current FQ","Next FQ","Next Week","Next Month","Last 60 Days","Last 90 Days","Last 120 Days","Next 7 Days","Next 30 Days","Next 60 Days","Next 90 Days","Next 120 Days","Full Name","Due on","All User","View Requests","Add Request","View Thread","Paid User","Open in New Window","Recent articles","Contract Name","Contract End","Contract Start","Request Id","Contract Number","Sub Category","support.label.Additional Information","Closed Activities","Recent Views","Modified By","Other Phone","Home Phone","Account Number","Request Subject","Request Charge","Other Address","Mailing Address","Billing Address","Shipping Address","Response Due Date","Unassigned Cases","Case On Hold Time","Summarize information by","and then by","and finally by","Time to Respond","Closing Date","crm.label.Product Category","crm.label.Product Owner","crm.label.Product Information","crm.label.Contact Name","Sub Category","mousemove click","Manufacturer","Hour","Deactivated","Review","Notes","CREATEDTIME","Requests","Social","Reports","Report","Solution","Articles","Article","Customized","Title","Fax","Lookup","Chat","Community","Left","Cases","Solutions","Contract","Accounts","Account","Contacts","Contact","Products","Product","Home","Tasks","Calls","Events","IM","Phone","Mobile","Email","Type","Website","Name","Country","Comments","Priority","Description","Department","click","email","is","are","None","this","these","Total","Category","Pending","Status","Subject","Answer","Overdue","between","Top","Customer","Completed","Deferred","Highest","Lowest","High","Low","Normal","Inactive","Open","New","Web","Draft","Duplicate","Closed","Archived","Today","January","February","March","April","May","June","July","August","September","October","November","December","Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Oct","Nov","Dec","days","day","on","User","Records","Private","AllUsers","Month","Avg","General","and","or","currentDateTime","confirmmsg","maxlenmsg","AM","PM","for","Update","to","Direction","hour","hours","minute",
8
+ "minutes","second","seconds","ago","Move","Unassigned","Expired","Prospect","potential","Lead","Request","Mode","Forums","More","Call","Task","Event","sendingportalinvitation","loading","Custom","loggedinuser_view","everyone_view","onlyagents_view","Agent","Ticket","Attachment","SMS","Subscriptions","ActiveUsersList","DeactivatedUsersList","NotConfirmedUsersList","Content","Created"],
9
+ commentsToIgnoreHardcodingCheck:["no i18n"],
10
+ stringsAllowedAsBlockCommentStart: ["ignore i18n start","no i18n start"],
11
+ stringsAllowedAsBlockCommentEnd: ["ignore i18n end","no i18n end"],
12
+ dateFormatPatterns:["DD MMM YYYY hh:mm A","DD\/MM\/YYYY h:mm A","DDD, DD MMM YYYY HH:mm:ss","DD MMM YYYY","hh:mm A"]
13
+ }
14
+ const [error,,off] = ['error','','off']
15
+
16
+ let usegetI18NValueAppropriatelyExcludes = {
17
+ i18nKeys:noHardcodingRuleExcludes.keys,
18
+ commentsToIgnoreCheck:noHardcodingRuleExcludes.commentsToIgnoreHardcodingCheck
19
+ }
20
+
21
+ module.exports.i18Configuration = [
22
+ {
23
+ files: ['src/**/*.js'],
24
+ rules: {
25
+ '@zohodesk/no-hardcoding/no-hardcoding' : [error,{...noHardcodingRuleExcludes}],
26
+ '@zohodesk/no-hardcoding/use-getI18NValue-method-appropriately': [error,{...usegetI18NValueAppropriatelyExcludes}]
27
+ }
28
+ }
29
+ ]
30
+
31
+
32
+
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ const { getLintConfigurationUtil } = require("./build/utils/EslintConfigFileUtils/getLintConfiguration");
2
+ const { rulesConfig, plugins, extendPlugins } = getLintConfigurationUtil();
3
+
4
+ module.exports = {
5
+ rulesConfig,
6
+ plugins,
7
+ extendPlugins
8
+ };
@@ -0,0 +1,17 @@
1
+
2
+ /**
3
+ * @typedef {Object} LinterConfiguration
4
+ * @property {string} endPoint - The URL of the git repository containing the linter configuration.
5
+ * @property {string} branch - The branch of the git repository to use.
6
+ * @property {string} cacheDirectory - The directory where the configuration should be cached.
7
+ * @property {string} commonLinterRepoName - The name in which the linter configuration repo will be cloned.
8
+ * @property {string} type - The type of configuration source, typically "git".
9
+ */
10
+
11
+ module.exports = {
12
+ endPoint: "https://zgit.csez.zohocorpin.com/code_standard/client_linter/linter_configuration.git",
13
+ branch: "master",
14
+ cacheDirectory: "./",
15
+ commonLinterRepoName: "configuration",
16
+ type: "git"
17
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@zohodesk/codestandard-validator",
3
+ "version": "0.0.0-exp-1",
4
+ "description": "library to enforce code standard using eslint",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "postinstall": "node bin/postinstall.js",
9
+ "build": "babel -d ./build ./src --copy-files"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "bin": {
14
+ "ZDPrecommit": "./bin/cli.js"
15
+ },
16
+ "type": "commonjs",
17
+ "dependencies": {
18
+ "@zohodesk-private/client_deployment_tool": "0.0.5",
19
+ "eslint": "^8.26.0"
20
+ },
21
+ "devDependencies": {
22
+ "@babel/core": "^7.24.7",
23
+ "@babel/plugin-transform-runtime": "^7.24.7",
24
+ "@babel/preset-env": "^7.24.7",
25
+ "husky": "^7.0.4"
26
+ }
27
+ }