Skip to content

Commit

Permalink
Ignore some things in coverage (#2741)
Browse files Browse the repository at this point in the history
- If statements for old deprecated stuff.
- "This should never happen" (and never happens in the tests) code paths.
  • Loading branch information
lydell authored and vjeux committed Sep 3, 2017
1 parent 368522c commit 133303f
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli-util.js
Expand Up @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions src/comments.js
Expand Up @@ -121,6 +121,7 @@ function decorateComment(node, comment, text) {
continue;
}

/* istanbul ignore next */
throw new Error("Comment location overlaps with node location");
}

Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions 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"))
) {
Expand Down
1 change: 1 addition & 0 deletions src/fast-path.js
Expand Up @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions src/multiparser.js
Expand Up @@ -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");
}
Expand Down
2 changes: 2 additions & 0 deletions src/options.js
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/parser.js
Expand Up @@ -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;
}

Expand All @@ -60,6 +62,7 @@ function parse(text, opts) {
throw error;
}

/* istanbul ignore next */
throw error.stack;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/printer-graphql.js
Expand Up @@ -431,6 +431,7 @@ function genericPrint(path, options, print) {
}

default:
/* istanbul ignore next */
throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/printer-htmlparser2.js
Expand Up @@ -88,6 +88,7 @@ function genericPrint(path, options, print) {
}

default:
/* istanbul ignore next */
throw new Error("unknown htmlparser2 type: " + n.type);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/printer-postcss.js
Expand Up @@ -17,6 +17,7 @@ const removeLines = docUtils.removeLines;
function genericPrint(path, options, print) {
const n = path.getValue();

/* istanbul ignore if */
if (!n) {
return "";
}
Expand Down Expand Up @@ -380,6 +381,7 @@ function genericPrint(path, options, print) {
}

default:
/* istanbul ignore next */
throw new Error("unknown postcss type: " + JSON.stringify(n.type));
}
}
Expand Down

0 comments on commit 133303f

Please sign in to comment.