UNPKG

1.53 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _lodash = require('lodash');
8
9var _lodash2 = _interopRequireDefault(_lodash);
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13var reportWeakType = function reportWeakType(context, weakType) {
14 return function (node) {
15 context.report({
16 data: { weakType: weakType },
17 message: 'Unexpected use of weak type "{{weakType}}"',
18 node: node
19 });
20 };
21};
22
23var genericTypeEvaluator = function genericTypeEvaluator(context, _ref) {
24 var checkFunction = _ref.checkFunction;
25 var checkObject = _ref.checkObject;
26
27 return function (node) {
28 var name = _lodash2.default.get(node, 'id.name');
29
30 if (checkFunction && name === 'Function' || checkObject && name === 'Object') {
31 reportWeakType(context, name)(node);
32 }
33 };
34};
35
36exports.default = function (context) {
37 var checkAny = _lodash2.default.get(context, 'options[0].any', true) === true;
38 var checkFunction = _lodash2.default.get(context, 'options[0].Function', true) === true;
39 var checkObject = _lodash2.default.get(context, 'options[0].Object', true) === true;
40
41 var checks = {};
42
43 if (checkAny) {
44 checks.AnyTypeAnnotation = reportWeakType(context, 'any');
45 }
46
47 if (checkFunction || checkObject) {
48 checks.GenericTypeAnnotation = genericTypeEvaluator(context, {
49 checkFunction: checkFunction,
50 checkObject: checkObject
51 });
52 }
53
54 return checks;
55};
56
57module.exports = exports['default'];
\No newline at end of file