-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add respect to
@noflow
annotation (#451)
* fix: general filter for all rules - should be either @flow file, or `onlyFilesWithFlowAnnotation` should not be enabled and file not marked with @noflow * fix: require-valid-file-annotation tests broken with new `checkFlowFileAnnotation` - respect onlyFilesWithFlowAnnotation == true Co-authored-by: Gajus Kuizinas <gajus@gajus.com>
- Loading branch information
Showing
7 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import isNoFlowFileAnnotation from './isNoFlowFileAnnotation'; | ||
|
||
/** | ||
* Checks whether a file has an @flow or @noflow annotation. | ||
* | ||
* @param context | ||
* @param [strict] - By default, the function returns true if the file starts with @flow but not if it | ||
* starts by @noflow. When the strict flag is set to false, the function returns true if the flag has @noflow also. | ||
*/ | ||
|
||
export default (context, strict = true) => { | ||
const comments = context.getAllComments(); | ||
|
||
if (!comments.length) { | ||
return false; | ||
} | ||
|
||
return comments.some((comment) => { | ||
return isNoFlowFileAnnotation(comment.value, strict); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _ from 'lodash'; | ||
|
||
const FLOW_MATCHER = /^@noflow$/; | ||
|
||
export default (comment, strict) => { | ||
// The flow parser splits comments with the following regex to look for the @flow flag. | ||
// See https://github.com/facebook/flow/blob/a96249b93541f2f7bfebd8d62085bf7a75de02f2/src/parsing/docblock.ml#L39 | ||
return _.some(comment.split(/[\t\n\r */\\]+/), (commentPart) => { | ||
const match = commentPart.match(FLOW_MATCHER); | ||
|
||
if (match === null) { | ||
return false; | ||
} | ||
|
||
return !strict || match[0] === '@noflow'; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters