1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var LinterError_1 = require("./LinterError");
|
4 | var Rules = (function () {
|
5 | function Rules() {
|
6 | }
|
7 | Rules.run = function (ctx) {
|
8 | ctx.getContent().forEach(function (line, index) {
|
9 | Rules.lineLimit(line, index, ctx);
|
10 | Rules.queryStructure(line, index, ctx);
|
11 | Rules.lineWithTODO(line, index, ctx);
|
12 | Rules.queryWithoutCondition(line, index, ctx);
|
13 | Rules.whiteSpace(line, index, ctx);
|
14 | });
|
15 | };
|
16 | Rules.lineLimit = function (line, index, ctx) {
|
17 | if (line.length > 120) {
|
18 | ctx.addError(new LinterError_1.LinterError(index + 1, 'Line exceeds the limit of 120 characters.'));
|
19 | }
|
20 | };
|
21 | Rules.queryStructure = function (line, index, ctx) {
|
22 | if (line.match(/(where.+)?(and|limit).*\]/i) || line.match(/,\s*\w+(\s+)?(\n*)?from/i)) {
|
23 | ctx.addError(new LinterError_1.LinterError(index + 1, 'SOQL query with more than one condition and/or field being searched should be splitted into multiple lines.'));
|
24 | }
|
25 | };
|
26 | Rules.queryWithoutCondition = function (line, index, ctx) {
|
27 | if (ctx.getSOQLCount() > 0) {
|
28 | if (line.match(/from \w+\s*\]/i)) {
|
29 | ctx.addError(new LinterError_1.LinterError(index + 1, 'SOQL query without condition.'));
|
30 | }
|
31 | }
|
32 | };
|
33 | Rules.lineWithTODO = function (line, index, ctx) {
|
34 | if (line.match(/\/\/\s?TODO\s?:/g)) {
|
35 | ctx.foundTodo();
|
36 | ctx.addError(new LinterError_1.LinterError(index + 1, 'TODO found, with missing feature.'));
|
37 | }
|
38 | };
|
39 | Rules.whiteSpace = function (line, index, ctx) {
|
40 | if (line.search('if\\(') != -1) {
|
41 | ctx.addError(new LinterError_1.LinterError(index + 1, 'Missing space between "if" and "(".'));
|
42 | }
|
43 | if (line.search('for\\(') != -1) {
|
44 | ctx.addError(new LinterError_1.LinterError(index + 1, 'Missing space between "for" and "(".'));
|
45 | }
|
46 | if (line.search('else\\{') != -1) {
|
47 | ctx.addError(new LinterError_1.LinterError(index + 1, 'Missing space between "else" and "{".'));
|
48 | }
|
49 | if (line.search('\\}else') != -1) {
|
50 | ctx.addError(new LinterError_1.LinterError(index + 1, 'Missing space between "}" and "else".'));
|
51 | }
|
52 | };
|
53 | return Rules;
|
54 | }());
|
55 | exports.Rules = Rules;
|