Skip to content

Commit

Permalink
chore: switch nyc to c8 (#16263)
Browse files Browse the repository at this point in the history
* chore: switch nyc to c8

* chore: istanbul ignore => c8 ignore

* Update lib/linter/code-path-analysis/code-path-segment.js

Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>

* chore: c8 ignore if/else => c8 ignore start/end

refs: #16263 (comment)

* fix: c8 ignore end => stop

* fix: rm an unused c8 ignore

it does not have an `else`, so seems no longer needed.

* fix: c8 disallows additional text

Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
  • Loading branch information
aladdin-add and AriPerkkio committed Sep 9, 2022
1 parent 67db10c commit 1c388fb
Show file tree
Hide file tree
Showing 26 changed files with 49 additions and 47 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile.js
Expand Up @@ -601,12 +601,12 @@ target.mocha = () => {

echo("Running unit tests");

lastReturn = exec(`${getBinFile("nyc")} -- ${MOCHA} --forbid-only -R progress -t ${MOCHA_TIMEOUT} -c ${TEST_FILES}`);
lastReturn = exec(`${getBinFile("c8")} -- ${MOCHA} --forbid-only -R progress -t ${MOCHA_TIMEOUT} -c ${TEST_FILES}`);
if (lastReturn.code !== 0) {
errors++;
}

lastReturn = exec(`${getBinFile("nyc")} check-coverage --statement 98 --branch 97 --function 98 --lines 98`);
lastReturn = exec(`${getBinFile("c8")} check-coverage --statement 98 --branch 97 --function 98 --lines 98`);
if (lastReturn.code !== 0) {
errors++;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -122,7 +122,8 @@ function statSafeSync(filePath) {
try {
return fs.statSync(filePath);
} catch (error) {
/* istanbul ignore next */

/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
Expand All @@ -141,7 +142,8 @@ function readdirSafeSync(directoryPath) {
try {
return fs.readdirSync(directoryPath, { withFileTypes: true });
} catch (error) {
/* istanbul ignore next */

/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/linter/code-path-analysis/code-path-segment.js
Expand Up @@ -88,10 +88,10 @@ class CodePathSegment {
}
});

/* istanbul ignore if */
/* c8 ignore start */
if (debug.enabled) {
this.internal.nodes = [];
}
}/* c8 ignore stop */
}

/**
Expand Down
14 changes: 7 additions & 7 deletions lib/linter/code-path-analysis/code-path-state.js
Expand Up @@ -59,7 +59,7 @@ function getContinueContext(state, label) {
context = context.upper;
}

/* istanbul ignore next: foolproof (syntax error) */
/* c8 ignore next */
return null;
}

Expand All @@ -79,7 +79,7 @@ function getBreakContext(state, label) {
context = context.upper;
}

/* istanbul ignore next: foolproof (syntax error) */
/* c8 ignore next */
return null;
}

Expand Down Expand Up @@ -433,7 +433,7 @@ class CodePathState {
*/
return context;

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error("unreachable");
}
Expand Down Expand Up @@ -1030,7 +1030,7 @@ class CodePathState {
};
break;

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error(`unknown type: "${type}"`);
}
Expand Down Expand Up @@ -1095,7 +1095,7 @@ class CodePathState {
);
break;

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error("unreachable");
}
Expand Down Expand Up @@ -1392,11 +1392,12 @@ class CodePathState {

const context = getBreakContext(this, label);

/* istanbul ignore else: foolproof (syntax error) */

if (context) {
context.brokenForkContext.add(forkContext.head);
}

/* c8 ignore next */
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
}

Expand All @@ -1417,7 +1418,6 @@ class CodePathState {

const context = getContinueContext(this, label);

/* istanbul ignore else: foolproof (syntax error) */
if (context) {
if (context.continueDestSegments) {
makeLooped(this, forkContext.head, context.continueDestSegments);
Expand Down
6 changes: 3 additions & 3 deletions lib/linter/code-path-analysis/debug-helpers.js
Expand Up @@ -20,7 +20,7 @@ const debug = require("debug")("eslint:code-path");
* @param {CodePathSegment} segment A segment to get.
* @returns {string} Id of the segment.
*/
/* istanbul ignore next */
/* c8 ignore next */
function getId(segment) { // eslint-disable-line jsdoc/require-jsdoc -- Ignoring
return segment.id + (segment.reachable ? "" : "!");
}
Expand Down Expand Up @@ -67,7 +67,7 @@ module.exports = {
* @param {boolean} leaving A flag whether or not it's leaving
* @returns {void}
*/
dumpState: !debug.enabled ? debug : /* istanbul ignore next */ function(node, state, leaving) {
dumpState: !debug.enabled ? debug : /* c8 ignore next */ function(node, state, leaving) {
for (let i = 0; i < state.currentSegments.length; ++i) {
const segInternal = state.currentSegments[i].internal;

Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = {
* @see http://www.graphviz.org
* @see http://www.webgraphviz.com
*/
dumpDot: !debug.enabled ? debug : /* istanbul ignore next */ function(codePath) {
dumpDot: !debug.enabled ? debug : /* c8 ignore next */ function(codePath) {
let text =
"\n" +
"digraph {\n" +
Expand Down
4 changes: 2 additions & 2 deletions lib/linter/code-path-analysis/id-generator.js
Expand Up @@ -33,10 +33,10 @@ class IdGenerator {
next() {
this.n = 1 + this.n | 0;

/* istanbul ignore if */
/* c8 ignore start */
if (this.n < 0) {
this.n = 1;
}
}/* c8 ignore stop */

return this.prefix + this.n;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/linter/timing.js
Expand Up @@ -9,7 +9,7 @@
// Helpers
//------------------------------------------------------------------------------

/* istanbul ignore next */
/* c8 ignore next */
/**
* Align the string to left
* @param {string} str string to evaluate
Expand All @@ -22,7 +22,7 @@ function alignLeft(str, len, ch) {
return str + new Array(len - str.length + 1).join(ch || " ");
}

/* istanbul ignore next */
/* c8 ignore next */
/**
* Align the string to right
* @param {string} str string to evaluate
Expand Down Expand Up @@ -64,7 +64,7 @@ function getListSize() {
return TIMING_ENV_VAR_AS_INTEGER > 10 ? TIMING_ENV_VAR_AS_INTEGER : MINIMUM_SIZE;
}

/* istanbul ignore next */
/* c8 ignore next */
/**
* display the data
* @param {Object} data Data object to be displayed
Expand Down Expand Up @@ -119,7 +119,7 @@ function display(data) {
console.log(table.join("\n")); // eslint-disable-line no-console -- Debugging function
}

/* istanbul ignore next */
/* c8 ignore next */
module.exports = (function() {

const data = Object.create(null);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/array-callback-return.js
Expand Up @@ -125,7 +125,7 @@ function getArrayMethodName(node) {
}
}

/* istanbul ignore next: unreachable */
/* c8 ignore next */
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/global-require.js
Expand Up @@ -28,10 +28,11 @@ function findReference(scope, node) {
const references = scope.references.filter(reference => reference.identifier.range[0] === node.range[0] &&
reference.identifier.range[1] === node.range[1]);

/* istanbul ignore else: correctly returns null */
if (references.length === 1) {
return references[0];
}

/* c8 ignore next */
return null;

}
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/indent-legacy.js
Expand Up @@ -18,8 +18,8 @@ const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

/* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */
// this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway.
/* c8 ignore next */
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
Expand Down Expand Up @@ -212,10 +212,10 @@ module.exports = {
if (context.options[0] === "tab") {
indentSize = 1;
indentType = "tab";
} else /* istanbul ignore else : this will be caught by options validation */ if (typeof context.options[0] === "number") {
} else /* c8 ignore start */ if (typeof context.options[0] === "number") {
indentSize = context.options[0];
indentType = "space";
}
}/* c8 ignore stop */

if (context.options[1]) {
const opts = context.options[1];
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/new-cap.js
Expand Up @@ -39,10 +39,10 @@ const CAPS_ALLOWED = [
*/
function checkArray(obj, key, fallback) {

/* istanbul ignore if */
/* c8 ignore start */
if (Object.prototype.hasOwnProperty.call(obj, key) && !Array.isArray(obj[key])) {
throw new TypeError(`${key}, if provided, must be an Array`);
}
}/* c8 ignore stop */
return obj[key] || fallback;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-extra-boolean-cast.js
Expand Up @@ -188,7 +188,7 @@ module.exports = {
}
return precedence(node) <= precedence(parent);

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error(`Unexpected parent type: ${parent.type}`);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/no-extra-parens.js
Expand Up @@ -634,10 +634,10 @@ module.exports = {

currentNode = currentNode.parent;

/* istanbul ignore if */
/* c8 ignore start */
if (currentNode === null) {
throw new Error("Nodes are not in the ancestor-descendant relationship.");
}
}/* c8 ignore stop */

path.push(currentNode);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-labels.js
Expand Up @@ -98,7 +98,7 @@ module.exports = {
info = info.upper;
}

/* istanbul ignore next: syntax error */
/* c8 ignore next */
return "other";
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-useless-computed-key.js
Expand Up @@ -74,7 +74,7 @@ function hasUselessComputedKey(node) {

return value !== "constructor";

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error(`Unexpected node type: ${node.type}`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-var.js
Expand Up @@ -90,7 +90,7 @@ function getScopeNode(node) {
}
}

/* istanbul ignore next : unreachable */
/* c8 ignore next */
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/padded-blocks.js
Expand Up @@ -186,7 +186,7 @@ module.exports = {
case "ClassBody":
return options.classes;

/* istanbul ignore next */
/* c8 ignore next */
default:
throw new Error("unreachable");
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/prefer-arrow-callback.js
Expand Up @@ -53,7 +53,7 @@ function getVariableOfArguments(scope) {
}
}

/* istanbul ignore next */
/* c8 ignore next */
return null;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ function getCallbackInfo(node) {
parent = parent.parent;
}

/* istanbul ignore next */
/* c8 ignore next */
throw new Error("unreachable");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-rest-params.js
Expand Up @@ -30,7 +30,7 @@ function getVariableOfArguments(scope) {
}
}

/* istanbul ignore next : unreachable */
/* c8 ignore next */
return null;
}

Expand Down
1 change: 0 additions & 1 deletion lib/rules/require-yield.js
Expand Up @@ -68,7 +68,6 @@ module.exports = {
// Increases the count of `yield` keyword.
YieldExpression() {

/* istanbul ignore else */
if (stack.length > 0) {
stack[stack.length - 1] += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/utils/ast-utils.js
Expand Up @@ -1350,7 +1350,7 @@ module.exports = {
}
}

/* istanbul ignore next */
/* c8 ignore next */
return true;
},

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/logging.js
Expand Up @@ -7,7 +7,7 @@

/* eslint no-console: "off" -- Logging util */

/* istanbul ignore next */
/* c8 ignore next */
module.exports = {

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/source-code/token-store/cursor.js
Expand Up @@ -69,7 +69,7 @@ module.exports = class Cursor {
* @returns {boolean} `true` if the next token exists.
* @abstract
*/
/* istanbul ignore next */
/* c8 ignore next */
moveNext() { // eslint-disable-line class-methods-use-this -- Unused
throw new Error("Not implemented.");
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -99,6 +99,7 @@
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"babel-loader": "^8.0.5",
"c8": "^7.12.0",
"chai": "^4.0.1",
"cheerio": "^0.22.0",
"common-tags": "^1.8.0",
Expand Down Expand Up @@ -142,7 +143,6 @@
"mocha-junit-reporter": "^2.0.0",
"node-polyfill-webpack-plugin": "^1.0.3",
"npm-license": "^0.3.3",
"nyc": "^15.0.1",
"pirates": "^4.0.5",
"progress": "^2.0.3",
"proxyquire": "^2.0.1",
Expand Down

0 comments on commit 1c388fb

Please sign in to comment.