1 | 'use strict';
|
2 | var __extends = (this && this.__extends) || function (d, b) {
|
3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
4 | function __() { this.constructor = d; }
|
5 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
6 | };
|
7 | var fs = require('fs');
|
8 | var abstractFormatter_1 = require('tslint/lib/language/formatter/abstractFormatter');
|
9 | var BaseFormatter = (function (_super) {
|
10 | __extends(BaseFormatter, _super);
|
11 | function BaseFormatter(ruleName, applyFix) {
|
12 | _super.call(this);
|
13 | this.ruleName = ruleName;
|
14 | this.applyFix = applyFix;
|
15 | }
|
16 | BaseFormatter.prototype.format = function (allFailures) {
|
17 | for (var index = allFailures.length - 1; index >= 0; index--) {
|
18 | var failure = allFailures[index];
|
19 | if (failure.getRuleName() === this.ruleName) {
|
20 | this.applyFix(failure);
|
21 | }
|
22 | }
|
23 | var outputLines = allFailures.map(this.formatFailure);
|
24 | return outputLines.join('\n') + '\n';
|
25 | };
|
26 | BaseFormatter.prototype.readFile = function (fileName) {
|
27 | return fs.readFileSync(fileName, { encoding: 'UTF-8' });
|
28 | };
|
29 | BaseFormatter.prototype.writeFile = function (fileName, fileContents) {
|
30 | fs.writeFileSync(fileName, fileContents, { encoding: 'UTF-8' });
|
31 | };
|
32 | BaseFormatter.prototype.formatFailure = function (failure) {
|
33 | var fileName = failure.getFileName();
|
34 | var failureString = failure.getFailure();
|
35 | var ruleName = failure.getRuleName();
|
36 | var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
|
37 | var positionTuple = '[' + (lineAndCharacter.line + 1) + ', ' + (lineAndCharacter.character + 1) + ']';
|
38 | return '(' + ruleName + ') ' + fileName + positionTuple + ': ' + failureString;
|
39 | };
|
40 | return BaseFormatter;
|
41 | }(abstractFormatter_1.AbstractFormatter));
|
42 | exports.BaseFormatter = BaseFormatter;
|
43 |
|
\ | No newline at end of file |