.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / tslint / lib / rules / eoflineRule.js
1 "use strict";
2 /**
3  * @license
4  * Copyright 2013 Palantir Technologies, Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var Lint = require("../index");
21 var Rule = /** @class */ (function (_super) {
22     tslib_1.__extends(Rule, _super);
23     function Rule() {
24         return _super !== null && _super.apply(this, arguments) || this;
25     }
26     Rule.prototype.apply = function (sourceFile) {
27         var length = sourceFile.text.length;
28         if (length === 0 || // if the file is empty, it "ends with a newline", so don't return a failure
29             sourceFile.text[length - 1] === "\n") {
30             return [];
31         }
32         var fix;
33         var lines = sourceFile.getLineStarts();
34         if (lines.length > 1) {
35             fix = Lint.Replacement.appendText(length, sourceFile.text[lines[1] - 2] === "\r" ? "\r\n" : "\n");
36         }
37         return [
38             new Lint.RuleFailure(sourceFile, length, length, Rule.FAILURE_STRING, this.ruleName, fix),
39         ];
40     };
41     /* tslint:disable:object-literal-sort-keys */
42     Rule.metadata = {
43         ruleName: "eofline",
44         description: "Ensures the file ends with a newline.",
45         descriptionDetails: "Fix for single-line files is not supported.",
46         rationale: "It is a [standard convention](https://stackoverflow.com/q/729692/3124288) to end files with a newline.",
47         optionsDescription: "Not configurable.",
48         options: null,
49         optionExamples: [true],
50         hasFix: true,
51         type: "formatting",
52         typescriptOnly: false,
53     };
54     /* tslint:enable:object-literal-sort-keys */
55     Rule.FAILURE_STRING = "file should end with a newline";
56     return Rule;
57 }(Lint.Rules.AbstractRule));
58 exports.Rule = Rule;