eslint-plugin-babel
Advanced tools
Comparing version 4.1.0 to 4.1.1
{ | ||
"name": "eslint-plugin-babel", | ||
"version": "4.1.0", | ||
"version": "4.1.1", | ||
"description": "an eslint rule plugin companion to babel-eslint", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -33,4 +33,2 @@ # eslint-plugin-babel | ||
"babel/object-curly-spacing": 1, | ||
"babel/no-await-in-loop": 1, | ||
"babel/flow-object-type": 1, | ||
"babel/no-invalid-this": 1, | ||
@@ -45,14 +43,9 @@ "babel/semi": 1 | ||
🛠 : means it's autofixable with `--fix`. | ||
🛠: means it's autofixable with `--fix`. | ||
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`) | ||
- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠 ) | ||
- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠) | ||
- `babel/no-invalid-this`: doesn't fail when inside class properties (`class A { a = this.b; }`) | ||
- `babel/semi`: Includes class properties (🛠 ) | ||
- `babel/semi`: Includes class properties (🛠) | ||
The following rules are not in `eslint`, but are relevant only to syntax that is not specified by | ||
the current JavaScript standard or supported by `eslint`. | ||
- `babel/no-await-in-loop`: guard against awaiting async functions inside of a loop | ||
#### Deprecated | ||
@@ -66,1 +59,2 @@ | ||
- `babel/flow-object-type`: Use [`flowtype/object-type-delimiter`](https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter). | ||
- `babel/no-await-in-loop`: Use [`no-await-in-loop`](http://eslint.org/docs/rules/no-await-in-loop). |
@@ -1,68 +0,24 @@ | ||
/** | ||
* @fileoverview Rule to disallow uses of await inside of loops. | ||
* @author Nat Mote | ||
*/ | ||
"use strict"; | ||
// Node types which are considered loops. | ||
var loopTypes = { | ||
'ForStatement': true, | ||
'ForOfStatement': true, | ||
'ForInStatement': true, | ||
'WhileStatement': true, | ||
'DoWhileStatement': true, | ||
}; | ||
var isWarnedForDeprecation = false; | ||
module.exports = { | ||
meta: { | ||
deprecated: true, | ||
schema: [] | ||
}, | ||
create: function() { | ||
return { | ||
Program: function() { | ||
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { | ||
return; | ||
} | ||
// Node types at which we should stop looking for loops. For example, it is fine to declare an async | ||
// function within a loop, and use await inside of that. | ||
var boundaryTypes = { | ||
'FunctionDeclaration': true, | ||
'FunctionExpression': true, | ||
'ArrowFunctionExpression': true, | ||
/* eslint-disable no-console */ | ||
console.log('The babel/no-await-in-loop rule is deprecated. Please ' + | ||
'use the built in no-await-in-loop rule instead.'); | ||
/* eslint-enable no-console */ | ||
isWarnedForDeprecation = true; | ||
} | ||
}; | ||
} | ||
}; | ||
module.exports = function(context) { | ||
return { | ||
AwaitExpression(node) { | ||
var ancestors = context.getAncestors(); | ||
// Reverse so that we can traverse from the deepest node upwards. | ||
ancestors.reverse(); | ||
// Create a set of all the ancestors plus this node so that we can check | ||
// if this use of await appears in the body of the loop as opposed to | ||
// the right-hand side of a for...of, for example. | ||
// | ||
// Implement the set with an Array since there are likely to be very few | ||
// elements. An Object would not be appropriate since the elements are | ||
// not strings. | ||
var ancestorSet = [].concat(ancestors, [node]); | ||
var ancestorSetHas = function(element) { | ||
return ancestorSet.indexOf(element) !== -1; | ||
} | ||
for (var i = 0; i < ancestors.length; i++) { | ||
var ancestor = ancestors[i]; | ||
if (boundaryTypes.hasOwnProperty(ancestor.type)) { | ||
// Short-circuit out if we encounter a boundary type. Loops above | ||
// this do not matter. | ||
return; | ||
} | ||
if (loopTypes.hasOwnProperty(ancestor.type)) { | ||
// Only report if we are actually in the body or another part that gets executed on | ||
// every iteration. | ||
if ( | ||
ancestorSetHas(ancestor.body) || | ||
ancestorSetHas(ancestor.test) || | ||
ancestorSetHas(ancestor.update) | ||
) { | ||
context.report( | ||
node, | ||
'Avoid using await inside a loop. Consider refactoring to use Promise.all. If ' + | ||
'you are sure you want to do this, add `// eslint-disable-line ' + | ||
context.id + '` at the end of this line.' | ||
); | ||
return; | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
} |
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
142696
23
3335
58