4 * Copyright 2018 Palantir Technologies, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 Object.defineProperty(exports, "__esModule", { value: true });
19 var tslib_1 = require("tslib");
20 var ts = require("typescript");
21 var Lint = require("../index");
22 var Rule = /** @class */ (function (_super) {
23 tslib_1.__extends(Rule, _super);
25 return _super !== null && _super.apply(this, arguments) || this;
27 Rule.prototype.apply = function (sourceFile) {
28 return this.applyWithFunction(sourceFile, walk);
30 /* tslint:disable:object-literal-sort-keys */
32 ruleName: "no-default-export",
33 description: "Disallows default exports in ES6-style modules.",
34 descriptionDetails: "Use named exports instead.",
35 rationale: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n Named imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453).\n In addition, current tooling differs on the correct way to handle default imports/exports.\n Avoiding them all together can help avoid tooling bugs and conflicts."], ["\n Named imports/exports [promote clarity](https://github.com/palantir/tslint/issues/1182#issue-151780453).\n In addition, current tooling differs on the correct way to handle default imports/exports.\n Avoiding them all together can help avoid tooling bugs and conflicts."]))),
36 optionsDescription: "Not configurable.",
38 optionExamples: [true],
39 type: "maintainability",
40 typescriptOnly: false,
42 /* tslint:enable:object-literal-sort-keys */
43 Rule.FAILURE_STRING = "Use of default exports is forbidden";
45 }(Lint.Rules.AbstractRule));
48 if (ctx.sourceFile.isDeclarationFile || !ts.isExternalModule(ctx.sourceFile)) {
51 for (var _i = 0, _a = ctx.sourceFile.statements; _i < _a.length; _i++) {
52 var statement = _a[_i];
53 if (statement.kind === ts.SyntaxKind.ExportAssignment) {
54 if (!statement.isExportEquals) {
55 ctx.addFailureAtNode(statement.getChildAt(1, ctx.sourceFile), Rule.FAILURE_STRING);
58 else if (statement.modifiers !== undefined &&
59 statement.modifiers.length >= 2 &&
60 statement.modifiers[0].kind === ts.SyntaxKind.ExportKeyword &&
61 statement.modifiers[1].kind === ts.SyntaxKind.DefaultKeyword) {
62 ctx.addFailureAtNode(statement.modifiers[1], Rule.FAILURE_STRING);