From 133303f47a30f6b3e46ffdf9d5c2d6609d65c416 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 3 Sep 2017 22:40:44 +0200 Subject: [PATCH] Ignore some things in coverage (#2741) - If statements for old deprecated stuff. - "This should never happen" (and never happens in the tests) code paths. --- src/cli-util.js | 1 + src/comments.js | 5 +++++ src/doc-builders.js | 1 + src/fast-path.js | 1 + src/multiparser.js | 1 + src/options.js | 2 ++ src/parser.js | 3 +++ src/printer-graphql.js | 1 + src/printer-htmlparser2.js | 1 + src/printer-postcss.js | 2 ++ 10 files changed, 18 insertions(+) diff --git a/src/cli-util.js b/src/cli-util.js index a73b94389051..2fffa90ab77c 100644 --- a/src/cli-util.js +++ b/src/cli-util.js @@ -41,6 +41,7 @@ function getParserOption(argv) { } // For backward compatibility. Deprecated in 0.0.10 + /* istanbul ignore if */ if (argv["flow-parser"]) { console.warn("`--flow-parser` is deprecated. Use `--parser flow` instead."); return "flow"; diff --git a/src/comments.js b/src/comments.js index 9681affdf3f0..198be95a46af 100644 --- a/src/comments.js +++ b/src/comments.js @@ -121,6 +121,7 @@ function decorateComment(node, comment, text) { continue; } + /* istanbul ignore next */ throw new Error("Comment location overlaps with node location"); } @@ -226,6 +227,7 @@ function attach(comments, ast, text) { addDanglingComment(enclosingNode, comment); } else { // There are no nodes, let's attach it to the root of the ast + /* istanbul ignore next */ addDanglingComment(ast, comment); } } else if (util.hasNewline(text, locEnd(comment))) { @@ -278,6 +280,7 @@ function attach(comments, ast, text) { addDanglingComment(enclosingNode, comment); } else { // There are no nodes, let's attach it to the root of the ast + /* istanbul ignore next */ addDanglingComment(ast, comment); } } else { @@ -317,6 +320,7 @@ function attach(comments, ast, text) { addDanglingComment(enclosingNode, comment); } else { // There are no nodes, let's attach it to the root of the ast + /* istanbul ignore next */ addDanglingComment(ast, comment); } } @@ -887,6 +891,7 @@ function findExpressionIndexForComment(quasis, comment) { // We haven't found it, it probably means that some of the locations are off. // Let's just return the first one. + /* istanbul ignore next */ return 0; } diff --git a/src/doc-builders.js b/src/doc-builders.js index dccd680cd527..92f8c7d28fbb 100644 --- a/src/doc-builders.js +++ b/src/doc-builders.js @@ -1,6 +1,7 @@ "use strict"; function assertDoc(val) { + /* istanbul ignore if */ if ( !(typeof val === "string" || (val != null && typeof val.type === "string")) ) { diff --git a/src/fast-path.js b/src/fast-path.js index c0d41c91b0c4..61b74c72b3d7 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -19,6 +19,7 @@ FastPath.prototype.getName = function getName() { } // Since the name is always a string, null is a safe sentinel value to // return if we do not know the name of the (root) value. + /* istanbul ignore next */ return null; }; diff --git a/src/multiparser.js b/src/multiparser.js index 8b477bfd9f02..8f0f7b02400c 100644 --- a/src/multiparser.js +++ b/src/multiparser.js @@ -178,6 +178,7 @@ function transformCssDoc(quasisDoc, parent) { ? parent.path.map(parent.print, "expressions") : []; const newDoc = replacePlaceholders(quasisDoc, expressionDocs); + /* istanbul ignore if */ if (!newDoc) { throw new Error("Couldn't insert all the expressions"); } diff --git a/src/options.js b/src/options.js index 9389f096f7c7..25ad8c865e5b 100644 --- a/src/options.js +++ b/src/options.js @@ -45,6 +45,7 @@ function normalize(options) { normalized.trailingComma = "none"; } + /* istanbul ignore if */ if (typeof normalized.trailingComma === "boolean") { // Support a deprecated boolean type for the trailing comma config // for a few versions. This code can be removed later. @@ -68,6 +69,7 @@ function normalize(options) { normalized.parser = parserBackup; // For backward compatibility. Deprecated in 0.0.10 + /* istanbul ignore if */ if ("useFlowParser" in normalized) { normalized.parser = normalized.useFlowParser ? "flow" : "babylon"; delete normalized.useFlowParser; diff --git a/src/parser.js b/src/parser.js index 57923a8203d1..d33d97547ea4 100644 --- a/src/parser.js +++ b/src/parser.js @@ -37,9 +37,11 @@ function resolveParseFunction(opts) { try { return eval("require")(path.resolve(process.cwd(), opts.parser)); } catch (err) { + /* istanbul ignore next */ throw new Error(`Couldn't resolve parser "${opts.parser}"`); } } + /* istanbul ignore next */ return parsers.babylon; } @@ -60,6 +62,7 @@ function parse(text, opts) { throw error; } + /* istanbul ignore next */ throw error.stack; } } diff --git a/src/printer-graphql.js b/src/printer-graphql.js index 4b78035cf8e9..efaab7cf0a12 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -431,6 +431,7 @@ function genericPrint(path, options, print) { } default: + /* istanbul ignore next */ throw new Error("unknown graphql type: " + JSON.stringify(n.kind)); } } diff --git a/src/printer-htmlparser2.js b/src/printer-htmlparser2.js index a60e963b6deb..87fe93d1cd10 100644 --- a/src/printer-htmlparser2.js +++ b/src/printer-htmlparser2.js @@ -88,6 +88,7 @@ function genericPrint(path, options, print) { } default: + /* istanbul ignore next */ throw new Error("unknown htmlparser2 type: " + n.type); } } diff --git a/src/printer-postcss.js b/src/printer-postcss.js index 227a48b1b63e..f2b2d695867e 100644 --- a/src/printer-postcss.js +++ b/src/printer-postcss.js @@ -17,6 +17,7 @@ const removeLines = docUtils.removeLines; function genericPrint(path, options, print) { const n = path.getValue(); + /* istanbul ignore if */ if (!n) { return ""; } @@ -380,6 +381,7 @@ function genericPrint(path, options, print) { } default: + /* istanbul ignore next */ throw new Error("unknown postcss type: " + JSON.stringify(n.type)); } }