isml-linter 5.39.1 → 5.40.0

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 (61) hide show
  1. package/CHANGELOG.md +1177 -1142
  2. package/LICENSE +21 -21
  3. package/README.md +245 -245
  4. package/bin/isml-linter.js +32 -32
  5. package/ismllinter.config.js +33 -33
  6. package/package.json +53 -53
  7. package/scaffold_files/ismllinter.config.js +47 -47
  8. package/src/Builder.js +15 -15
  9. package/src/Constants.js +139 -139
  10. package/src/IsmlLinter.js +255 -255
  11. package/src/enums/ParseStatus.js +5 -5
  12. package/src/enums/SfccTagContainer.js +287 -287
  13. package/src/isml_tree/ContainerNode.js +38 -38
  14. package/src/isml_tree/IsmlNode.js +692 -658
  15. package/src/isml_tree/MaskUtils.js +421 -419
  16. package/src/isml_tree/ParseUtils.js +515 -434
  17. package/src/isml_tree/TreeBuilder.js +273 -271
  18. package/src/publicApi.js +24 -24
  19. package/src/rules/line_by_line/enforce-isprint.js +53 -53
  20. package/src/rules/line_by_line/enforce-require.js +35 -35
  21. package/src/rules/line_by_line/lowercase-filename.js +29 -29
  22. package/src/rules/line_by_line/max-lines.js +37 -37
  23. package/src/rules/line_by_line/no-br.js +36 -36
  24. package/src/rules/line_by_line/no-git-conflict.js +43 -43
  25. package/src/rules/line_by_line/no-import-package.js +34 -34
  26. package/src/rules/line_by_line/no-inline-style.js +34 -34
  27. package/src/rules/line_by_line/no-isscript.js +34 -34
  28. package/src/rules/line_by_line/no-space-only-lines.js +47 -47
  29. package/src/rules/line_by_line/no-tabs.js +38 -38
  30. package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
  31. package/src/rules/prototypes/RulePrototype.js +79 -79
  32. package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
  33. package/src/rules/prototypes/TreeRulePrototype.js +84 -84
  34. package/src/rules/tree/align-isset.js +87 -87
  35. package/src/rules/tree/contextual-attrs.js +105 -105
  36. package/src/rules/tree/custom-tags.js +54 -54
  37. package/src/rules/tree/disallow-tags.js +39 -39
  38. package/src/rules/tree/empty-eof.js +66 -66
  39. package/src/rules/tree/enforce-security.js +85 -85
  40. package/src/rules/tree/eslint-to-isscript.js +179 -179
  41. package/src/rules/tree/indent.js +856 -853
  42. package/src/rules/tree/leading-iscache.js +39 -43
  43. package/src/rules/tree/leading-iscontent.js +35 -39
  44. package/src/rules/tree/max-depth.js +54 -54
  45. package/src/rules/tree/no-deprecated-attrs.js +67 -67
  46. package/src/rules/tree/no-embedded-isml.js +17 -17
  47. package/src/rules/tree/no-hardcode.js +51 -51
  48. package/src/rules/tree/no-iselse-slash.js +35 -35
  49. package/src/rules/tree/no-redundant-context.js +134 -134
  50. package/src/rules/tree/no-require-in-loop.js +63 -63
  51. package/src/rules/tree/one-element-per-line.js +82 -76
  52. package/src/util/CommandLineUtils.js +19 -19
  53. package/src/util/ConfigUtils.js +219 -219
  54. package/src/util/ConsoleUtils.js +327 -327
  55. package/src/util/CustomTagContainer.js +45 -45
  56. package/src/util/ExceptionUtils.js +149 -136
  57. package/src/util/FileUtils.js +79 -79
  58. package/src/util/GeneralUtils.js +60 -60
  59. package/src/util/NativeExtensionUtils.js +6 -6
  60. package/src/util/RuleUtils.js +295 -295
  61. package/src/util/TempRuleUtils.js +232 -232
@@ -1,45 +1,45 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const Constants = require('../Constants');
4
-
5
- const templatePath = path.join(Constants.specTemplateDir, 'util', 'modules.isml');
6
- const customTagContainer = {};
7
-
8
- if (fs.existsSync(templatePath)) {
9
- const ismoduleTagArray = fs
10
- .readFileSync(templatePath, 'utf-8')
11
- .replace(new RegExp(Constants.OS_EOL, 'g'), '')
12
- .split('/>');
13
-
14
- for (let j = 0; j < ismoduleTagArray.length; j++) {
15
- const ismoduleTag = ismoduleTagArray[j];
16
-
17
- if (ismoduleTag) {
18
-
19
- const attrArray = ismoduleTag
20
- .replace(/\t/g, ' ')
21
- .split(' ')
22
- .slice(1)
23
- . filter( line => line );
24
-
25
- const tag = {
26
- attrList : []
27
- };
28
-
29
- for (let i = 0; i < attrArray.length; i++) {
30
- const stringifiedAttr = attrArray[i];
31
-
32
- const attr = stringifiedAttr.split('=');
33
- const val = attr[1].substring(1, attr[1].length - 1);
34
-
35
- attr[0] === 'attribute' ?
36
- tag.attrList.push(val) :
37
- tag[attr[0]] = val;
38
- }
39
-
40
- customTagContainer['is' + tag.name] = tag;
41
- }
42
- }
43
- }
44
-
45
- module.exports = customTagContainer;
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const Constants = require('../Constants');
4
+
5
+ const templatePath = path.join(Constants.specTemplateDir, 'util', 'modules.isml');
6
+ const customTagContainer = {};
7
+
8
+ if (fs.existsSync(templatePath)) {
9
+ const ismoduleTagArray = fs
10
+ .readFileSync(templatePath, 'utf-8')
11
+ .replace(new RegExp(Constants.OS_EOL, 'g'), '')
12
+ .split('/>');
13
+
14
+ for (let j = 0; j < ismoduleTagArray.length; j++) {
15
+ const ismoduleTag = ismoduleTagArray[j];
16
+
17
+ if (ismoduleTag) {
18
+
19
+ const attrArray = ismoduleTag
20
+ .replace(/\t/g, ' ')
21
+ .split(' ')
22
+ .slice(1)
23
+ . filter( line => line );
24
+
25
+ const tag = {
26
+ attrList : []
27
+ };
28
+
29
+ for (let i = 0; i < attrArray.length; i++) {
30
+ const stringifiedAttr = attrArray[i];
31
+
32
+ const attr = stringifiedAttr.split('=');
33
+ const val = attr[1].substring(1, attr[1].length - 1);
34
+
35
+ attr[0] === 'attribute' ?
36
+ tag.attrList.push(val) :
37
+ tag[attr[0]] = val;
38
+ }
39
+
40
+ customTagContainer['is' + tag.name] = tag;
41
+ }
42
+ }
43
+ }
44
+
45
+ module.exports = customTagContainer;
@@ -1,136 +1,149 @@
1
- const Constants = require('../Constants');
2
- const ConfigUtils = require('../util/ConfigUtils');
3
-
4
- const types = {
5
- UNKNOWN_ERROR : 'UNKNOWN_ERROR',
6
- UNCLOSED_DEPRECATED_ISML_COMMENT : 'UNCLOSED_DEPRECATED_ISML_COMMENT',
7
- INVALID_TEMPLATE : 'INVALID_TEMPLATE',
8
- INVALID_CHARACTER : 'INVALID_CHARACTER',
9
- RULE_ERROR : 'RULE_ERROR',
10
- NO_CONFIG : 'NO_CONFIG',
11
- };
12
-
13
- // TODO: This function is originally from ConsoleUtils,
14
- // but it is here to avoid circular dependency;
15
- const displayVerboseMessage = (message, depth = 0) => {
16
- const config = ConfigUtils.load();
17
- let indentation = '';
18
-
19
- for (let i = 0; i < depth; i++) {
20
- indentation += ' ';
21
- }
22
-
23
- if (config.verbose) {
24
- console.log(indentation + message);
25
- }
26
- };
27
-
28
- const unbalancedElementError = (elementType, lineNumber, globalPos, length, templatePath) => {
29
- return {
30
- message : `Unbalanced <${elementType}> element`,
31
- templatePath : templatePath,
32
- globalPos,
33
- length,
34
- lineNumber : lineNumber,
35
- isCustom : true,
36
- type : types.INVALID_TEMPLATE
37
- };
38
- };
39
-
40
- const ruleApplianceError = (rule, originalError, templatePath) => {
41
- displayVerboseMessage(originalError.stack);
42
-
43
- return {
44
- message : `An error happened while applying rule "${rule.id}" to ${templatePath}`,
45
- ruleID : rule.id,
46
- originalError,
47
- lineNumber : 0,
48
- templatePath : templatePath,
49
- isCustom : true,
50
- type : types.RULE_ERROR
51
- };
52
- };
53
-
54
- const unexpectedClosingElementError = (elementType, lineNumber, globalPos, length, templatePath) => {
55
- return {
56
- message : `Unexpected </${elementType}> element`,
57
- templatePath : templatePath,
58
- globalPos,
59
- length,
60
- lineNumber : lineNumber,
61
- isCustom : true,
62
- type : types.INVALID_TEMPLATE
63
- };
64
- };
65
-
66
- const unbalancedQuotesError = (elementType, lineNumber, globalPos, length, templatePath) => {
67
- return {
68
- message : `Unbalanced quotes in <${elementType}> element`,
69
- templatePath : templatePath,
70
- globalPos,
71
- length,
72
- lineNumber : lineNumber,
73
- isCustom : true,
74
- type : types.INVALID_TEMPLATE
75
- };
76
- };
77
-
78
- const unclosedDeprecatedIsmlComment = (lineNumber, globalPos, length, templatePath) => {
79
- return {
80
- message : '"<!---" element not correctly closed: use "--->" instead of "-->"',
81
- templatePath : templatePath,
82
- globalPos,
83
- length,
84
- lineNumber : lineNumber,
85
- isCustom : true,
86
- type : types.UNCLOSED_DEPRECATED_ISML_COMMENT
87
- };
88
- };
89
-
90
- const invalidCharacterError = (character, lineNumber, globalPos, length, templatePath) => {
91
- return {
92
- message : `Invalid character "${character}" found`,
93
- templatePath : templatePath,
94
- globalPos,
95
- length,
96
- lineNumber : lineNumber,
97
- isCustom : true,
98
- type : types.INVALID_CHARACTER
99
- };
100
- };
101
-
102
- const noConfigError = () => {
103
- return {
104
- message : `No configuration found. Please run the following command: ${Constants.EOL}${Constants.EOL}\t./node_modules/.bin/isml-linter --init${Constants.EOL}${Constants.EOL}`,
105
- isCustom : true
106
- };
107
- };
108
-
109
- const noEslintConfigError = () => {
110
- return {
111
- message : 'No eslint configuration found. Please add an ESLint configuration file and try again.',
112
- isCustom : true
113
- };
114
- };
115
-
116
- const emptyException = () => {
117
- return {
118
- isCustom : true
119
- };
120
- };
121
-
122
- const isLinterException = e => e && e.isCustom;
123
-
124
- module.exports = {
125
- unbalancedQuotesError,
126
- ruleApplianceError,
127
- unclosedDeprecatedIsmlComment,
128
- unbalancedElementError,
129
- unexpectedClosingElementError,
130
- invalidCharacterError,
131
- noConfigError,
132
- noEslintConfigError,
133
- emptyException,
134
- isLinterException,
135
- types
136
- };
1
+ const Constants = require('../Constants');
2
+ const ConfigUtils = require('../util/ConfigUtils');
3
+
4
+ const types = {
5
+ UNKNOWN_ERROR : 'UNKNOWN_ERROR',
6
+ UNCLOSED_DEPRECATED_ISML_COMMENT : 'UNCLOSED_DEPRECATED_ISML_COMMENT',
7
+ INVALID_TEMPLATE : 'INVALID_TEMPLATE',
8
+ INVALID_CHARACTER : 'INVALID_CHARACTER',
9
+ RULE_ERROR : 'RULE_ERROR',
10
+ NO_CONFIG : 'NO_CONFIG',
11
+ };
12
+
13
+ // TODO: This function is originally from ConsoleUtils,
14
+ // but it is here to avoid circular dependency;
15
+ const displayVerboseMessage = (message, depth = 0) => {
16
+ const config = ConfigUtils.load();
17
+ let indentation = '';
18
+
19
+ for (let i = 0; i < depth; i++) {
20
+ indentation += ' ';
21
+ }
22
+
23
+ if (config.verbose) {
24
+ console.log(indentation + message);
25
+ }
26
+ };
27
+
28
+ const unbalancedElementError = (elementType, lineNumber, globalPos, length, templatePath) => {
29
+ return {
30
+ message : `Unbalanced <${elementType}> element`,
31
+ templatePath : templatePath,
32
+ globalPos,
33
+ length,
34
+ lineNumber : lineNumber,
35
+ isCustom : true,
36
+ type : types.INVALID_TEMPLATE
37
+ };
38
+ };
39
+
40
+ const ruleApplianceError = (rule, originalError, templatePath) => {
41
+ displayVerboseMessage(originalError.stack);
42
+
43
+ return {
44
+ message : `An error happened while applying rule "${rule.id}" to ${templatePath}`,
45
+ ruleID : rule.id,
46
+ originalError,
47
+ lineNumber : 0,
48
+ templatePath : templatePath,
49
+ isCustom : true,
50
+ type : types.RULE_ERROR
51
+ };
52
+ };
53
+
54
+ const unexpectedClosingElementError = (elementType, lineNumber, globalPos, length, templatePath) => {
55
+ return {
56
+ message : `Unexpected </${elementType}> element`,
57
+ templatePath : templatePath,
58
+ globalPos,
59
+ length,
60
+ lineNumber : lineNumber,
61
+ isCustom : true,
62
+ type : types.INVALID_TEMPLATE
63
+ };
64
+ };
65
+
66
+ const unbalancedQuotesError = (elementType, lineNumber, globalPos, length, templatePath) => {
67
+ return {
68
+ message : `Unbalanced quotes in <${elementType}> element`,
69
+ templatePath : templatePath,
70
+ globalPos,
71
+ length,
72
+ lineNumber : lineNumber,
73
+ isCustom : true,
74
+ type : types.INVALID_TEMPLATE
75
+ };
76
+ };
77
+
78
+ const unclosedDeprecatedIsmlComment = (lineNumber, globalPos, length, templatePath) => {
79
+ return {
80
+ message : '"<!---" element not correctly closed: use "--->" instead of "-->"',
81
+ templatePath : templatePath,
82
+ globalPos,
83
+ length,
84
+ lineNumber : lineNumber,
85
+ isCustom : true,
86
+ type : types.UNCLOSED_DEPRECATED_ISML_COMMENT
87
+ };
88
+ };
89
+
90
+ const invalidCharacterError = (character, lineNumber, globalPos, length, templatePath) => {
91
+ return {
92
+ message : `Invalid character "${character}" found`,
93
+ templatePath : templatePath,
94
+ globalPos,
95
+ length,
96
+ lineNumber : lineNumber,
97
+ isCustom : true,
98
+ type : types.INVALID_CHARACTER
99
+ };
100
+ };
101
+
102
+ const parseError = (elementType, lineNumber, globalPos, length, templatePath) => {
103
+ return {
104
+ message : `An unexpected error happened while parsing element ${elementType} at ${templatePath}:${lineNumber}.`,
105
+ templatePath : templatePath,
106
+ globalPos,
107
+ length,
108
+ lineNumber : lineNumber,
109
+ isCustom : true,
110
+ type : types.UNKNOWN_ERROR
111
+ };
112
+ };
113
+
114
+ const noConfigError = () => {
115
+ return {
116
+ message : `No configuration found. Please run the following command: ${Constants.EOL}${Constants.EOL}\t./node_modules/.bin/isml-linter --init${Constants.EOL}${Constants.EOL}`,
117
+ isCustom : true
118
+ };
119
+ };
120
+
121
+ const noEslintConfigError = () => {
122
+ return {
123
+ message : 'No eslint configuration found. Please add an ESLint configuration file and try again.',
124
+ isCustom : true
125
+ };
126
+ };
127
+
128
+ const emptyException = () => {
129
+ return {
130
+ isCustom : true
131
+ };
132
+ };
133
+
134
+ const isLinterException = e => e && e.isCustom;
135
+
136
+ module.exports = {
137
+ parseError,
138
+ unbalancedQuotesError,
139
+ ruleApplianceError,
140
+ unclosedDeprecatedIsmlComment,
141
+ unbalancedElementError,
142
+ unexpectedClosingElementError,
143
+ invalidCharacterError,
144
+ noConfigError,
145
+ noEslintConfigError,
146
+ emptyException,
147
+ isLinterException,
148
+ types
149
+ };
@@ -1,79 +1,79 @@
1
- const path = require('path');
2
- const Constants = require('./../Constants');
3
- const rootPath = Constants.clientIsmlLinterDir;
4
- const fs = require('fs');
5
- const ConfigUtils = require('./ConfigUtils');
6
-
7
- const saveToJsonFile = (filePath, fileName, content) => {
8
- createDirIfDoesNotExist(filePath);
9
- const fullPath = path.join(filePath, fileName);
10
-
11
- fs.writeFileSync(fullPath, JSON.stringify(content, null, 4));
12
- };
13
-
14
- const saveToFile = (filePath, fileName, content) => {
15
- createDirIfDoesNotExist(filePath);
16
- const fullPath = path.join(filePath, fileName);
17
-
18
- fs.writeFileSync(fullPath, JSON.stringify(content, null, 4));
19
- };
20
-
21
- const deleteFile = filePath => {
22
- if (fileExists(filePath)) {
23
- fs.unlinkSync(path.join(filePath));
24
- }
25
- };
26
-
27
- const createDirIfDoesNotExist = dirPath => {
28
- if (!fs.existsSync(dirPath)) {
29
- fs.mkdirSync(dirPath);
30
- }
31
- };
32
-
33
- const createClientDir = (dirName, dirPath = rootPath) => {
34
- if (!fs.existsSync(path.join(dirPath, dirName))) {
35
- fs.mkdirSync(path.join(dirPath, dirName));
36
- }
37
- };
38
-
39
- const deleteDirectoryRecursively = dirPath => {
40
- if (fs.existsSync(dirPath)) {
41
- const fileArray = fs.readdirSync(dirPath);
42
-
43
- for (let i = 0; i < fileArray.length; i++) {
44
- const file = fileArray[i];
45
- const curPath = path.join(dirPath, file);
46
-
47
- if (fs.lstatSync(curPath).isDirectory()) {
48
- deleteDirectoryRecursively(curPath);
49
- } else {
50
- fs.unlinkSync(curPath);
51
- }
52
- }
53
-
54
- fs.rmdirSync(dirPath);
55
-
56
- return true;
57
- }
58
-
59
- return false;
60
- };
61
-
62
- const isIgnored = filePath => {
63
- const config = ConfigUtils.load();
64
-
65
- return config.ignore && config.ignore.some( ignoredPath => {
66
- return filePath.indexOf(ignoredPath) >= 0;
67
- });
68
- };
69
-
70
- const fileExists = filePath => fs.existsSync(filePath);
71
-
72
- module.exports.saveToFile = saveToFile;
73
- module.exports.saveToJsonFile = saveToJsonFile;
74
- module.exports.fileExists = fileExists;
75
- module.exports.createDirIfDoesNotExist = createDirIfDoesNotExist;
76
- module.exports.deleteFile = deleteFile;
77
- module.exports.deleteDirectoryRecursively = deleteDirectoryRecursively;
78
- module.exports.createClientDir = createClientDir;
79
- module.exports.isIgnored = isIgnored;
1
+ const path = require('path');
2
+ const Constants = require('./../Constants');
3
+ const rootPath = Constants.clientIsmlLinterDir;
4
+ const fs = require('fs');
5
+ const ConfigUtils = require('./ConfigUtils');
6
+
7
+ const saveToJsonFile = (filePath, fileName, content) => {
8
+ createDirIfDoesNotExist(filePath);
9
+ const fullPath = path.join(filePath, fileName);
10
+
11
+ fs.writeFileSync(fullPath, JSON.stringify(content, null, 4));
12
+ };
13
+
14
+ const saveToFile = (filePath, fileName, content) => {
15
+ createDirIfDoesNotExist(filePath);
16
+ const fullPath = path.join(filePath, fileName);
17
+
18
+ fs.writeFileSync(fullPath, JSON.stringify(content, null, 4));
19
+ };
20
+
21
+ const deleteFile = filePath => {
22
+ if (fileExists(filePath)) {
23
+ fs.unlinkSync(path.join(filePath));
24
+ }
25
+ };
26
+
27
+ const createDirIfDoesNotExist = dirPath => {
28
+ if (!fs.existsSync(dirPath)) {
29
+ fs.mkdirSync(dirPath);
30
+ }
31
+ };
32
+
33
+ const createClientDir = (dirName, dirPath = rootPath) => {
34
+ if (!fs.existsSync(path.join(dirPath, dirName))) {
35
+ fs.mkdirSync(path.join(dirPath, dirName));
36
+ }
37
+ };
38
+
39
+ const deleteDirectoryRecursively = dirPath => {
40
+ if (fs.existsSync(dirPath)) {
41
+ const fileArray = fs.readdirSync(dirPath);
42
+
43
+ for (let i = 0; i < fileArray.length; i++) {
44
+ const file = fileArray[i];
45
+ const curPath = path.join(dirPath, file);
46
+
47
+ if (fs.lstatSync(curPath).isDirectory()) {
48
+ deleteDirectoryRecursively(curPath);
49
+ } else {
50
+ fs.unlinkSync(curPath);
51
+ }
52
+ }
53
+
54
+ fs.rmdirSync(dirPath);
55
+
56
+ return true;
57
+ }
58
+
59
+ return false;
60
+ };
61
+
62
+ const isIgnored = filePath => {
63
+ const config = ConfigUtils.load();
64
+
65
+ return config.ignore && config.ignore.some( ignoredPath => {
66
+ return filePath.indexOf(ignoredPath) >= 0;
67
+ });
68
+ };
69
+
70
+ const fileExists = filePath => fs.existsSync(filePath);
71
+
72
+ module.exports.saveToFile = saveToFile;
73
+ module.exports.saveToJsonFile = saveToJsonFile;
74
+ module.exports.fileExists = fileExists;
75
+ module.exports.createDirIfDoesNotExist = createDirIfDoesNotExist;
76
+ module.exports.deleteFile = deleteFile;
77
+ module.exports.deleteDirectoryRecursively = deleteDirectoryRecursively;
78
+ module.exports.createClientDir = createClientDir;
79
+ module.exports.isIgnored = isIgnored;
@@ -1,60 +1,60 @@
1
- const path = require('path');
2
- const Constants = require('../Constants');
3
- const ConfigUtils = require('./ConfigUtils');
4
-
5
- const isObject = item => {
6
- return item && typeof item === 'object' && !Array.isArray(item);
7
- };
8
-
9
- const mergeDeep = (target, ...sources) => {
10
- if (!sources.length) {
11
- return target;
12
- }
13
-
14
- const source = sources.shift();
15
-
16
- if (isObject(target) && isObject(source)) {
17
- for (const key in source) {
18
- if (isObject(source[key])) {
19
- if (!target[key]) Object.assign(target, { [key]: {} });
20
- mergeDeep(target[key], source[key]);
21
- } else {
22
- Object.assign(target, { [key]: source[key] });
23
- }
24
- }
25
- }
26
-
27
- return mergeDeep(target, ...sources);
28
- };
29
-
30
- const getActiveLineBreak = () => {
31
- const config = ConfigUtils.load();
32
- const configLineBreak = config.linebreakStyle && Constants.lineBreak[config.linebreakStyle];
33
-
34
- return configLineBreak || Constants.EOL;
35
- };
36
-
37
- module.exports.formatTemplatePath = filePath => {
38
- return filePath.replace(/\//g, path.sep);
39
- };
40
-
41
- module.exports.toLF = content => {
42
- return content.replace(/\r\n/g, '\n');
43
- };
44
-
45
- module.exports.applyActiveLineBreaks = content => {
46
- const activeLineBreak = getActiveLineBreak();
47
-
48
- return content
49
- .replace(new RegExp(Constants.lineBreak.windows, 'g'), activeLineBreak)
50
- .replace(new RegExp(Constants.lineBreak.unix, 'g'), activeLineBreak);
51
- };
52
-
53
- module.exports.parseISOString = isoString => {
54
- const isoArray = isoString.split(/\D+/);
55
- return new Date(Date.UTC(isoArray[0], --isoArray[1], isoArray[2], isoArray[3], isoArray[4], isoArray[5], isoArray[6]));
56
- };
57
-
58
- module.exports.getActiveLineBreak = getActiveLineBreak;
59
-
60
- module.exports.mergeDeep = mergeDeep;
1
+ const path = require('path');
2
+ const Constants = require('../Constants');
3
+ const ConfigUtils = require('./ConfigUtils');
4
+
5
+ const isObject = item => {
6
+ return item && typeof item === 'object' && !Array.isArray(item);
7
+ };
8
+
9
+ const mergeDeep = (target, ...sources) => {
10
+ if (!sources.length) {
11
+ return target;
12
+ }
13
+
14
+ const source = sources.shift();
15
+
16
+ if (isObject(target) && isObject(source)) {
17
+ for (const key in source) {
18
+ if (isObject(source[key])) {
19
+ if (!target[key]) Object.assign(target, { [key]: {} });
20
+ mergeDeep(target[key], source[key]);
21
+ } else {
22
+ Object.assign(target, { [key]: source[key] });
23
+ }
24
+ }
25
+ }
26
+
27
+ return mergeDeep(target, ...sources);
28
+ };
29
+
30
+ const getActiveLineBreak = () => {
31
+ const config = ConfigUtils.load();
32
+ const configLineBreak = config.linebreakStyle && Constants.lineBreak[config.linebreakStyle];
33
+
34
+ return configLineBreak || Constants.EOL;
35
+ };
36
+
37
+ module.exports.formatTemplatePath = filePath => {
38
+ return filePath.replace(/\//g, path.sep);
39
+ };
40
+
41
+ module.exports.toLF = content => {
42
+ return content.replace(/\r\n/g, '\n');
43
+ };
44
+
45
+ module.exports.applyActiveLineBreaks = content => {
46
+ const activeLineBreak = getActiveLineBreak();
47
+
48
+ return content
49
+ .replace(new RegExp(Constants.lineBreak.windows, 'g'), activeLineBreak)
50
+ .replace(new RegExp(Constants.lineBreak.unix, 'g'), activeLineBreak);
51
+ };
52
+
53
+ module.exports.parseISOString = isoString => {
54
+ const isoArray = isoString.split(/\D+/);
55
+ return new Date(Date.UTC(isoArray[0], --isoArray[1], isoArray[2], isoArray[3], isoArray[4], isoArray[5], isoArray[6]));
56
+ };
57
+
58
+ module.exports.getActiveLineBreak = getActiveLineBreak;
59
+
60
+ module.exports.mergeDeep = mergeDeep;
@@ -1,6 +1,6 @@
1
- if (!String.prototype.replaceAll) {
2
- String.prototype.replaceAll = function(search, replacement) {
3
- const target = this;
4
- return target.split(search).join(replacement);
5
- };
6
- }
1
+ if (!String.prototype.replaceAll) {
2
+ String.prototype.replaceAll = function(search, replacement) {
3
+ const target = this;
4
+ return target.split(search).join(replacement);
5
+ };
6
+ }