@scandipwa/magento-scripts 1.14.0 → 1.14.1-alpha.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.
Files changed (44) hide show
  1. package/lib/config/templates/php-fpm.template.conf +1 -0
  2. package/lib/config/versions/magento-2.3.7-p2.js +47 -0
  3. package/lib/config/versions/magento-2.3.7-p3.js +47 -0
  4. package/lib/config/versions/magento-2.4.3-p2.js +51 -0
  5. package/lib/config/versions/magento-2.4.4.js +51 -0
  6. package/lib/config/xml-parser.js +61 -0
  7. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +248 -0
  8. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  9. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  10. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  11. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +29 -0
  12. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  13. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +31 -0
  14. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  15. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  16. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  17. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +29 -0
  18. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +145 -0
  19. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  20. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  21. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +119 -0
  22. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  23. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  24. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  25. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +57 -0
  26. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +76 -0
  27. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +63 -0
  28. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +69 -0
  29. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  30. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +98 -0
  31. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  32. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  33. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  34. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +60 -0
  35. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +51 -0
  36. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +74 -0
  37. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  38. package/lib/tasks/file-system/index.js +1 -1
  39. package/lib/tasks/start.js +6 -2
  40. package/lib/util/instance-metadata.js +7 -1
  41. package/package.json +13 -2
  42. package/typings/context.d.ts +2 -0
  43. package/typings/phpstorm.d.ts +33 -0
  44. package/lib/tasks/file-system/create-php-storm-config.js +0 -82
@@ -0,0 +1,154 @@
1
+ const path = require('path');
2
+ const { loadXmlFile, buildXmlFile } = require('../../../config/xml-parser');
3
+ const pathExists = require('../../../util/path-exists');
4
+ const { formatPathForPHPStormConfig } = require('./xml-utils');
5
+
6
+ const pathToModulesConfig = path.join(process.cwd(), '.idea', 'modules.xml');
7
+ const excludeFoldersPaths = [
8
+ 'bin',
9
+ 'dev',
10
+ 'pub',
11
+ 'setup',
12
+ 'var/cache',
13
+ 'var/page_cache',
14
+ 'var/log'
15
+ ].map((p) => `file://$MODULE_DIR$/${p}`);
16
+
17
+ /**
18
+ * Will retrieve project config file path from module.xml
19
+ *
20
+ * @returns {Promise<String>}
21
+ */
22
+ const getProjectConfigFilePath = async () => {
23
+ const modulesConfigData = await loadXmlFile(pathToModulesConfig);
24
+ return modulesConfigData.project.component.modules.module['@_filepath'].replace('$PROJECT_DIR$', process.cwd());
25
+ };
26
+
27
+ /**
28
+ * @returns {Array<{'@_url': string}>}
29
+ */
30
+ const getExcludedFoldersConfig = (projectConfigData) => {
31
+ if (!projectConfigData.module) {
32
+ projectConfigData.module = {
33
+ '@_type': 'WEB_MODULE',
34
+ '@_version': '4'
35
+ };
36
+ }
37
+
38
+ if (!projectConfigData.module.component) {
39
+ projectConfigData.module.component = {
40
+ '@_name': 'NewModuleRootManager',
41
+ orderEntry: [
42
+ {
43
+ '@_type': 'inheritedJdk'
44
+ },
45
+ {
46
+ '@_type': 'sourceFolder',
47
+ '@_forTest': 'false'
48
+ }
49
+ ]
50
+ };
51
+ }
52
+
53
+ if (!projectConfigData.module.component.content) {
54
+ projectConfigData.module.component.content = {
55
+ '@_url': 'file://$MODULE_DIR$'
56
+ };
57
+ }
58
+
59
+ if (!projectConfigData.module.component.content.excludeFolder) {
60
+ projectConfigData.module.component.content.excludeFolder = [];
61
+ }
62
+
63
+ return projectConfigData
64
+ .module.component.content.excludeFolder;
65
+ };
66
+
67
+ const setupExcludedFolders = (excludedFoldersConfig) => {
68
+ let hasChanges = false;
69
+ // filter excluded folders to get ones that needs to be added to excluded folders list
70
+ const missingExcludedFolders = excludeFoldersPaths
71
+ .filter(
72
+ (excludeFoldersPath) => !excludedFoldersConfig.some(
73
+ (config) => config['@_url'] === excludeFoldersPath
74
+ )
75
+ );
76
+
77
+ if (missingExcludedFolders.length > 0) {
78
+ hasChanges = true;
79
+ missingExcludedFolders.forEach((missingExcludedFolder) => {
80
+ excludedFoldersConfig.unshift({
81
+ '@_url': missingExcludedFolder
82
+ });
83
+ });
84
+ }
85
+
86
+ return hasChanges;
87
+ };
88
+
89
+ const createModulesXML = async () => {
90
+ const filePath = path.join(process.cwd(), '.idea', `${path.parse(process.cwd()).base}.iml`);
91
+ const fileFormattedPath = formatPathForPHPStormConfig(filePath);
92
+ const fileFormattedUrl = `file://${fileFormattedPath}`;
93
+
94
+ const modulesConfig = {
95
+ '?xml': {
96
+ '@_version': '1.0',
97
+ '@_encoding': 'UTF-8'
98
+ },
99
+ project: {
100
+ '@_version': '4',
101
+ component: {
102
+ '@_name': 'ProjectModuleManager',
103
+ modules: [
104
+ {
105
+ module: {
106
+ '@_fileurl': fileFormattedUrl,
107
+ '@_filepath': fileFormattedPath
108
+ }
109
+ }
110
+ ]
111
+ }
112
+ }
113
+ };
114
+
115
+ await buildXmlFile(pathToModulesConfig, modulesConfig);
116
+
117
+ return filePath;
118
+ };
119
+
120
+ /**
121
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
122
+ */
123
+ const setupExcludedFoldersConfig = () => ({
124
+ title: 'Set up excluded folders configuration',
125
+ task: async (ctx, task) => {
126
+ if (await pathExists(pathToModulesConfig)) {
127
+ const projectFilePath = await getProjectConfigFilePath();
128
+ const projectConfigData = await loadXmlFile(projectFilePath);
129
+ const excludedFoldersConfig = getExcludedFoldersConfig(projectConfigData);
130
+ const hasChanges = setupExcludedFolders(excludedFoldersConfig);
131
+ if (hasChanges) {
132
+ await buildXmlFile(projectFilePath, projectConfigData);
133
+ } else {
134
+ task.skip();
135
+ }
136
+
137
+ return;
138
+ }
139
+
140
+ const projectFilePath = await createModulesXML();
141
+ const projectConfigData = {
142
+ '?xml': {
143
+ '@_version': '1.0',
144
+ '@_encoding': 'UTF-8'
145
+ }
146
+ };
147
+ const excludedFoldersConfig = getExcludedFoldersConfig(projectConfigData);
148
+ setupExcludedFolders(excludedFoldersConfig);
149
+
150
+ await buildXmlFile(projectFilePath, projectConfigData);
151
+ }
152
+ });
153
+
154
+ module.exports = setupExcludedFoldersConfig;
@@ -0,0 +1,27 @@
1
+ const setupWorkspaceConfig = require('./workspace-config');
2
+ const setupPhpConfig = require('./php-config');
3
+ const setupDatabaseConfig = require('./database-config');
4
+ const setupInspectionToolsConfig = require('./inspection-tools-config');
5
+ const setupExcludedFoldersConfig = require('./exclude-folder-config');
6
+ const setupStylelintConfig = require('./stylelint-config');
7
+ const setupESLintConfig = require('./eslint-config');
8
+
9
+ /**
10
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
11
+ */
12
+ const createPhpStormConfig = () => ({
13
+ title: 'Setting PHPStorm config',
14
+ task: (ctx, task) => task.newListr([
15
+ setupWorkspaceConfig(),
16
+ setupPhpConfig(),
17
+ setupDatabaseConfig(),
18
+ setupInspectionToolsConfig(),
19
+ setupExcludedFoldersConfig(),
20
+ setupStylelintConfig(),
21
+ setupESLintConfig()
22
+ ], {
23
+ concurrent: true
24
+ })
25
+ });
26
+
27
+ module.exports = createPhpStormConfig;
@@ -0,0 +1,29 @@
1
+ const { nameKey, valueKey } = require('../keys');
2
+ const {
3
+ options: {
4
+ CODING_STANDARD_OPTION_NAME,
5
+ CUSTOM_CODING_STANDARD_OPTION_VALUE
6
+ }
7
+ } = require('./config');
8
+
9
+ const setupCodingStandardOption = async (config) => {
10
+ let hasChanges = false;
11
+ const codingStandardOption = config.option.find(
12
+ (option) => option[nameKey] === CODING_STANDARD_OPTION_NAME
13
+ );
14
+
15
+ if (!codingStandardOption) {
16
+ hasChanges = true;
17
+ config.option.push({
18
+ [nameKey]: CODING_STANDARD_OPTION_NAME,
19
+ [valueKey]: CUSTOM_CODING_STANDARD_OPTION_VALUE
20
+ });
21
+ } else if (codingStandardOption[valueKey] !== CUSTOM_CODING_STANDARD_OPTION_VALUE) {
22
+ hasChanges = true;
23
+ codingStandardOption[valueKey] = CUSTOM_CODING_STANDARD_OPTION_VALUE;
24
+ }
25
+
26
+ return hasChanges;
27
+ };
28
+
29
+ module.exports = setupCodingStandardOption;
@@ -0,0 +1,54 @@
1
+ // inspection tool classes
2
+ const PHP_CS_FIXER_VALIDATION_INSPECTION = 'PhpCSFixerValidationInspection';
3
+ const PHP_CS_VALIDATION_INSPECTION = 'PhpCSValidationInspection';
4
+ const STYLELINT_INSPECTION = 'Stylelint';
5
+ const ESLINT_INSPECTION = 'Eslint';
6
+ const MESS_DETECTOR_VALIDATION_INSPECTION = 'MessDetectorValidationInspection';
7
+
8
+ // options
9
+ const CODING_STANDARD_OPTION_NAME = 'CODING_STANDARD';
10
+ const CUSTOM_CODING_STANDARD_OPTION_VALUE = 'Custom';
11
+ const CUSTOM_RULE_SET_PATH_OPTION_NAME = 'CUSTOM_RULESET_PATH';
12
+ const MAGENTO2_CODING_STANDARD_OPTION_VALUE = 'Magento2';
13
+ const EXTENSIONS_OPTION_NAME = 'EXTENSIONS';
14
+ const WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME = 'WARNING_HIGHLIGHT_LEVEL_NAME';
15
+ const WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_VALUE = 'ERROR';
16
+ const SHOW_SNIFF_NAMES_OPTION_NAME = 'SHOW_SNIFF_NAMES';
17
+ const USE_INSTALLED_PATHS_OPTION_NAME = 'USE_INSTALLED_PATHS';
18
+ const INSTALLED_PATHS_OPTION_NAME = 'INSTALLED_PATHS';
19
+ const CODESIZE_OPTION_NAME = 'CODESIZE';
20
+ const CONTROVERSIAL_OPTION_NAME = 'CONTROVERSIAL';
21
+ const DESIGN_OPTION_NAME = 'DESIGN';
22
+ const UNUSED_CODE_OPTION_NAME = 'UNUSEDCODE';
23
+ const NAMING_OPTION_NAME = 'NAMING';
24
+ const CUSTOM_RULESETS_OPTION_NAME = 'customRulesets';
25
+ const PHP_MD_RULESET_OPTION_VALUE = 'Magento PHPMD rule set';
26
+
27
+ module.exports = {
28
+ options: {
29
+ CODESIZE_OPTION_NAME,
30
+ CONTROVERSIAL_OPTION_NAME,
31
+ DESIGN_OPTION_NAME,
32
+ UNUSED_CODE_OPTION_NAME,
33
+ NAMING_OPTION_NAME,
34
+ CUSTOM_RULESETS_OPTION_NAME,
35
+ PHP_MD_RULESET_OPTION_VALUE,
36
+ CODING_STANDARD_OPTION_NAME,
37
+ CUSTOM_CODING_STANDARD_OPTION_VALUE,
38
+ CUSTOM_RULE_SET_PATH_OPTION_NAME,
39
+ MAGENTO2_CODING_STANDARD_OPTION_VALUE,
40
+ EXTENSIONS_OPTION_NAME,
41
+ WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_NAME,
42
+ WARNING_HIGHLIGHT_LEVEL_NAME_OPTION_VALUE,
43
+ SHOW_SNIFF_NAMES_OPTION_NAME,
44
+ USE_INSTALLED_PATHS_OPTION_NAME,
45
+ INSTALLED_PATHS_OPTION_NAME
46
+ },
47
+ classes: {
48
+ PHP_CS_FIXER_VALIDATION_INSPECTION,
49
+ PHP_CS_VALIDATION_INSPECTION,
50
+ STYLELINT_INSPECTION,
51
+ ESLINT_INSPECTION,
52
+ MESS_DETECTOR_VALIDATION_INSPECTION
53
+ }
54
+ };
@@ -0,0 +1,31 @@
1
+ const pathExists = require('../../../../util/path-exists');
2
+ const { phpCSConfigurationPath, phpCSConfigFormattedPath } = require('./paths');
3
+ const { nameKey, valueKey } = require('../keys');
4
+ const {
5
+ options: {
6
+ CUSTOM_RULE_SET_PATH_OPTION_NAME
7
+ }
8
+ } = require('./config');
9
+
10
+ const setupCustomRuleSetPathOption = async (config) => {
11
+ let hasChanges = false;
12
+ const customRuleSetPathOption = config.option.find(
13
+ (option) => option[nameKey] === CUSTOM_RULE_SET_PATH_OPTION_NAME
14
+ );
15
+ const phpCSConfigExists = await pathExists(phpCSConfigurationPath);
16
+
17
+ if (!customRuleSetPathOption && phpCSConfigExists) {
18
+ hasChanges = true;
19
+ config.option.push({
20
+ [nameKey]: CUSTOM_RULE_SET_PATH_OPTION_NAME,
21
+ [valueKey]: phpCSConfigFormattedPath
22
+ });
23
+ } else if (customRuleSetPathOption && customRuleSetPathOption[valueKey] !== phpCSConfigFormattedPath) {
24
+ hasChanges = true;
25
+ customRuleSetPathOption[valueKey] = phpCSConfigFormattedPath;
26
+ }
27
+
28
+ return hasChanges;
29
+ };
30
+
31
+ module.exports = setupCustomRuleSetPathOption;
@@ -0,0 +1,42 @@
1
+ /* eslint-disable no-param-reassign */
2
+ const properties = {
3
+ enabled: 'true',
4
+ enabled_by_default: 'true',
5
+ level: 'ERROR'
6
+ };
7
+
8
+ /**
9
+ * @param {Object} inspectionTool
10
+ * @param {{
11
+ * enabled: 'true' | 'false',
12
+ * enabled_by_default: 'true' | 'false',
13
+ * level: 'ERROR' | 'WEAK WARNING'
14
+ * }} defaultProperties
15
+ * @returns {Boolean}
16
+ */
17
+ const setupDefaultProperties = (inspectionTool, defaultProperties = properties) => {
18
+ let hasChanges = false;
19
+ if (inspectionTool['@_enabled'] !== defaultProperties.enabled) {
20
+ hasChanges = true;
21
+ inspectionTool['@_enabled'] = defaultProperties.enabled;
22
+ }
23
+
24
+ if (!inspectionTool['@_enabled_by_default']) {
25
+ hasChanges = true;
26
+ inspectionTool['@_enabled_by_default'] = defaultProperties.enabled_by_default;
27
+ }
28
+
29
+ if (!inspectionTool['@_level']) {
30
+ hasChanges = true;
31
+ inspectionTool['@_level'] = defaultProperties.level;
32
+ }
33
+
34
+ if (inspectionTool.option && !Array.isArray(inspectionTool.option)) {
35
+ hasChanges = true;
36
+ inspectionTool.option = [inspectionTool.option];
37
+ }
38
+
39
+ return hasChanges;
40
+ };
41
+
42
+ module.exports = setupDefaultProperties;
@@ -0,0 +1,37 @@
1
+ const {
2
+ classes: {
3
+ ESLINT_INSPECTION
4
+ }
5
+ } = require('./config');
6
+ const { classKey } = require('../keys');
7
+ const setupDefaultProperties = require('./default-properties-config');
8
+
9
+ /**
10
+ * Set up Styelint configuration
11
+ *
12
+ * *function is async so it will be properly handled in Promise.all*
13
+ * @param {Array} inspectionToolsData
14
+ * @returns {Promise<Boolean>}
15
+ */
16
+ const setupESLintInspection = async (inspectionToolsData) => {
17
+ let hasChanges = false;
18
+ const eslintConfig = inspectionToolsData.find(
19
+ (inspectionToolData) => inspectionToolData[classKey] === ESLINT_INSPECTION
20
+ );
21
+
22
+ if (eslintConfig) {
23
+ hasChanges = setupDefaultProperties(eslintConfig);
24
+ } else {
25
+ hasChanges = true;
26
+ inspectionToolsData.push({
27
+ [classKey]: ESLINT_INSPECTION,
28
+ '@_enabled': 'true',
29
+ '@_level': 'ERROR',
30
+ '@_enabled_by_default': 'true'
31
+ });
32
+ }
33
+
34
+ return hasChanges;
35
+ };
36
+
37
+ module.exports = setupESLintInspection;
@@ -0,0 +1,80 @@
1
+ const { loadXmlFile, buildXmlFile } = require('../../../../config/xml-parser');
2
+ const pathExists = require('../../../../util/path-exists');
3
+ const {
4
+ nameKey,
5
+ valueKey,
6
+ classKey
7
+ } = require('../keys');
8
+ const setupESLintInspection = require('./eslint-inspection-config');
9
+ const setupMessDetectorValidationInspection = require('./mess-detector-validation-inspection-config');
10
+ const setupPhpCSFixerValidationInspection = require('./php-cs-fixer-validation-inspection-config');
11
+ const setupPhpCSValidationInspection = require('./php-cs-validation-inspection-config');
12
+ const setupStyleLintInspection = require('./stylelint-inspection-config');
13
+
14
+ /**
15
+ * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext>}
16
+ */
17
+ const setupInspectionToolsConfig = () => ({
18
+ title: 'Set up inspection tools configuration',
19
+ task: async (ctx, task) => {
20
+ const {
21
+ config: {
22
+ phpStorm
23
+ }
24
+ } = ctx;
25
+
26
+ if (await pathExists(phpStorm.inspectionTools.path)) {
27
+ const inspectionToolsData = await loadXmlFile(phpStorm.inspectionTools.path);
28
+ const inspectionTools = inspectionToolsData.component.profile.inspection_tool;
29
+ const hasChanges = await Promise.all([
30
+ setupPhpCSFixerValidationInspection(inspectionTools),
31
+ setupPhpCSValidationInspection(inspectionTools),
32
+ setupStyleLintInspection(inspectionTools),
33
+ setupMessDetectorValidationInspection(inspectionTools)
34
+ ]);
35
+
36
+ if (hasChanges.includes(true)) {
37
+ await buildXmlFile(phpStorm.inspectionTools.path, inspectionToolsData);
38
+ } else {
39
+ task.skip();
40
+ }
41
+
42
+ return;
43
+ }
44
+
45
+ const inspectionToolsData = {
46
+ component: {
47
+ [nameKey]: 'InspectionProjectProfileManager',
48
+ profile: {
49
+ '@_version': '1.0',
50
+ option: {
51
+ [nameKey]: 'myName',
52
+ [valueKey]: 'Project Default'
53
+ },
54
+ inspection_tool: [
55
+ {
56
+ [classKey]: 'PhpStanGlobal',
57
+ '@_enabled': 'true',
58
+ '@_level': 'ERROR',
59
+ '@_enabled_by_default': 'true'
60
+ }
61
+ ]
62
+ }
63
+ }
64
+ };
65
+ const inspectionTools = inspectionToolsData.component.profile.inspection_tool;
66
+
67
+ await Promise.all([
68
+ setupPhpCSFixerValidationInspection(inspectionTools),
69
+ setupPhpCSValidationInspection(inspectionTools),
70
+ setupStyleLintInspection(inspectionTools),
71
+ setupMessDetectorValidationInspection(inspectionTools),
72
+ setupStyleLintInspection(inspectionTools),
73
+ setupESLintInspection(inspectionTools)
74
+ ]);
75
+
76
+ await buildXmlFile(phpStorm.inspectionTools.path, inspectionToolsData);
77
+ }
78
+ });
79
+
80
+ module.exports = setupInspectionToolsConfig;
@@ -0,0 +1,29 @@
1
+ const { nameKey, valueKey } = require('../keys');
2
+ const {
3
+ options: {
4
+ CODING_STANDARD_OPTION_NAME,
5
+ MAGENTO2_CODING_STANDARD_OPTION_VALUE
6
+ }
7
+ } = require('./config');
8
+
9
+ const setupMagento2CodingStandardOption = async (config) => {
10
+ let hasChanges = false;
11
+ const codingStandardOption = config.option.find(
12
+ (option) => option[nameKey] === CODING_STANDARD_OPTION_NAME
13
+ );
14
+
15
+ if (!codingStandardOption) {
16
+ hasChanges = true;
17
+ config.option.push({
18
+ [nameKey]: CODING_STANDARD_OPTION_NAME,
19
+ [valueKey]: MAGENTO2_CODING_STANDARD_OPTION_VALUE
20
+ });
21
+ } else if (codingStandardOption[valueKey] !== MAGENTO2_CODING_STANDARD_OPTION_VALUE) {
22
+ hasChanges = true;
23
+ codingStandardOption[valueKey] = MAGENTO2_CODING_STANDARD_OPTION_VALUE;
24
+ }
25
+
26
+ return hasChanges;
27
+ };
28
+
29
+ module.exports = setupMagento2CodingStandardOption;
@@ -0,0 +1,145 @@
1
+ const { phpMDRuleSetFormattedPath } = require('./paths');
2
+ const {
3
+ classes: {
4
+ MESS_DETECTOR_VALIDATION_INSPECTION
5
+ },
6
+ options: {
7
+ CODESIZE_OPTION_NAME,
8
+ CONTROVERSIAL_OPTION_NAME,
9
+ DESIGN_OPTION_NAME,
10
+ UNUSED_CODE_OPTION_NAME,
11
+ NAMING_OPTION_NAME,
12
+ CUSTOM_RULESETS_OPTION_NAME,
13
+ PHP_MD_RULESET_OPTION_VALUE
14
+ }
15
+ } = require('./config');
16
+ const {
17
+ classKey,
18
+ nameKey,
19
+ valueKey
20
+ } = require('../keys');
21
+ const setupDefaultProperties = require('./default-properties-config');
22
+
23
+ const messDetectorBooleanOptionNames = [
24
+ CODESIZE_OPTION_NAME,
25
+ CONTROVERSIAL_OPTION_NAME,
26
+ DESIGN_OPTION_NAME,
27
+ UNUSED_CODE_OPTION_NAME,
28
+ NAMING_OPTION_NAME
29
+ ];
30
+
31
+ const messDetectorDefaultRuleSetsListContent = {
32
+ RulesetDescriptor: {
33
+ option: [
34
+ {
35
+ [nameKey]: 'name',
36
+ [valueKey]: PHP_MD_RULESET_OPTION_VALUE
37
+ },
38
+ {
39
+ [nameKey]: 'path',
40
+ [valueKey]: phpMDRuleSetFormattedPath
41
+ }
42
+ ]
43
+ }
44
+ };
45
+
46
+ const messDetectorDefaultOptions = [
47
+ ...messDetectorBooleanOptionNames.map((optionName) => ({
48
+ [nameKey]: optionName,
49
+ [valueKey]: 'true'
50
+ })),
51
+ {
52
+ [nameKey]: CUSTOM_RULESETS_OPTION_NAME,
53
+ list: messDetectorDefaultRuleSetsListContent
54
+ }
55
+ ];
56
+
57
+ /**
58
+ * @param {Array} inspectionToolsData
59
+ * @returns {Promise<Boolean>}
60
+ */
61
+ const setupMessDetectorValidationInspection = async (inspectionToolsData) => {
62
+ let hasChanges = false;
63
+ const messDetectorConfig = inspectionToolsData.find((inspectionToolData) => inspectionToolData[classKey] === MESS_DETECTOR_VALIDATION_INSPECTION);
64
+ if (messDetectorConfig) {
65
+ const hasChangesInProperties = setupDefaultProperties(messDetectorConfig, {
66
+ enabled: 'true',
67
+ enabled_by_default: 'true',
68
+ level: 'WEAK WARNING'
69
+ });
70
+
71
+ if (hasChangesInProperties) {
72
+ hasChanges = true;
73
+ }
74
+
75
+ if (messDetectorConfig.option) {
76
+ messDetectorBooleanOptionNames.forEach((optionName) => {
77
+ const booleanOption = messDetectorConfig.option.find(
78
+ (o) => o[nameKey] === optionName
79
+ );
80
+
81
+ if (!booleanOption) {
82
+ hasChanges = true;
83
+ messDetectorConfig.option.push({
84
+ [nameKey]: optionName,
85
+ [valueKey]: 'true'
86
+ });
87
+ } else if (booleanOption[valueKey] !== 'true') {
88
+ hasChanges = true;
89
+ booleanOption[valueKey] = 'true';
90
+ }
91
+ });
92
+
93
+ const customRulesetsOption = messDetectorConfig.option.find(
94
+ (o) => o[nameKey] === CUSTOM_RULESETS_OPTION_NAME
95
+ );
96
+
97
+ if (customRulesetsOption) {
98
+ if (!customRulesetsOption.list) {
99
+ hasChanges = true;
100
+ customRulesetsOption.list = [];
101
+ }
102
+
103
+ if (customRulesetsOption.list && !Array.isArray(customRulesetsOption.list)) {
104
+ hasChanges = true;
105
+ customRulesetsOption.list = [customRulesetsOption.list];
106
+ }
107
+
108
+ const correctRulesetsExists = customRulesetsOption.list.some(
109
+ (r) => r.RulesetDescriptor.option.some(
110
+ (o) => o[nameKey] === 'path' && o[valueKey] === phpMDRuleSetFormattedPath
111
+ )
112
+ );
113
+
114
+ if (!correctRulesetsExists) {
115
+ hasChanges = true;
116
+ customRulesetsOption.list.push(
117
+ messDetectorDefaultRuleSetsListContent
118
+ );
119
+ }
120
+ } else {
121
+ hasChanges = true;
122
+ messDetectorConfig.option.push({
123
+ [nameKey]: CUSTOM_RULESETS_OPTION_NAME,
124
+ list: messDetectorDefaultRuleSetsListContent
125
+ });
126
+ }
127
+ } else {
128
+ hasChanges = true;
129
+ messDetectorConfig.option = messDetectorDefaultOptions;
130
+ }
131
+ } else {
132
+ hasChanges = true;
133
+ inspectionToolsData.push({
134
+ [classKey]: MESS_DETECTOR_VALIDATION_INSPECTION,
135
+ '@_enabled': 'true',
136
+ '@_level': 'WEAK WARNING',
137
+ '@_enabled_by_default': 'true',
138
+ option: messDetectorDefaultOptions
139
+ });
140
+ }
141
+
142
+ return hasChanges;
143
+ };
144
+
145
+ module.exports = setupMessDetectorValidationInspection;
@@ -0,0 +1,20 @@
1
+ const path = require('path');
2
+ const { formatPathForPHPStormConfig } = require('../xml-utils');
3
+
4
+ const phpCompatibilityPath = path.join(process.cwd(), 'vendor', 'phpcompatibility', 'php-compatibility', 'PHPCompatibility');
5
+ const phpCompatibilityRuleSetPath = path.join(phpCompatibilityPath, 'ruleset.xml');
6
+ const phpCompatibilityFormattedPath = formatPathForPHPStormConfig(phpCompatibilityPath);
7
+ const phpCSConfigurationPath = path.join(process.cwd(), '.php_cs.dist');
8
+ const phpCSConfigFormattedPath = formatPathForPHPStormConfig(phpCSConfigurationPath);
9
+ const phpMDRuleSetPath = path.join(process.cwd(), 'dev', 'tests', 'static', 'testsuite', 'Magento', 'Test', 'Php', '_files', 'phpmd', 'ruleset.xml');
10
+ const phpMDRuleSetFormattedPath = formatPathForPHPStormConfig(phpMDRuleSetPath);
11
+
12
+ module.exports = {
13
+ phpCompatibilityPath,
14
+ phpCompatibilityRuleSetPath,
15
+ phpCompatibilityFormattedPath,
16
+ phpCSConfigurationPath,
17
+ phpCSConfigFormattedPath,
18
+ phpMDRuleSetPath,
19
+ phpMDRuleSetFormattedPath
20
+ };