eslint-plugin-flowtype
Advanced tools
Comparing version 2.14.3 to 2.15.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="2.15.0"></a> | ||
# [2.15.0](https://github.com/gajus/eslint-plugin-flowtype/compare/v2.14.3...v2.15.0) (2016-09-05) | ||
### Features | ||
* options to prevent specific types in `no-weak-types` (#99) ([9c903ad](https://github.com/gajus/eslint-plugin-flowtype/commit/9c903ad)) | ||
<a name="2.14.3"></a> | ||
@@ -7,0 +17,0 @@ ## [2.14.3](https://github.com/gajus/eslint-plugin-flowtype/compare/v2.14.2...v2.14.3) (2016-09-05) |
@@ -23,10 +23,10 @@ 'use strict'; | ||
var genericTypeEvaluator = function genericTypeEvaluator(context) { | ||
var weakTypes = ['Function', 'Object']; | ||
var genericTypeEvaluator = function genericTypeEvaluator(context, _ref) { | ||
var checkFunction = _ref.checkFunction; | ||
var checkObject = _ref.checkObject; | ||
return function (node) { | ||
var name = _lodash2.default.get(node, 'id.name'); | ||
var isWeakType = weakTypes.indexOf(name) >= 0; | ||
if (isWeakType) { | ||
if (checkFunction && name === 'Function' || checkObject && name === 'Object') { | ||
reportWeakType(context, name)(node); | ||
@@ -38,8 +38,22 @@ } | ||
exports.default = function (context) { | ||
return { | ||
AnyTypeAnnotation: reportWeakType(context, 'any'), | ||
GenericTypeAnnotation: genericTypeEvaluator(context) | ||
}; | ||
var checkAny = _lodash2.default.get(context, 'options[0].any', true) === true; | ||
var checkFunction = _lodash2.default.get(context, 'options[0].Function', true) === true; | ||
var checkObject = _lodash2.default.get(context, 'options[0].Object', true) === true; | ||
var checks = {}; | ||
if (checkAny) { | ||
checks.AnyTypeAnnotation = reportWeakType(context, 'any'); | ||
} | ||
if (checkFunction || checkObject) { | ||
checks.GenericTypeAnnotation = genericTypeEvaluator(context, { | ||
checkFunction: checkFunction, | ||
checkObject: checkObject | ||
}); | ||
} | ||
return checks; | ||
}; | ||
module.exports = exports['default']; |
{ | ||
"name": "eslint-plugin-flowtype", | ||
"description": "Flowtype linting rules for ESLint.", | ||
"version": "2.14.3", | ||
"version": "2.15.0", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -292,2 +292,28 @@ <a name="eslint-plugin-flowtype"></a> | ||
This rule optionally takes one argument, an object to configure which type warnings to enable. By default, all of the | ||
warnings are enabled. e.g. to disable the `any` warning (allowing it to exist in your code), while continuing to warn | ||
about `Object` and `Function`: | ||
```js | ||
{ | ||
"rules": { | ||
"flowtype/no-weak-types": [2, { | ||
"any": false, | ||
"Object": true, | ||
"Function": true | ||
}] | ||
} | ||
} | ||
// or, the following is equivalent as default is true: | ||
{ | ||
"rules": { | ||
"flowtype/no-weak-types": [2, { | ||
"any": false | ||
}] | ||
} | ||
} | ||
``` | ||
The following patterns are considered problems: | ||
@@ -382,2 +408,11 @@ | ||
// Message: Unexpected use of weak type "any" | ||
// Options: [{"Function":false}] | ||
type X = any; type Y = Function; type Z = Object | ||
// Message: Unexpected use of weak type "any" | ||
// Message: Unexpected use of weak type "Object" | ||
// Options: [{"Object":false,"any":false}] | ||
type X = any; type Y = Function; type Z = Object | ||
// Message: Unexpected use of weak type "Function" | ||
``` | ||
@@ -415,2 +450,8 @@ | ||
class Foo { props: string } | ||
// Options: [{"Object":false,"any":false}] | ||
type X = any; type Y = Object | ||
// Options: [{"Function":false}] | ||
type X = Function | ||
``` | ||
@@ -417,0 +458,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111198
1168
2038