1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.schema = undefined;
|
7 |
|
8 | var _lodash = require('lodash');
|
9 |
|
10 | var _lodash2 = _interopRequireDefault(_lodash);
|
11 |
|
12 | var _utilities = require('./../utilities');
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 | var looksLikeFlowFileAnnotation = function looksLikeFlowFileAnnotation(comment) {
|
17 | return (/@(?:no)?flow/i.test(comment)
|
18 | );
|
19 | };
|
20 |
|
21 | var schema = exports.schema = [{
|
22 | enum: ['always']
|
23 | }];
|
24 |
|
25 | exports.default = function (context) {
|
26 | var checkThisFile = !_lodash2.default.get(context, 'settings.flowtype.onlyFilesWithFlowAnnotation') || (0, _utilities.isFlowFile)(context);
|
27 |
|
28 | if (!checkThisFile) {
|
29 | return {};
|
30 | }
|
31 |
|
32 | var always = context.options[0] === 'always';
|
33 |
|
34 | return {
|
35 | Program: function Program(node) {
|
36 | var firstToken = node.tokens[0];
|
37 |
|
38 | var potentialFlowFileAnnotation = _lodash2.default.find(context.getAllComments(), function (comment) {
|
39 | return looksLikeFlowFileAnnotation(comment.value);
|
40 | });
|
41 |
|
42 | if (potentialFlowFileAnnotation) {
|
43 | if (firstToken && firstToken.start < potentialFlowFileAnnotation.start) {
|
44 | context.report(potentialFlowFileAnnotation, 'Flow file annotation not at the top of the file.');
|
45 | }
|
46 |
|
47 | if (!(0, _utilities.isFlowFileAnnotation)(potentialFlowFileAnnotation.value)) {
|
48 | context.report(potentialFlowFileAnnotation, 'Malformed flow file annotation.');
|
49 | }
|
50 | } else if (always) {
|
51 | context.report(node, 'Flow file annotation is missing.');
|
52 | }
|
53 | }
|
54 | };
|
55 | }; |
\ | No newline at end of file |