Skip to content
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"ajv": "^5.2.1",
"babel-cli": "^6.14.0",
"babel-eslint": "^6.1.2",
"babel-eslint": "^7.2.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.1.10",
Expand Down
3 changes: 0 additions & 3 deletions src/rules/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ const create = (context) => {
makeDefined(qid);
}
},
InterfaceDeclaration (node) {
makeDefined(node.id);
},
Program () {
globalScope = context.getScope();
},
Expand Down
4 changes: 4 additions & 0 deletions src/rules/noDupeKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ const create = (context) => {
const haystack = [];

_.forEach(node.properties, (identifierNode) => {
if (identifierNode.type === 'ObjectTypeSpreadProperty') {
return;
}

const needle = {name: getParameterName(identifierNode, context)};

if (identifierNode.value.type === 'FunctionTypeAnnotation') {
Expand Down
24 changes: 1 addition & 23 deletions src/rules/useFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ const create = (context) => {
DeclareClass: markTypeAsUsed,
DeclareFunction: markTypeAsUsed,
DeclareModule: markTypeAsUsed,
DeclareVariable: markTypeAsUsed,
GenericTypeAnnotation (node) {
let typeId;
let scope;
let variable;

if (node.id.type === 'Identifier') {
typeId = node.id;
} else if (node.id.type === 'QualifiedTypeIdentifier') {
typeId = node.id;
do {
typeId = typeId.qualification;
} while (typeId.qualification);
}

for (scope = context.getScope(); scope; scope = scope.upper) {
variable = scope.set.get(typeId.name);
if (variable && variable.defs.length) {
context.markVariableAsUsed(typeId.name);
break;
}
}
}
DeclareVariable: markTypeAsUsed
};
};

Expand Down
17 changes: 3 additions & 14 deletions tests/rules/assertions/defineFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
'\'AType\' is not defined.'
]
},
{
code: 'interface AType {}',
errors: [
'\'AType\' is not defined.'
]
},
{
code: '({ a: ({b() {}}: AType) })',
// `AType` appears twice in `globalScope.through` as distinct
Expand All @@ -112,13 +106,6 @@ const VALID_WITH_DEFINE_FLOW_TYPE = [
'\'AType\' is not defined.',
'\'BType\' is not defined.'
]
},
{
code: 'interface AType<BType> {}',
errors: [
'\'AType\' is not defined.',
'\'BType\' is not defined.'
]
}
];

Expand Down Expand Up @@ -158,7 +145,9 @@ const ALWAYS_VALID = [
'function f(a): string {}',
'class C { a: string }',
'var AType = {}; class C { a: AType.a }',
'declare module A { declare var a: AType }'
'declare module A { declare var a: AType }',
'interface AType {}',
'interface AType<BType> {}'
];

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/rules/assertions/noDupeKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export default {
},
{
code: 'var a = 1; var b = 1; type f = { get(key: a): string, get(key: b): string }'
},
{
code: 'type One = { c: number }; type Two = { a: number, b: string, ...One }'
}
]
};
70 changes: 12 additions & 58 deletions tests/rules/assertions/useFlowType.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,62 +34,6 @@ const VALID_WITH_USE_FLOW_TYPE = [
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'import type A from "a"; (function<T: A>(): T {})',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type A from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'import type {A} from "a"; (function<T: A>(): T {})',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type {A} from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: '(function<T: A>(): T {}); import type {a as A} from "a"',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'type A = {}; function x<Y: A>(i: Y) { i }; x()',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'function x<Y: A>(i: Y) { i }; type A = {}; x()',
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()',
// QualifiedTypeIdentifier -------^
errors: [
'\'A\' is defined but never used.'
]
},
{
code: 'function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()',
// ^- QualifiedTypeIdentifier
errors: [
'\'A\' is defined but never used.'
]
}
];

Expand Down Expand Up @@ -125,7 +69,18 @@ const ALWAYS_VALID = [
'import type A from "a"; (function(): A {})',
'(function(): A {}); import type A from "a";',
'declare interface A {}',
'declare type A = {}'
'declare type A = {}',
'import type A from "a"; (function<T: A>(): T {})',
'(function<T: A>(): T {}); import type A from "a"',
'import type {A} from "a"; (function<T: A>(): T {})',
'(function<T: A>(): T {}); import type {A} from "a"',
'(function<T: A>(): T {}); import type {a as A} from "a"',
'type A = {}; function x<Y: A>(i: Y) { i }; x()',
'function x<Y: A>(i: Y) { i }; type A = {}; x()',
'type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()',
// QualifiedTypeIdentifier -------^
'function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()'
// ^- QualifiedTypeIdentifier
];

/**
Expand Down Expand Up @@ -187,4 +142,3 @@ export default {
})
]
};