Skip to content

Commit

Permalink
Replace nyc with c8 (#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored Jan 12, 2022
1 parent e910633 commit 57bd00e
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- run: npm install
- run: npm run lint
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
- run: npx nyc ava --update-snapshots
- run: npx c8 ava --update-snapshots
env:
AVA_FORCE_CI: not-ci
- run: npm run generate-rules-table
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
yarn.lock
.nyc_output
coverage
package-lock.json
/test/integration/fixtures
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs",
"smoke": "eslint-remote-tester --config ./test/smoke/eslint-remote-tester.config.js",
"test": "npm-run-all --continue-on-error lint test:*",
"test:js": "nyc ava"
"test:js": "c8 ava"
},
"files": [
"index.js",
Expand Down Expand Up @@ -69,6 +69,7 @@
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
"@typescript-eslint/parser": "^5.7.0",
"ava": "^3.15.0",
"c8": "^7.11.0",
"chalk": "^5.0.0",
"enquirer": "^2.3.6",
"eslint": "^8.6.0",
Expand All @@ -83,7 +84,6 @@
"mem": "^9.0.1",
"npm-package-json-lint": "^5.4.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"outdent": "^0.8.0",
"typescript": "^4.5.4",
"vue-eslint-parser": "^8.0.1",
Expand All @@ -98,7 +98,7 @@
"test/unit/*.mjs"
]
},
"nyc": {
"c8": {
"reporter": [
"text",
"lcov"
Expand Down
2 changes: 1 addition & 1 deletion rules/catch-error-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const create = context => {

// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1075#issuecomment-768072967
// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ function checkReferences(scope, parent, scopeManager) {
const identifierScope = scopeManager.acquire(identifier);

// If we have a scope, the earlier checks should have worked so ignore them here
/* istanbul ignore next: Hard to test */
/* c8 ignore next 3 */
if (identifierScope) {
return false;
}

const identifierParentScope = scopeManager.acquire(identifier.parent);
/* istanbul ignore next: Hard to test */
/* c8 ignore next 3 */
if (!identifierParentScope) {
return false;
}
Expand Down
17 changes: 11 additions & 6 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ function reachedDate(past) {
}

function tryToCoerceVersion(rawVersion) {
/* istanbul ignore if: version in `package.json` and comment can't be empty */
// `version` in `package.json` and comment can't be empty
/* c8 ignore next 3 */
if (!rawVersion) {
return false;
}
Expand All @@ -215,12 +216,14 @@ function tryToCoerceVersion(rawVersion) {

// Get only the first member for cases such as `1.0.0 - 2.9999.9999`
const parts = version.split(' ');
/* istanbul ignore if: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
if (parts.length > 1) {
version = parts[0];
}

/* istanbul ignore if: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
if (semver.valid(version)) {
return version;
}
Expand All @@ -230,7 +233,8 @@ function tryToCoerceVersion(rawVersion) {
// But coerce can't parse pre-releases.
return semver.parse(version) || semver.coerce(version);
} catch {
/* istanbul ignore next: We don't have this `package.json` to test */
// We don't have this `package.json` to test
/* c8 ignore next 3 */
return false;
}
}
Expand Down Expand Up @@ -403,11 +407,12 @@ const create = context => {
const todoVersion = tryToCoerceVersion(dependency.version);
const targetPackageVersion = tryToCoerceVersion(targetPackageRawVersion);

/* istanbul ignore if: Can't test in Node.js */
/* c8 ignore start */
if (!hasTargetPackage || !targetPackageVersion) {
// Can't compare `¯\_(ツ)_/¯`
continue;
}
/* c8 ignore end */

const compare = semverComparisonForOperator(dependency.condition);

Expand All @@ -431,7 +436,7 @@ const create = context => {
const targetPackageRawEngineVersion = packageEngines.node;
const hasTargetEngine = Boolean(targetPackageRawEngineVersion);

/* istanbul ignore if: Can't test in this repo */
/* c8 ignore next 3 */
if (!hasTargetEngine) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/fix/append-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {isCommaToken} = require('eslint-utils');
function appendArgument(fixer, node, text, sourceCode) {
// This function should also work for `NewExpression`
// But parentheses of `NewExpression` could be omitted, add this check to prevent accident use on it
/* istanbul ignore next */
/* c8 ignore next 3 */
if (node.type !== 'CallExpression') {
throw new Error(`Unexpected node "${node.type}".`);
}
Expand Down
3 changes: 2 additions & 1 deletion rules/fix/remove-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ function removeArgument(fixer, node, sourceCode) {
}

// If the removed argument is the only argument, the trailing comma must be removed too
/* istanbul ignore next: Not reachable for now */
/* c8 ignore start */
if (callExpression.arguments.length === 1) {
const tokenAfter = sourceCode.getTokenBefore(lastToken);
if (isCommaToken(tokenAfter)) {
end = tokenAfter[1];
}
}
/* c8 ignore end */

return fixer.replaceTextRange([start, end], '');
}
Expand Down
2 changes: 1 addition & 1 deletion rules/import-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const getActualAssignmentTargetImportStyles = assignmentTarget => {
// Next line is not test-coverable until unforceable changes to the language
// like an addition of new AST node types usable in `const __HERE__ = foo;`.
// An exotic custom parser or a bug in one could cover it too.
/* istanbul ignore next */
/* c8 ignore next */
return [];
};

Expand Down
3 changes: 2 additions & 1 deletion rules/no-array-for-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ function isFixable(callExpression, {scope, functionInfo, allIdentifiers, context
}

// Check `CallExpression.callee`
/* istanbul ignore next: Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check, keep this just for safety */
// Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check keep this just for safety
/* c8 ignore next 3 */
if (callExpression.callee.optional) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-array-push-push.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getFirstExpression(node, sourceCode) {
}
}

/* istanbul ignore next */
/* c8 ignore next */
throw new Error('Cannot find the first `Array#push()` call.\nPlease open an issue at https://github.com/sindresorhus/eslint-plugin-unicorn/issues/new?title=%60no-array-push-push%60%3A%20Cannot%20find%20first%20%60push()%60');
}

Expand Down
2 changes: 1 addition & 1 deletion rules/no-keyword-prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function checkObjectPattern(report, node, options) {
const {name, parent} = node;
const keyword = findKeywordPrefix(name, options);

/* istanbul ignore next: Can't find a case to cover this line */
/* c8 ignore next 3 */
if (parent.shorthand && parent.value.left && Boolean(keyword)) {
report(node, keyword);
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-static-only-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function switchClassToObject(node, sourceCode) {

return function * (fixer) {
const classToken = sourceCode.getFirstToken(node);
/* istanbul ignore next */
/* c8 ignore next */
assertToken(classToken, {
expected: {type: 'Keyword', value: 'class'},
ruleId: 'no-static-only-class',
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-array-find.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ const hasLowerPrecedence = (node, operator) => (
))
|| node.type === 'ConditionalExpression'
// Lower than `assignment`, should already parenthesized
/* istanbul ignore next */
/* c8 ignore next */
|| node.type === 'AssignmentExpression'
|| node.type === 'YieldExpression'
|| node.type === 'SequenceExpression'
);

const getDestructuringLeftAndRight = node => {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-default-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const create = context => {

// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1122
// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-export-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function getExported(identifier, context, sourceCode) {
function isVariableUnused(node, context) {
const variables = context.getDeclaredVariables(node);

/* istanbul ignore next */
/* c8 ignore next 3 */
if (variables.length !== 1) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-keyboard-event-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const getParentByLevel = (node, level) => {
current = current.parent;
}

/* istanbul ignore else */
/* c8 ignore next 3 */
if (level === 0) {
return current;
}
Expand Down
4 changes: 2 additions & 2 deletions rules/prefer-set-has.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const selector = [
].join('');

const isIncludesCall = node => {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node.parent || !node.parent.parent) {
return false;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ const create = context => ({

// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1075#issuecomment-768073342
// But can't reproduce, just ignore this case
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!variable) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rules/prefer-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const selector = [
const isTernary = node => node && node.type === 'ConditionalExpression';

function getNodeBody(node) {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (!node) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion rules/selectors/not-dom-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const impossibleNodeTypes = [
];

// We might need this later
/* istanbul ignore next */
/* c8 ignore start */
const isNotDomNode = node =>
impossibleNodeTypes.includes(node.type)
|| (node.type === 'Identifier' && node.name === 'undefined');
/* c8 ignore end */

const notDomNodeSelector = node => [
...impossibleNodeTypes.map(type => `[${node}.type!="${type}"]`),
Expand Down
2 changes: 1 addition & 1 deletion rules/utils/get-builtin-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function getBuiltinRule(id) {
// TODO: Remove this when we drop support for ESLint 7
const eslintVersion = require('eslint/package.json').version;
/* istanbul ignore next */
/* c8 ignore next 3 */
if (eslintVersion.startsWith('7.')) {
return require(`eslint/lib/rules/${id}`);
}
Expand Down
3 changes: 2 additions & 1 deletion rules/utils/get-key-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function getKeyOrPropertyName(keyOrProperty, computed, scope) {
return keyOrProperty.name;
}

/* istanbul ignore next: It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class` */
// It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class`
/* c8 ignore next */
return;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/utils/is-function-self-used-inside.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Check if `this`, `arguments`, or the function name is used inside of itself.
@returns {boolean}
*/
function isFunctionSelfUsedInside(functionNode, functionScope) {
/* istanbul ignore next */
/* c8 ignore next 3 */
if (functionScope.block !== functionNode) {
throw new Error('"functionScope" should be the scope of "functionNode".');
}
Expand Down
8 changes: 4 additions & 4 deletions rules/utils/is-same-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ function getStaticPropertyName(node) {
property = node.property;
break;

/* istanbul ignore next: Hard to test */
/* c8 ignore next 2 */
case 'ChainExpression':
return getStaticPropertyName(node.expression);

/* istanbul ignore next: Only reachable when use this to get class/object member key */
// Only reachable when use this to get class/object member key
/* c8 ignore next */
case 'Property':
case 'MethodDefinition':
/* istanbul ignore next */
/* c8 ignore next 2 */
property = node.key;
/* istanbul ignore next */
break;

// No default
Expand Down
2 changes: 1 addition & 1 deletion rules/utils/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function wrapFixFunction(fix) {
return;
}

/* istanbul ignore next: Safe */
/* c8 ignore next */
throw error;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Check if parentheses should be added to a `node` when it's used as child of `Log
@returns {boolean}
*/
function shouldAddParenthesesToLogicalExpressionChild(node, {operator, property}) {
/* istanbul ignore next: When operator or property is different, need check `LogicalExpression` operator precedence, not implemented */
// When operator or property is different, need check `LogicalExpression` operator precedence, not implemented
/* c8 ignore next 3 */
if (operator !== '??' || property !== 'left') {
throw new Error('Not supported.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function shouldAddParenthesesToMemberExpressionObject(node, sourceCode) {
case 'NewExpression':
return !isNewExpressionWithParentheses(node, sourceCode);
case 'Literal': {
/* istanbul ignore next */
/* c8 ignore next */
if (isDecimalIntegerNode(node)) {
return true;
}
Expand Down

0 comments on commit 57bd00e

Please sign in to comment.