Bug 1358418 - Be more informative about which file ESLint is failing on when getASTSource() hits a computed member expression. r=Mossop

MozReview-Commit-ID: GA4bEvJXH3O

--HG--
extra : amend_source : 1fc5729343f29e429a20e787eab13125ca3c91a2
This commit is contained in:
Mark Banner 2017-04-21 10:10:54 +01:00
Родитель be39101bce
Коммит 7cad8fd464
3 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -80,11 +80,12 @@ module.exports = {
* @return {String}
* The JS source for the node.
*/
getASTSource(node) {
getASTSource(node, context) {
switch (node.type) {
case "MemberExpression":
if (node.computed) {
throw new Error("getASTSource unsupported computed MemberExpression");
let filename = context && context.getFilename();
throw new Error(`getASTSource unsupported computed MemberExpression in ${filename}`);
}
return this.getASTSource(node.object) + "." +
this.getASTSource(node.property);

Просмотреть файл

@ -34,7 +34,7 @@ module.exports = function(context) {
if (callee.object.type == "MemberExpression" &&
callee.object.property.type == "Identifier" &&
callee.object.property.name == "parentNode" &&
helpers.getASTSource(callee.object.object) ==
helpers.getASTSource(callee.object.object, context) ==
helpers.getASTSource(node.arguments[0])) {
context.report(node, "use element.remove() instead of " +
"element.parentNode.removeChild(element)");
@ -43,7 +43,7 @@ module.exports = function(context) {
if (node.arguments[0].type == "MemberExpression" &&
node.arguments[0].property.type == "Identifier" &&
node.arguments[0].property.name == "firstChild" &&
helpers.getASTSource(callee.object) ==
helpers.getASTSource(callee.object, context) ==
helpers.getASTSource(node.arguments[0].object)) {
context.report(node, "use element.firstChild.remove() instead of " +
"element.removeChild(element.firstChild)");

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "eslint-plugin-mozilla",
"version": "0.2.42",
"version": "0.2.43",
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
"keywords": [
"eslint",