Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

deprecation: Don't show errors on imports and exports #3141

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/rules/deprecationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ function walk(ctx: Lint.WalkContext<void>, tc: ts.TypeChecker) {
}
}
} else {
switch (node.kind) {
case ts.SyntaxKind.ImportDeclaration:
case ts.SyntaxKind.ImportEqualsDeclaration:
case ts.SyntaxKind.ExportDeclaration:
case ts.SyntaxKind.ExportAssignment:
return;
}
return ts.forEachChild(node, cb);
}
});
Expand Down Expand Up @@ -90,13 +97,12 @@ function isDeclaration(identifier: ts.Identifier): boolean {
case ts.SyntaxKind.PropertyDeclaration:
case ts.SyntaxKind.PropertyAssignment:
case ts.SyntaxKind.EnumMember:
case ts.SyntaxKind.ImportEqualsDeclaration:
return (parent as ts.NamedDeclaration).name === identifier;
case ts.SyntaxKind.BindingElement:
case ts.SyntaxKind.ExportSpecifier:
case ts.SyntaxKind.ImportSpecifier:
// return true for `b` in `import {a as b} from "foo"`
return (parent as ts.ImportOrExportSpecifier | ts.BindingElement).name === identifier &&
(parent as ts.ImportOrExportSpecifier | ts.BindingElement).propertyName !== undefined;
// return true for `b` in `const {a: b} = obj"`
return (parent as ts.BindingElement).name === identifier &&
(parent as ts.BindingElement).propertyName !== undefined;
default:
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions test/rules/deprecation/other.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @deprecated reason */
export function other() {}
export function other(): void;
/** not deprecated */
export function other(num: number);
export function other(_num?: number) {}

/** @deprecated */
export let other2: Function;
Expand All @@ -11,4 +14,4 @@ export let notDeprecated2: any;

/** @deprecated deprecated default export */
let def = "";
export default def;
export default def;
20 changes: 15 additions & 5 deletions test/rules/deprecation/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// don't show an error on imports, because they don't do any harm if not used
import def, {other, other2 as foobar, notDeprecated, notDeprecated2} from './other.test';
~~~ [errmsg % ('def', 'deprecated default export')]
~~~~~ [errmsg % ('other', 'reason')]
~~~~~~ [err % ('other2')]
import * as namespaceImport from './other.test';
import * as other2 from './other2.test';
~~~~~~ [err % ('other2')]

other();
~~~~~ [errmsg % ('other', 'reason')]
other(1);
foobar();
~~~~~~ [err % ('foobar')]
other2;
~~~~~~ [err % ('other2')]

import tmp = namespaceImport.other;

tmp;
~~~ [errmsg % ('tmp', 'reason')]

declare interface D {
/** @deprecated */ m: () => void;
}


declare let d: D;
d.m();
~ [err % ('m')]
Expand Down Expand Up @@ -52,6 +60,8 @@ A + B;
~ [err % ('A')]
~ [err % ('B')]

export default A;

declarationIsMissing();

function fn<T>(): T;
Expand Down Expand Up @@ -126,4 +136,4 @@ let {f, g, h} = p;
(function ({f, g}: I) {})

[err]: %s is deprecated.
[errmsg]: %s is deprecated: %s
[errmsg]: %s is deprecated: %s