Skip to content

Commit

Permalink
Exclude eslint comments in prop descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
anantkamath committed Aug 6, 2019
1 parent fdb9bec commit 2198612
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/extract-react-types/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,24 @@ Object {
"kind": "string",
},
},
Object {
"key": Object {
"kind": "id",
"name": "b",
},
"kind": "property",
"leadingComments": Array [
Object {
"raw": " Type comment for b ",
"type": "commentBlock",
"value": "Type comment for b",
},
],
"optional": false,
"value": Object {
"kind": "any",
},
},
],
"referenceIdName": "Props",
},
Expand Down
7 changes: 6 additions & 1 deletion packages/extract-react-types/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,11 @@ function convertMethodCall(path, context): K.Func {
};
}

function shouldIncludeComment(comment) {
const excludePatterns = [/\s*eslint/];
return !excludePatterns.find(pattern => comment.value.match(pattern));
}

function mapComment(comment) {
return {
type: comment.type === 'CommentLine' ? 'commentLine' : 'commentBlock',
Expand All @@ -1419,7 +1424,7 @@ function attachCommentProperty(source, dest, name) {
if (!source || !source[name]) return;
if (!dest[name]) dest[name] = [];

let comments = source[name].map(mapComment);
let comments = source[name].filter(shouldIncludeComment).map(mapComment);
dest[name] = dest[name].concat(comments);
}

Expand Down
3 changes: 3 additions & 0 deletions packages/extract-react-types/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,9 @@ const TESTS = [
type Props = {
/* Type comment for a */
a: string;
/* Type comment for b */
// eslint-disable-next-line flowtype/no-weak-types
b: any;
}
class Component extends React.Component<Props> {
Expand Down

0 comments on commit 2198612

Please sign in to comment.