1 | 'use strict';
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var BaseFormatter_1 = require("./utils/BaseFormatter");
|
17 | var warnedForDeprecation = false;
|
18 | var Formatter = (function (_super) {
|
19 | __extends(Formatter, _super);
|
20 | function Formatter() {
|
21 | var _this = this;
|
22 | if (!warnedForDeprecation) {
|
23 | console.warn('The fix-no-require-imports formatter is deprecated. Use --fix instead.');
|
24 | warnedForDeprecation = true;
|
25 | }
|
26 | _this = _super.call(this, 'no-require-imports', function (failure) {
|
27 | var fileName = failure.getFileName();
|
28 | var fileContents = this.readFile(fileName);
|
29 | var start = failure.getStartPosition().getPosition();
|
30 | var end = failure.getEndPosition().getPosition();
|
31 | var importStartIndex = fileContents.lastIndexOf('\n', start) + 1;
|
32 | if (importStartIndex === -1) {
|
33 | importStartIndex = 0;
|
34 | }
|
35 | var importEndIndex = fileContents.indexOf('\n', end);
|
36 | var leftSide = fileContents.substring(0, importStartIndex);
|
37 | var middle = fileContents.substring(importStartIndex, importEndIndex).trim();
|
38 | var rightSide = fileContents.substring(importEndIndex);
|
39 | var newImport = middle.replace(/import\s+(.*)\s+=\s*require\(((.|\s)*)\);/m, 'import {$1} from $2;');
|
40 | newImport = newImport.replace(/from \n/, 'from\n');
|
41 | var newContent = leftSide + newImport + rightSide;
|
42 | this.writeFile(fileName, newContent);
|
43 | console.log('Automatically converting require-style import to an ES6 import. Please re-compile and re-lint: ' + fileName);
|
44 | }) || this;
|
45 | return _this;
|
46 | }
|
47 | return Formatter;
|
48 | }(BaseFormatter_1.BaseFormatter));
|
49 | exports.Formatter = Formatter;
|
50 |
|
\ | No newline at end of file |