Skip to content

Commit 57bd00e

Browse files
authored
Replace nyc with c8 (#1686)
1 parent e910633 commit 57bd00e

27 files changed

+49
-40
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- run: npm install
3737
- run: npm run lint
3838
# Force update snapshots, https://github.com/avajs/ava/discussions/2754
39-
- run: npx nyc ava --update-snapshots
39+
- run: npx c8 ava --update-snapshots
4040
env:
4141
AVA_FORCE_CI: not-ci
4242
- run: npm run generate-rules-table

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules
22
yarn.lock
3-
.nyc_output
43
coverage
54
package-lock.json
65
/test/integration/fixtures

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"run-rules-on-codebase": "node ./test/run-rules-on-codebase/lint.mjs",
3030
"smoke": "eslint-remote-tester --config ./test/smoke/eslint-remote-tester.config.js",
3131
"test": "npm-run-all --continue-on-error lint test:*",
32-
"test:js": "nyc ava"
32+
"test:js": "c8 ava"
3333
},
3434
"files": [
3535
"index.js",
@@ -69,6 +69,7 @@
6969
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
7070
"@typescript-eslint/parser": "^5.7.0",
7171
"ava": "^3.15.0",
72+
"c8": "^7.11.0",
7273
"chalk": "^5.0.0",
7374
"enquirer": "^2.3.6",
7475
"eslint": "^8.6.0",
@@ -83,7 +84,6 @@
8384
"mem": "^9.0.1",
8485
"npm-package-json-lint": "^5.4.2",
8586
"npm-run-all": "^4.1.5",
86-
"nyc": "^15.1.0",
8787
"outdent": "^0.8.0",
8888
"typescript": "^4.5.4",
8989
"vue-eslint-parser": "^8.0.1",
@@ -98,7 +98,7 @@
9898
"test/unit/*.mjs"
9999
]
100100
},
101-
"nyc": {
101+
"c8": {
102102
"reporter": [
103103
"text",
104104
"lcov"

rules/catch-error-name.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const create = context => {
6565

6666
// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1075#issuecomment-768072967
6767
// But can't reproduce, just ignore this case
68-
/* istanbul ignore next */
68+
/* c8 ignore next 3 */
6969
if (!variable) {
7070
return;
7171
}

rules/consistent-function-scoping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ function checkReferences(scope, parent, scopeManager) {
4646
const identifierScope = scopeManager.acquire(identifier);
4747

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

5454
const identifierParentScope = scopeManager.acquire(identifier.parent);
55-
/* istanbul ignore next: Hard to test */
55+
/* c8 ignore next 3 */
5656
if (!identifierParentScope) {
5757
return false;
5858
}

rules/expiring-todo-comments.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ function reachedDate(past) {
192192
}
193193

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

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

223-
/* istanbul ignore if: We don't have this `package.json` to test */
225+
// We don't have this `package.json` to test
226+
/* c8 ignore next 3 */
224227
if (semver.valid(version)) {
225228
return version;
226229
}
@@ -230,7 +233,8 @@ function tryToCoerceVersion(rawVersion) {
230233
// But coerce can't parse pre-releases.
231234
return semver.parse(version) || semver.coerce(version);
232235
} catch {
233-
/* istanbul ignore next: We don't have this `package.json` to test */
236+
// We don't have this `package.json` to test
237+
/* c8 ignore next 3 */
234238
return false;
235239
}
236240
}
@@ -403,11 +407,12 @@ const create = context => {
403407
const todoVersion = tryToCoerceVersion(dependency.version);
404408
const targetPackageVersion = tryToCoerceVersion(targetPackageRawVersion);
405409

406-
/* istanbul ignore if: Can't test in Node.js */
410+
/* c8 ignore start */
407411
if (!hasTargetPackage || !targetPackageVersion) {
408412
// Can't compare `¯\_(ツ)_/¯`
409413
continue;
410414
}
415+
/* c8 ignore end */
411416

412417
const compare = semverComparisonForOperator(dependency.condition);
413418

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

434-
/* istanbul ignore if: Can't test in this repo */
439+
/* c8 ignore next 3 */
435440
if (!hasTargetEngine) {
436441
continue;
437442
}

rules/fix/append-argument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {isCommaToken} = require('eslint-utils');
44
function appendArgument(fixer, node, text, sourceCode) {
55
// This function should also work for `NewExpression`
66
// But parentheses of `NewExpression` could be omitted, add this check to prevent accident use on it
7-
/* istanbul ignore next */
7+
/* c8 ignore next 3 */
88
if (node.type !== 'CallExpression') {
99
throw new Error(`Unexpected node "${node.type}".`);
1010
}

rules/fix/remove-argument.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ function removeArgument(fixer, node, sourceCode) {
1717
}
1818

1919
// If the removed argument is the only argument, the trailing comma must be removed too
20-
/* istanbul ignore next: Not reachable for now */
20+
/* c8 ignore start */
2121
if (callExpression.arguments.length === 1) {
2222
const tokenAfter = sourceCode.getTokenBefore(lastToken);
2323
if (isCommaToken(tokenAfter)) {
2424
end = tokenAfter[1];
2525
}
2626
}
27+
/* c8 ignore end */
2728

2829
return fixer.replaceTextRange([start, end], '');
2930
}

rules/import-style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const getActualAssignmentTargetImportStyles = assignmentTarget => {
9999
// Next line is not test-coverable until unforceable changes to the language
100100
// like an addition of new AST node types usable in `const __HERE__ = foo;`.
101101
// An exotic custom parser or a bug in one could cover it too.
102-
/* istanbul ignore next */
102+
/* c8 ignore next */
103103
return [];
104104
};
105105

rules/no-array-for-each.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ function isFixable(callExpression, {scope, functionInfo, allIdentifiers, context
319319
}
320320

321321
// Check `CallExpression.callee`
322-
/* istanbul ignore next: Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check, keep this just for safety */
322+
// Because of `ChainExpression` wrapper, `foo?.forEach()` is already failed on previous check keep this just for safety
323+
/* c8 ignore next 3 */
323324
if (callExpression.callee.optional) {
324325
return false;
325326
}

rules/no-array-push-push.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getFirstExpression(node, sourceCode) {
3434
}
3535
}
3636

37-
/* istanbul ignore next */
37+
/* c8 ignore next */
3838
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');
3939
}
4040

rules/no-keyword-prefix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function checkObjectPattern(report, node, options) {
5252
const {name, parent} = node;
5353
const keyword = findKeywordPrefix(name, options);
5454

55-
/* istanbul ignore next: Can't find a case to cover this line */
55+
/* c8 ignore next 3 */
5656
if (parent.shorthand && parent.value.left && Boolean(keyword)) {
5757
report(node, keyword);
5858
}

rules/no-static-only-class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function switchClassToObject(node, sourceCode) {
140140

141141
return function * (fixer) {
142142
const classToken = sourceCode.getFirstToken(node);
143-
/* istanbul ignore next */
143+
/* c8 ignore next */
144144
assertToken(classToken, {
145145
expected: {type: 'Keyword', value: 'class'},
146146
ruleId: 'no-static-only-class',

rules/prefer-array-find.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ const hasLowerPrecedence = (node, operator) => (
127127
))
128128
|| node.type === 'ConditionalExpression'
129129
// Lower than `assignment`, should already parenthesized
130-
/* istanbul ignore next */
130+
/* c8 ignore next */
131131
|| node.type === 'AssignmentExpression'
132132
|| node.type === 'YieldExpression'
133133
|| node.type === 'SequenceExpression'
134134
);
135135

136136
const getDestructuringLeftAndRight = node => {
137-
/* istanbul ignore next */
137+
/* c8 ignore next 3 */
138138
if (!node) {
139139
return {};
140140
}

rules/prefer-default-parameters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const create = context => {
152152

153153
// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1122
154154
// But can't reproduce, just ignore this case
155-
/* istanbul ignore next */
155+
/* c8 ignore next 3 */
156156
if (!variable) {
157157
return;
158158
}

rules/prefer-export-from.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function getExported(identifier, context, sourceCode) {
194194
function isVariableUnused(node, context) {
195195
const variables = context.getDeclaredVariables(node);
196196

197-
/* istanbul ignore next */
197+
/* c8 ignore next 3 */
198198
if (variables.length !== 1) {
199199
return false;
200200
}

rules/prefer-keyboard-event-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const getParentByLevel = (node, level) => {
6767
current = current.parent;
6868
}
6969

70-
/* istanbul ignore else */
70+
/* c8 ignore next 3 */
7171
if (level === 0) {
7272
return current;
7373
}

rules/prefer-set-has.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const selector = [
7575
].join('');
7676

7777
const isIncludesCall = node => {
78-
/* istanbul ignore next */
78+
/* c8 ignore next 3 */
7979
if (!node.parent || !node.parent.parent) {
8080
return false;
8181
}
@@ -131,7 +131,7 @@ const create = context => ({
131131

132132
// This was reported https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1075#issuecomment-768073342
133133
// But can't reproduce, just ignore this case
134-
/* istanbul ignore next */
134+
/* c8 ignore next 3 */
135135
if (!variable) {
136136
return;
137137
}

rules/prefer-ternary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const selector = [
2222
const isTernary = node => node && node.type === 'ConditionalExpression';
2323

2424
function getNodeBody(node) {
25-
/* istanbul ignore next */
25+
/* c8 ignore next 3 */
2626
if (!node) {
2727
return;
2828
}

rules/selectors/not-dom-node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const impossibleNodeTypes = [
1414
];
1515

1616
// We might need this later
17-
/* istanbul ignore next */
17+
/* c8 ignore start */
1818
const isNotDomNode = node =>
1919
impossibleNodeTypes.includes(node.type)
2020
|| (node.type === 'Identifier' && node.name === 'undefined');
21+
/* c8 ignore end */
2122

2223
const notDomNodeSelector = node => [
2324
...impossibleNodeTypes.map(type => `[${node}.type!="${type}"]`),

rules/utils/get-builtin-rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
function getBuiltinRule(id) {
44
// TODO: Remove this when we drop support for ESLint 7
55
const eslintVersion = require('eslint/package.json').version;
6-
/* istanbul ignore next */
6+
/* c8 ignore next 3 */
77
if (eslintVersion.startsWith('7.')) {
88
return require(`eslint/lib/rules/${id}`);
99
}

rules/utils/get-key-name.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function getKeyOrPropertyName(keyOrProperty, computed, scope) {
77
return keyOrProperty.name;
88
}
99

10-
/* istanbul ignore next: It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class` */
10+
// It could be `PrivateIdentifier`(ESTree) or `PrivateName`(Babel) when it's in `class`
11+
/* c8 ignore next */
1112
return;
1213
}
1314

rules/utils/is-function-self-used-inside.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Check if `this`, `arguments`, or the function name is used inside of itself.
1414
@returns {boolean}
1515
*/
1616
function isFunctionSelfUsedInside(functionNode, functionScope) {
17-
/* istanbul ignore next */
17+
/* c8 ignore next 3 */
1818
if (functionScope.block !== functionNode) {
1919
throw new Error('"functionScope" should be the scope of "functionNode".');
2020
}

rules/utils/is-same-reference.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ function getStaticPropertyName(node) {
4141
property = node.property;
4242
break;
4343

44-
/* istanbul ignore next: Hard to test */
44+
/* c8 ignore next 2 */
4545
case 'ChainExpression':
4646
return getStaticPropertyName(node.expression);
4747

48-
/* istanbul ignore next: Only reachable when use this to get class/object member key */
48+
// Only reachable when use this to get class/object member key
49+
/* c8 ignore next */
4950
case 'Property':
5051
case 'MethodDefinition':
51-
/* istanbul ignore next */
52+
/* c8 ignore next 2 */
5253
property = node.key;
53-
/* istanbul ignore next */
5454
break;
5555

5656
// No default

rules/utils/rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function wrapFixFunction(fix) {
2424
return;
2525
}
2626

27-
/* istanbul ignore next: Safe */
27+
/* c8 ignore next */
2828
throw error;
2929
}
3030
}

rules/utils/should-add-parentheses-to-logical-expression-child.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Check if parentheses should be added to a `node` when it's used as child of `Log
77
@returns {boolean}
88
*/
99
function shouldAddParenthesesToLogicalExpressionChild(node, {operator, property}) {
10-
/* istanbul ignore next: When operator or property is different, need check `LogicalExpression` operator precedence, not implemented */
10+
// When operator or property is different, need check `LogicalExpression` operator precedence, not implemented
11+
/* c8 ignore next 3 */
1112
if (operator !== '??' || property !== 'left') {
1213
throw new Error('Not supported.');
1314
}

rules/utils/should-add-parentheses-to-member-expression-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function shouldAddParenthesesToMemberExpressionObject(node, sourceCode) {
2626
case 'NewExpression':
2727
return !isNewExpressionWithParentheses(node, sourceCode);
2828
case 'Literal': {
29-
/* istanbul ignore next */
29+
/* c8 ignore next */
3030
if (isDecimalIntegerNode(node)) {
3131
return true;
3232
}

0 commit comments

Comments
 (0)