Skip to content
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
4 changes: 3 additions & 1 deletion src/rules/arrayStyle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default (defaultConfig, simpleType) => {
// verbose
GenericTypeAnnotation (node) {
if (node.id.name === 'Array') {
if (node.typeParameters.params.length === 1) {
// Don't report on un-parameterized Array annotations. There are valid cases for this,
// but regardless, we should not crash when encountering them.
if (node.typeParameters && node.typeParameters.params.length === 1) {
const elementTypeNode = node.typeParameters.params[0];
const rawElementType = context.getSourceCode().getText(elementTypeNode);
const inlinedType = inlineType(rawElementType);
Expand Down
10 changes: 10 additions & 0 deletions tests/rules/assertions/arrayStyleSimpleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ export default {
onlyFilesWithFlowAnnotation: true
}
}
},

// While this isn't valid flow, we shouldn't disallow it.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for this if it isn't valid Flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just a sanity check to check that the code won't break. I'm not attached to it at all.

{
code: 'type X = Array'
},

// Valid flow.
{
code: 'type X = typeof Array'
}
]
};