isml-linter 5.39.3 → 5.40.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.
- package/CHANGELOG.md +1184 -1159
- package/LICENSE +21 -21
- package/README.md +245 -245
- package/bin/isml-linter.js +32 -32
- package/ismllinter.config.js +33 -33
- package/package.json +53 -53
- package/scaffold_files/ismllinter.config.js +47 -47
- package/src/Builder.js +15 -15
- package/src/Constants.js +139 -139
- package/src/IsmlLinter.js +255 -255
- package/src/enums/ParseStatus.js +5 -5
- package/src/enums/SfccTagContainer.js +287 -287
- package/src/isml_tree/ContainerNode.js +38 -38
- package/src/isml_tree/IsmlNode.js +692 -684
- package/src/isml_tree/MaskUtils.js +421 -421
- package/src/isml_tree/ParseUtils.js +532 -506
- package/src/isml_tree/TreeBuilder.js +273 -273
- package/src/publicApi.js +24 -24
- package/src/rules/line_by_line/enforce-isprint.js +53 -53
- package/src/rules/line_by_line/enforce-require.js +35 -35
- package/src/rules/line_by_line/lowercase-filename.js +29 -29
- package/src/rules/line_by_line/max-lines.js +37 -37
- package/src/rules/line_by_line/no-br.js +36 -36
- package/src/rules/line_by_line/no-git-conflict.js +43 -43
- package/src/rules/line_by_line/no-import-package.js +34 -34
- package/src/rules/line_by_line/no-inline-style.js +34 -34
- package/src/rules/line_by_line/no-isscript.js +34 -34
- package/src/rules/line_by_line/no-space-only-lines.js +47 -47
- package/src/rules/line_by_line/no-tabs.js +38 -38
- package/src/rules/line_by_line/no-trailing-spaces.js +52 -52
- package/src/rules/prototypes/RulePrototype.js +79 -79
- package/src/rules/prototypes/SingleLineRulePrototype.js +47 -47
- package/src/rules/prototypes/TreeRulePrototype.js +84 -84
- package/src/rules/tree/align-isset.js +87 -87
- package/src/rules/tree/contextual-attrs.js +105 -105
- package/src/rules/tree/custom-tags.js +54 -54
- package/src/rules/tree/disallow-tags.js +39 -39
- package/src/rules/tree/empty-eof.js +66 -66
- package/src/rules/tree/enforce-security.js +85 -85
- package/src/rules/tree/eslint-to-isscript.js +179 -179
- package/src/rules/tree/indent.js +856 -853
- package/src/rules/tree/leading-iscache.js +39 -39
- package/src/rules/tree/leading-iscontent.js +35 -35
- package/src/rules/tree/max-depth.js +54 -54
- package/src/rules/tree/no-deprecated-attrs.js +67 -67
- package/src/rules/tree/no-embedded-isml.js +17 -17
- package/src/rules/tree/no-hardcode.js +51 -51
- package/src/rules/tree/no-iselse-slash.js +35 -35
- package/src/rules/tree/no-redundant-context.js +134 -134
- package/src/rules/tree/no-require-in-loop.js +63 -63
- package/src/rules/tree/one-element-per-line.js +82 -76
- package/src/util/CommandLineUtils.js +19 -19
- package/src/util/ConfigUtils.js +219 -219
- package/src/util/ConsoleUtils.js +327 -327
- package/src/util/CustomTagContainer.js +45 -45
- package/src/util/ExceptionUtils.js +173 -149
- package/src/util/FileUtils.js +79 -79
- package/src/util/GeneralUtils.js +60 -60
- package/src/util/NativeExtensionUtils.js +6 -6
- package/src/util/RuleUtils.js +295 -295
- package/src/util/TempRuleUtils.js +232 -232
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
-
|
|
3
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
4
|
-
const description = 'Avoid putting logic into ISML';
|
|
5
|
-
const occurrenceText = '<isscript>';
|
|
6
|
-
|
|
7
|
-
const Rule = Object.create(SingleLineRulePrototype);
|
|
8
|
-
|
|
9
|
-
Rule.init(ruleId, description);
|
|
10
|
-
|
|
11
|
-
Rule.isBroken = function(line) { return line.indexOf(occurrenceText) >= 0; };
|
|
12
|
-
|
|
13
|
-
Rule.getColumnNumber = function(line) {
|
|
14
|
-
return Math.max(line.indexOf(occurrenceText), 0) + 1;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
Rule.getFirstOccurrence = function(line) {
|
|
18
|
-
|
|
19
|
-
let result = null;
|
|
20
|
-
|
|
21
|
-
if (this.isBroken(line)) {
|
|
22
|
-
|
|
23
|
-
const matchPos = line.indexOf(occurrenceText);
|
|
24
|
-
|
|
25
|
-
result = {
|
|
26
|
-
globalPos : matchPos,
|
|
27
|
-
length : occurrenceText.length
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
module.exports = Rule;
|
|
1
|
+
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
+
|
|
3
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
4
|
+
const description = 'Avoid putting logic into ISML';
|
|
5
|
+
const occurrenceText = '<isscript>';
|
|
6
|
+
|
|
7
|
+
const Rule = Object.create(SingleLineRulePrototype);
|
|
8
|
+
|
|
9
|
+
Rule.init(ruleId, description);
|
|
10
|
+
|
|
11
|
+
Rule.isBroken = function(line) { return line.indexOf(occurrenceText) >= 0; };
|
|
12
|
+
|
|
13
|
+
Rule.getColumnNumber = function(line) {
|
|
14
|
+
return Math.max(line.indexOf(occurrenceText), 0) + 1;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
Rule.getFirstOccurrence = function(line) {
|
|
18
|
+
|
|
19
|
+
let result = null;
|
|
20
|
+
|
|
21
|
+
if (this.isBroken(line)) {
|
|
22
|
+
|
|
23
|
+
const matchPos = line.indexOf(occurrenceText);
|
|
24
|
+
|
|
25
|
+
result = {
|
|
26
|
+
globalPos : matchPos,
|
|
27
|
+
length : occurrenceText.length
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = Rule;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
-
const Constants = require('../../Constants');
|
|
3
|
-
|
|
4
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
5
|
-
const description = 'Line contains only blank spaces';
|
|
6
|
-
|
|
7
|
-
const Rule = Object.create(SingleLineRulePrototype);
|
|
8
|
-
|
|
9
|
-
Rule.init(ruleId, description);
|
|
10
|
-
|
|
11
|
-
Rule.isBroken = function(line) { return line !== '' && line !== '\r' && line !== Constants.EOL && !/\S/.test(line); };
|
|
12
|
-
|
|
13
|
-
Rule.getColumnNumber = function() {
|
|
14
|
-
return 1;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
Rule.getFixedContent = function(templateContent) {
|
|
18
|
-
const GeneralUtils = require('../../util/GeneralUtils');
|
|
19
|
-
|
|
20
|
-
const activeLineBreak = GeneralUtils.getActiveLineBreak();
|
|
21
|
-
const lineArray = templateContent.split(Constants.EOL);
|
|
22
|
-
const result = [];
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < lineArray.length; i++) {
|
|
25
|
-
const line = lineArray[i];
|
|
26
|
-
|
|
27
|
-
result.push(line.trim() ? line : line.trim());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return result.join(activeLineBreak);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
Rule.getFirstOccurrence = function(line) {
|
|
34
|
-
|
|
35
|
-
let result = null;
|
|
36
|
-
|
|
37
|
-
if (this.isBroken(line)) {
|
|
38
|
-
result = {
|
|
39
|
-
globalPos : 0,
|
|
40
|
-
length : line.length + 1
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
module.exports = Rule;
|
|
1
|
+
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
+
const Constants = require('../../Constants');
|
|
3
|
+
|
|
4
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
5
|
+
const description = 'Line contains only blank spaces';
|
|
6
|
+
|
|
7
|
+
const Rule = Object.create(SingleLineRulePrototype);
|
|
8
|
+
|
|
9
|
+
Rule.init(ruleId, description);
|
|
10
|
+
|
|
11
|
+
Rule.isBroken = function(line) { return line !== '' && line !== '\r' && line !== Constants.EOL && !/\S/.test(line); };
|
|
12
|
+
|
|
13
|
+
Rule.getColumnNumber = function() {
|
|
14
|
+
return 1;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
Rule.getFixedContent = function(templateContent) {
|
|
18
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
19
|
+
|
|
20
|
+
const activeLineBreak = GeneralUtils.getActiveLineBreak();
|
|
21
|
+
const lineArray = templateContent.split(Constants.EOL);
|
|
22
|
+
const result = [];
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < lineArray.length; i++) {
|
|
25
|
+
const line = lineArray[i];
|
|
26
|
+
|
|
27
|
+
result.push(line.trim() ? line : line.trim());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result.join(activeLineBreak);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Rule.getFirstOccurrence = function(line) {
|
|
34
|
+
|
|
35
|
+
let result = null;
|
|
36
|
+
|
|
37
|
+
if (this.isBroken(line)) {
|
|
38
|
+
result = {
|
|
39
|
+
globalPos : 0,
|
|
40
|
+
length : line.length + 1
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = Rule;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
-
const IndentRule = require('../tree/indent');
|
|
3
|
-
const GeneralUtils = require('../../util/GeneralUtils');
|
|
4
|
-
|
|
5
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
-
const description = 'Tab detected';
|
|
7
|
-
|
|
8
|
-
const Rule = Object.create(SingleLineRulePrototype);
|
|
9
|
-
|
|
10
|
-
Rule.init(ruleId, description);
|
|
11
|
-
|
|
12
|
-
Rule.isBroken = function(line) { return line.indexOf('\t') >= 0; };
|
|
13
|
-
|
|
14
|
-
Rule.getColumnNumber = function(line) {
|
|
15
|
-
return Math.max(line.indexOf(' '), 0) + 1;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
Rule.getFixedContent = function(templateContent) {
|
|
19
|
-
const indent = IndentRule.getIndentation();
|
|
20
|
-
const fixedContent = templateContent.replace(/\t/g, indent);
|
|
21
|
-
return GeneralUtils.applyActiveLineBreaks(fixedContent);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
Rule.getFirstOccurrence = function(line) {
|
|
25
|
-
|
|
26
|
-
let result = null;
|
|
27
|
-
|
|
28
|
-
if (this.isBroken(line)) {
|
|
29
|
-
result = {
|
|
30
|
-
globalPos : line.indexOf('\t'),
|
|
31
|
-
length : 1
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
module.exports = Rule;
|
|
1
|
+
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
+
const IndentRule = require('../tree/indent');
|
|
3
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
4
|
+
|
|
5
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
+
const description = 'Tab detected';
|
|
7
|
+
|
|
8
|
+
const Rule = Object.create(SingleLineRulePrototype);
|
|
9
|
+
|
|
10
|
+
Rule.init(ruleId, description);
|
|
11
|
+
|
|
12
|
+
Rule.isBroken = function(line) { return line.indexOf('\t') >= 0; };
|
|
13
|
+
|
|
14
|
+
Rule.getColumnNumber = function(line) {
|
|
15
|
+
return Math.max(line.indexOf(' '), 0) + 1;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Rule.getFixedContent = function(templateContent) {
|
|
19
|
+
const indent = IndentRule.getIndentation();
|
|
20
|
+
const fixedContent = templateContent.replace(/\t/g, indent);
|
|
21
|
+
return GeneralUtils.applyActiveLineBreaks(fixedContent);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
Rule.getFirstOccurrence = function(line) {
|
|
25
|
+
|
|
26
|
+
let result = null;
|
|
27
|
+
|
|
28
|
+
if (this.isBroken(line)) {
|
|
29
|
+
result = {
|
|
30
|
+
globalPos : line.indexOf('\t'),
|
|
31
|
+
length : 1
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = Rule;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
-
const Constants = require('../../Constants');
|
|
3
|
-
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
-
|
|
5
|
-
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
-
const description = 'Blank space at the end of the line detected';
|
|
7
|
-
|
|
8
|
-
const Rule = Object.create(SingleLineRulePrototype);
|
|
9
|
-
|
|
10
|
-
Rule.init(ruleId, description);
|
|
11
|
-
|
|
12
|
-
Rule.isBroken = function(line) { return (line.endsWith(' ') || line.endsWith(' \r')) && line.replace(/\s/g, '').length; };
|
|
13
|
-
|
|
14
|
-
Rule.getColumnNumber = function(line) {
|
|
15
|
-
const revertPosition = ParseUtils.getNextNonEmptyCharPos(line.split('').reverse().join(''));
|
|
16
|
-
return Math.max(line.length - revertPosition, 0) + 1;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
Rule.getFixedContent = function(templateContent) {
|
|
20
|
-
const GeneralUtils = require('../../util/GeneralUtils');
|
|
21
|
-
|
|
22
|
-
const activeLineBreak = GeneralUtils.getActiveLineBreak();
|
|
23
|
-
const lineArray = GeneralUtils.toLF(templateContent).split(Constants.EOL);
|
|
24
|
-
const result = [];
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < lineArray.length; i++) {
|
|
27
|
-
const line = lineArray[i];
|
|
28
|
-
|
|
29
|
-
result.push(line.replace(/\s+$/g, ''));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return result.join(activeLineBreak);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
Rule.getFirstOccurrence = function(line) {
|
|
36
|
-
|
|
37
|
-
let result = null;
|
|
38
|
-
|
|
39
|
-
if (this.isBroken(line)) {
|
|
40
|
-
|
|
41
|
-
const matchPos = /(\t|\s)*$/.exec(line).index;
|
|
42
|
-
|
|
43
|
-
result = {
|
|
44
|
-
globalPos : matchPos,
|
|
45
|
-
length : line.length - matchPos
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
module.exports = Rule;
|
|
1
|
+
const SingleLineRulePrototype = require('../prototypes/SingleLineRulePrototype');
|
|
2
|
+
const Constants = require('../../Constants');
|
|
3
|
+
const ParseUtils = require('../../isml_tree/ParseUtils');
|
|
4
|
+
|
|
5
|
+
const ruleId = require('path').basename(__filename).slice(0, -3);
|
|
6
|
+
const description = 'Blank space at the end of the line detected';
|
|
7
|
+
|
|
8
|
+
const Rule = Object.create(SingleLineRulePrototype);
|
|
9
|
+
|
|
10
|
+
Rule.init(ruleId, description);
|
|
11
|
+
|
|
12
|
+
Rule.isBroken = function(line) { return (line.endsWith(' ') || line.endsWith(' \r')) && line.replace(/\s/g, '').length; };
|
|
13
|
+
|
|
14
|
+
Rule.getColumnNumber = function(line) {
|
|
15
|
+
const revertPosition = ParseUtils.getNextNonEmptyCharPos(line.split('').reverse().join(''));
|
|
16
|
+
return Math.max(line.length - revertPosition, 0) + 1;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
Rule.getFixedContent = function(templateContent) {
|
|
20
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
21
|
+
|
|
22
|
+
const activeLineBreak = GeneralUtils.getActiveLineBreak();
|
|
23
|
+
const lineArray = GeneralUtils.toLF(templateContent).split(Constants.EOL);
|
|
24
|
+
const result = [];
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < lineArray.length; i++) {
|
|
27
|
+
const line = lineArray[i];
|
|
28
|
+
|
|
29
|
+
result.push(line.replace(/\s+$/g, ''));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result.join(activeLineBreak);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Rule.getFirstOccurrence = function(line) {
|
|
36
|
+
|
|
37
|
+
let result = null;
|
|
38
|
+
|
|
39
|
+
if (this.isBroken(line)) {
|
|
40
|
+
|
|
41
|
+
const matchPos = /(\t|\s)*$/.exec(line).index;
|
|
42
|
+
|
|
43
|
+
result = {
|
|
44
|
+
globalPos : matchPos,
|
|
45
|
+
length : line.length - matchPos
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports = Rule;
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
const ConfigUtils = require('../../util/ConfigUtils');
|
|
2
|
-
const GeneralUtils = require('../../util/GeneralUtils');
|
|
3
|
-
const Constants = require('../../Constants');
|
|
4
|
-
|
|
5
|
-
const RulePrototype = {
|
|
6
|
-
|
|
7
|
-
init(id, description) {
|
|
8
|
-
this.id = id;
|
|
9
|
-
this.description = description;
|
|
10
|
-
this.level = 'errors';
|
|
11
|
-
this.result = {
|
|
12
|
-
occurrenceList : []
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
getError(line, lineNumber, columnNumber, globalPos, length, description) {
|
|
17
|
-
return {
|
|
18
|
-
line,
|
|
19
|
-
globalPos,
|
|
20
|
-
length,
|
|
21
|
-
lineNumber,
|
|
22
|
-
columnNumber,
|
|
23
|
-
rule : this.id,
|
|
24
|
-
level : this.getConfigs().level || Constants.occurrenceLevels.ERROR,
|
|
25
|
-
message : description || this.description
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
isEnabled() {
|
|
30
|
-
const config = ConfigUtils.load();
|
|
31
|
-
return config && config.rules && this.id in config.rules;
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
shouldIgnore(templatePath) {
|
|
35
|
-
const ignoreArray = this.getConfigs().ignore;
|
|
36
|
-
|
|
37
|
-
if (ignoreArray) {
|
|
38
|
-
return ignoreArray.some( ignore => {
|
|
39
|
-
return templatePath.includes(ignore);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
getDefaultAttrs() {
|
|
47
|
-
return {};
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
getConfigs() {
|
|
51
|
-
const config = ConfigUtils.load();
|
|
52
|
-
const ruleDefaultConfigs = this.getDefaultAttrs();
|
|
53
|
-
const indentRuleValue = config.rules['indent'] && config.rules['indent'].value;
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
...ruleDefaultConfigs,
|
|
57
|
-
...config.rules[this.id],
|
|
58
|
-
autoFix : config.autoFix,
|
|
59
|
-
indent : indentRuleValue || 4,
|
|
60
|
-
linebreakStyle : GeneralUtils.getActiveLineBreak()
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
checkChildren(node, data) {
|
|
65
|
-
const occurrenceList = [];
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
68
|
-
const childrenOccurrenceList = this.check(node.children[i], data);
|
|
69
|
-
|
|
70
|
-
if (childrenOccurrenceList) {
|
|
71
|
-
occurrenceList.push(...childrenOccurrenceList);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return occurrenceList;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
module.exports = RulePrototype;
|
|
1
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
2
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
3
|
+
const Constants = require('../../Constants');
|
|
4
|
+
|
|
5
|
+
const RulePrototype = {
|
|
6
|
+
|
|
7
|
+
init(id, description) {
|
|
8
|
+
this.id = id;
|
|
9
|
+
this.description = description;
|
|
10
|
+
this.level = 'errors';
|
|
11
|
+
this.result = {
|
|
12
|
+
occurrenceList : []
|
|
13
|
+
};
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
getError(line, lineNumber, columnNumber, globalPos, length, description) {
|
|
17
|
+
return {
|
|
18
|
+
line,
|
|
19
|
+
globalPos,
|
|
20
|
+
length,
|
|
21
|
+
lineNumber,
|
|
22
|
+
columnNumber,
|
|
23
|
+
rule : this.id,
|
|
24
|
+
level : this.getConfigs().level || Constants.occurrenceLevels.ERROR,
|
|
25
|
+
message : description || this.description
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
isEnabled() {
|
|
30
|
+
const config = ConfigUtils.load();
|
|
31
|
+
return config && config.rules && this.id in config.rules;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
shouldIgnore(templatePath) {
|
|
35
|
+
const ignoreArray = this.getConfigs().ignore;
|
|
36
|
+
|
|
37
|
+
if (ignoreArray) {
|
|
38
|
+
return ignoreArray.some( ignore => {
|
|
39
|
+
return templatePath.includes(ignore);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
getDefaultAttrs() {
|
|
47
|
+
return {};
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getConfigs() {
|
|
51
|
+
const config = ConfigUtils.load();
|
|
52
|
+
const ruleDefaultConfigs = this.getDefaultAttrs();
|
|
53
|
+
const indentRuleValue = config.rules['indent'] && config.rules['indent'].value;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...ruleDefaultConfigs,
|
|
57
|
+
...config.rules[this.id],
|
|
58
|
+
autoFix : config.autoFix,
|
|
59
|
+
indent : indentRuleValue || 4,
|
|
60
|
+
linebreakStyle : GeneralUtils.getActiveLineBreak()
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
checkChildren(node, data) {
|
|
65
|
+
const occurrenceList = [];
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
68
|
+
const childrenOccurrenceList = this.check(node.children[i], data);
|
|
69
|
+
|
|
70
|
+
if (childrenOccurrenceList) {
|
|
71
|
+
occurrenceList.push(...childrenOccurrenceList);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return occurrenceList;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
module.exports = RulePrototype;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
const RulePrototype = require('./RulePrototype');
|
|
2
|
-
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
-
const Constants = require('../../Constants');
|
|
4
|
-
const GeneralUtils = require('../../util/GeneralUtils');
|
|
5
|
-
|
|
6
|
-
const SingleLineRulePrototype = Object.create(RulePrototype);
|
|
7
|
-
|
|
8
|
-
SingleLineRulePrototype.check = function(templateContent, data = { isCrlfLineBreak : false }) {
|
|
9
|
-
|
|
10
|
-
const config = ConfigUtils.load();
|
|
11
|
-
const lineArray = GeneralUtils.toLF(templateContent).split(Constants.EOL);
|
|
12
|
-
const occurrenceList = [];
|
|
13
|
-
let globalPos = 0;
|
|
14
|
-
|
|
15
|
-
for (let lineNumber = 0; lineNumber < lineArray.length; lineNumber++) {
|
|
16
|
-
const line = lineArray[lineNumber];
|
|
17
|
-
const occurrence = this.getFirstOccurrence(line);
|
|
18
|
-
|
|
19
|
-
if (occurrence) {
|
|
20
|
-
let occurrenceGlobalPos = globalPos + occurrence.globalPos;
|
|
21
|
-
const columnNumber = this.getColumnNumber(line);
|
|
22
|
-
|
|
23
|
-
if (data.isCrlfLineBreak) {
|
|
24
|
-
occurrenceGlobalPos += lineNumber;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const error = this.getError(line, lineNumber + 1, columnNumber, occurrenceGlobalPos, occurrence.length);
|
|
28
|
-
|
|
29
|
-
occurrenceList.push(error);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
globalPos += line.length + 1;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (occurrenceList.length &&
|
|
36
|
-
config.autoFix &&
|
|
37
|
-
this.getFixedContent) {
|
|
38
|
-
return {
|
|
39
|
-
occurrenceList,
|
|
40
|
-
fixedContent : this.getFixedContent(templateContent)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { occurrenceList };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
module.exports = SingleLineRulePrototype;
|
|
1
|
+
const RulePrototype = require('./RulePrototype');
|
|
2
|
+
const ConfigUtils = require('../../util/ConfigUtils');
|
|
3
|
+
const Constants = require('../../Constants');
|
|
4
|
+
const GeneralUtils = require('../../util/GeneralUtils');
|
|
5
|
+
|
|
6
|
+
const SingleLineRulePrototype = Object.create(RulePrototype);
|
|
7
|
+
|
|
8
|
+
SingleLineRulePrototype.check = function(templateContent, data = { isCrlfLineBreak : false }) {
|
|
9
|
+
|
|
10
|
+
const config = ConfigUtils.load();
|
|
11
|
+
const lineArray = GeneralUtils.toLF(templateContent).split(Constants.EOL);
|
|
12
|
+
const occurrenceList = [];
|
|
13
|
+
let globalPos = 0;
|
|
14
|
+
|
|
15
|
+
for (let lineNumber = 0; lineNumber < lineArray.length; lineNumber++) {
|
|
16
|
+
const line = lineArray[lineNumber];
|
|
17
|
+
const occurrence = this.getFirstOccurrence(line);
|
|
18
|
+
|
|
19
|
+
if (occurrence) {
|
|
20
|
+
let occurrenceGlobalPos = globalPos + occurrence.globalPos;
|
|
21
|
+
const columnNumber = this.getColumnNumber(line);
|
|
22
|
+
|
|
23
|
+
if (data.isCrlfLineBreak) {
|
|
24
|
+
occurrenceGlobalPos += lineNumber;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const error = this.getError(line, lineNumber + 1, columnNumber, occurrenceGlobalPos, occurrence.length);
|
|
28
|
+
|
|
29
|
+
occurrenceList.push(error);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
globalPos += line.length + 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (occurrenceList.length &&
|
|
36
|
+
config.autoFix &&
|
|
37
|
+
this.getFixedContent) {
|
|
38
|
+
return {
|
|
39
|
+
occurrenceList,
|
|
40
|
+
fixedContent : this.getFixedContent(templateContent)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { occurrenceList };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = SingleLineRulePrototype;
|