Skip to content

Commit 74ce729

Browse files
Enable linting for istanbul ignore comments (#2565)
1 parent c63d64d commit 74ce729

31 files changed

+63
-47
lines changed

.eslintrc.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins:
99
- graphql-internal
1010
- flowtype
1111
- node
12+
- istanbul
1213
- import
1314

1415
rules:
@@ -67,6 +68,14 @@ rules:
6768
flowtype/space-before-type-colon: off
6869
flowtype/union-intersection-spacing: off
6970

71+
##############################################################################
72+
# `eslint-plugin-istanbul` rule list based on `v0.1.1`
73+
# https://github.com/istanbuljs/eslint-plugin-istanbul#rules
74+
##############################################################################
75+
76+
istanbul/no-ignore-file: error
77+
istanbul/prefer-ignore-reason: error
78+
7079
##############################################################################
7180
# `eslint-plugin-node` rule list based on `v11.1.x`
7281
##############################################################################

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"eslint-plugin-flowtype": "5.1.0",
6060
"eslint-plugin-graphql-internal": "file:./resources/eslint-rules",
6161
"eslint-plugin-import": "2.20.2",
62+
"eslint-plugin-istanbul": "0.1.1",
6263
"eslint-plugin-node": "11.1.0",
6364
"flow-bin": "0.125.1",
6465
"mocha": "7.1.2",

src/__tests__/version-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ describe('Version', () => {
2626
expect(minor).to.be.a('number');
2727
expect(patch).to.be.a('number');
2828

29-
/* istanbul ignore next (Can't be verified on all versions) */
29+
// istanbul ignore next (Can't be verified on all versions)
3030
if (preReleaseTag !== null) {
3131
expect(preReleaseTag).to.be.a('string');
3232
}
3333

3434
expect(
3535
`${major}.${minor}.${patch}` +
36-
/* istanbul ignore next (Can't be verified on all versions) */
36+
// istanbul ignore next (Can't be verified on all versions)
3737
(preReleaseTag !== null ? '-' + preReleaseTag : ''),
3838
).to.equal(version);
3939
});

src/error/GraphQLError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class GraphQLError extends Error {
196196
return;
197197
}
198198

199-
/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
199+
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
200200
if (Error.captureStackTrace) {
201201
Error.captureStackTrace(this, GraphQLError);
202202
} else {

src/execution/execute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export function buildExecutionContext(
311311
return [new GraphQLError('Must provide an operation.')];
312312
}
313313

314-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
314+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
315315
const variableDefinitions = operation.variableDefinitions ?? [];
316316

317317
const coercedVariableValues = getVariableValues(

src/execution/values.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export function getArgumentValues(
170170
): { [argument: string]: mixed, ... } {
171171
const coercedValues = {};
172172

173-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
173+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
174174
const argumentNodes = node.arguments ?? [];
175175
const argNodeMap = keyMap(argumentNodes, (arg) => arg.name.value);
176176

src/jsutils/__tests__/inspect-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ describe('inspect', () => {
3737

3838
it('function', () => {
3939
const unnamedFuncStr = inspect(
40-
/* istanbul ignore next */ () => invariant(false),
40+
// istanbul ignore next (never called and used as a placeholder)
41+
() => invariant(false),
4142
);
4243
expect(unnamedFuncStr).to.equal('[function]');
4344

44-
/* istanbul ignore next */
45+
// istanbul ignore next (never called and used as a placeholder)
4546
function namedFunc() {
4647
invariant(false);
4748
}
@@ -107,7 +108,7 @@ describe('inspect', () => {
107108

108109
it('custom symbol inspect is take precedence', () => {
109110
const object = {
110-
/* istanbul ignore next */
111+
// istanbul ignore next (never called and use just as a placeholder)
111112
inspect() {
112113
invariant(false);
113114
},

src/jsutils/__tests__/isCollection-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('isCollection', () => {
3030
const iterator = { [Symbol.iterator]: identityFunc };
3131
expect(isCollection(iterator)).to.equal(true);
3232

33-
// istanbul ignore next
33+
// istanbul ignore next (never called and use just as a placeholder)
3434
function* generatorFunc() {
3535
/* do nothing */
3636
}

src/jsutils/dedent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function dedent(
2121
for (let i = 0; i < strings.length; ++i) {
2222
str += strings[i];
2323
if (i < values.length) {
24-
/* istanbul ignore next (ignore else inside Babel generated code) */
24+
// istanbul ignore next (ignore else inside Babel generated code)
2525
const value = values[i];
2626

2727
str += value; // interpolation

src/jsutils/defineInspect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function defineInspect(
1414

1515
classObject.prototype.inspect = fn;
1616

17-
/* istanbul ignore else (See: https://github.com/graphql/graphql-js/issues/2317) */
17+
// istanbul ignore else (See: https://github.com/graphql/graphql-js/issues/2317)
1818
if (nodejsCustomInspectSymbol) {
1919
classObject.prototype[nodejsCustomInspectSymbol] = fn;
2020
}

src/jsutils/devAssert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export default function devAssert(condition: mixed, message: string): void {
44
const booleanCondition = Boolean(condition);
5-
/* istanbul ignore else (see transformation done in './resources/inlineInvariant.js') */
5+
// istanbul ignore else (see transformation done in './resources/inlineInvariant.js')
66
if (!booleanCondition) {
77
throw new Error(message);
88
}

src/jsutils/instanceOf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ declare function instanceOf(
1212
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
1313
// See: https://webpack.js.org/guides/production/
1414
export default process.env.NODE_ENV === 'production'
15-
? /* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
15+
? // istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
1616
// eslint-disable-next-line no-shadow
1717
function instanceOf(value: mixed, constructor: mixed) {
1818
return value instanceof constructor;

src/jsutils/invariant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
export default function invariant(condition: mixed, message?: string): void {
44
const booleanCondition = Boolean(condition);
5-
/* istanbul ignore else (see transformation done in './resources/inlineInvariant.js') */
5+
// istanbul ignore else (see transformation done in './resources/inlineInvariant.js')
66
if (!booleanCondition) {
77
throw new Error(
88
message != null ? message : 'Unexpected invariant triggered.',

src/jsutils/nodejsCustomInspectSymbol.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow strict
22

3-
/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
3+
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
44
const nodejsCustomInspectSymbol =
55
typeof Symbol === 'function' && typeof Symbol.for === 'function'
66
? Symbol.for('nodejs.util.inspect.custom')

src/language/__tests__/visitor-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ describe('Visitor', () => {
11321132
return BREAK;
11331133
}
11341134
},
1135-
/* istanbul ignore next */
1135+
// istanbul ignore next (never called and used as a placeholder)
11361136
leave() {
11371137
invariant(false);
11381138
},

src/polyfills/arrayFrom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const arrayFrom =
3232
result.push(mapFn.call(thisArg, step.value, i));
3333
// Infinite Iterators could cause forEach to run forever.
3434
// After a very large number of iterations, produce an error.
35-
/* istanbul ignore if */
35+
// istanbul ignore if (too big to actually test)
3636
if (i > 9999999) {
3737
throw new TypeError('Near-infinite iteration.');
3838
}

src/polyfills/symbols.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// @flow strict
22

33
// In ES2015 (or a polyfilled) environment, this will be Symbol.iterator
4-
/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
4+
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
55
export const SYMBOL_ITERATOR: string =
66
typeof Symbol === 'function' ? Symbol.iterator : '@@iterator';
77

88
// In ES2017 (or a polyfilled) environment, this will be Symbol.asyncIterator
9-
/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
9+
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
1010
export const SYMBOL_ASYNC_ITERATOR: string =
1111
// $FlowFixMe Flow doesn't define `Symbol.asyncIterator` yet
1212
typeof Symbol === 'function' ? Symbol.asyncIterator : '@@asyncIterator';
1313

14-
/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
14+
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
1515
export const SYMBOL_TO_STRING_TAG: string =
1616
// $FlowFixMe Flow doesn't define `Symbol.toStringTag` yet
1717
typeof Symbol === 'function' ? Symbol.toStringTag : '@@toStringTag';

src/subscription/__tests__/mapAsyncIterator-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('mapAsyncIterator', () => {
9696
yield 1;
9797
yield 2;
9898

99-
/* istanbul ignore next (shouldn't be reached) */
99+
// istanbul ignore next (shouldn't be reached)
100100
yield 3;
101101
}
102102

@@ -156,7 +156,7 @@ describe('mapAsyncIterator', () => {
156156
yield 1;
157157
yield 2;
158158

159-
/* istanbul ignore next (shouldn't be reached) */
159+
// istanbul ignore next (shouldn't be reached)
160160
yield 3;
161161
} finally {
162162
yield 'Done';
@@ -223,7 +223,7 @@ describe('mapAsyncIterator', () => {
223223
yield 1;
224224
yield 2;
225225

226-
/* istanbul ignore next (shouldn't be reached) */
226+
// istanbul ignore next (shouldn't be reached)
227227
yield 3;
228228
} catch (e) {
229229
yield e;
@@ -311,7 +311,7 @@ describe('mapAsyncIterator', () => {
311311
yield 1;
312312
yield 2;
313313

314-
/* istanbul ignore next (shouldn't be reached) */
314+
// istanbul ignore next (shouldn't be reached)
315315
yield 3;
316316
} finally {
317317
didVisitFinally = true;

src/subscription/__tests__/subscribe-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ async function createSubscription(
136136
async function expectPromiseToThrow(promise, message) {
137137
try {
138138
await promise();
139-
/* istanbul ignore next */
139+
// istanbul ignore next(shouldn't be reached)
140140
expect.fail('promise should have thrown but did not');
141141
} catch (error) {
142142
expect(error).to.be.an.instanceOf(Error);
@@ -280,7 +280,7 @@ describe('Subscription Initialization Phase', () => {
280280
},
281281
nonImportantEmail: {
282282
type: EmailEventType,
283-
/* istanbul ignore next (shouldn't be called) */
283+
// istanbul ignore next (shouldn't be called)
284284
subscribe() {
285285
didResolveNonImportantEmail = true;
286286
return eventEmitterAsyncIterator(new EventEmitter(), 'event');

src/type/__tests__/definition-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const NonNullScalarType = GraphQLNonNull(ScalarType);
3939
const ListOfNonNullScalarsType = GraphQLList(NonNullScalarType);
4040
const NonNullListOfScalars = GraphQLNonNull(ListOfScalarsType);
4141

42-
/* istanbul ignore next */
42+
// istanbul ignore next (never called and used as a placeholder)
4343
const dummyFunc = () => {
4444
/* empty */
4545
};

src/type/__tests__/introspection-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ describe('Introspection', () => {
14761476
const schema = new GraphQLSchema({ query: QueryRoot });
14771477
const source = getIntrospectionQuery({ directiveIsRepeatable: true });
14781478

1479-
/* istanbul ignore next */
1479+
// istanbul ignore next (called only to fail test)
14801480
function fieldResolver(_1, _2, _3, info) {
14811481
invariant(false, `Called on ${info.parentType.name}::${info.fieldName}`);
14821482
}

src/type/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
588588
object: SDLDefinedObject<T, K>,
589589
getter: (T | K) => ?(L | $ReadOnlyArray<L>),
590590
): $ReadOnlyArray<L> {
591-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
591+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
592592
return flatMap(getAllNodes(object), (item) => getter(item) ?? []);
593593
}
594594

src/utilities/__tests__/stripIgnoredCharacters-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ function lexValue(str) {
6666
return value;
6767
}
6868

69-
// Called only to make error messages for failing tests
70-
/* istanbul ignore next */
69+
// istanbul ignore next (called only to make error messages for failing tests)
7170
function inspectStr(str) {
7271
return (JSON.stringify(str) ?? '')
7372
.replace(/^"|"$/g, '`')

src/utilities/extendSchema.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export function extendSchemaImpl(
415415
|} {
416416
const opTypes = {};
417417
for (const node of nodes) {
418-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
418+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
419419
const operationTypesNodes = node.operationTypes ?? [];
420420

421421
for (const operationType of operationTypesNodes) {
@@ -474,7 +474,7 @@ export function extendSchemaImpl(
474474
): GraphQLFieldConfigMap<mixed, mixed> {
475475
const fieldConfigMap = Object.create(null);
476476
for (const node of nodes) {
477-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
477+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
478478
const nodeFields = node.fields ?? [];
479479

480480
for (const field of nodeFields) {
@@ -496,7 +496,7 @@ export function extendSchemaImpl(
496496
function buildArgumentMap(
497497
args: ?$ReadOnlyArray<InputValueDefinitionNode>,
498498
): GraphQLFieldConfigArgumentMap {
499-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
499+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
500500
const argsNodes = args ?? [];
501501

502502
const argConfigMap = Object.create(null);
@@ -523,7 +523,7 @@ export function extendSchemaImpl(
523523
): GraphQLInputFieldConfigMap {
524524
const inputFieldMap = Object.create(null);
525525
for (const node of nodes) {
526-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
526+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
527527
const fieldsNodes = node.fields ?? [];
528528

529529
for (const field of fieldsNodes) {
@@ -548,7 +548,7 @@ export function extendSchemaImpl(
548548
): GraphQLEnumValueConfigMap {
549549
const enumValueMap = Object.create(null);
550550
for (const node of nodes) {
551-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
551+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
552552
const valuesNodes = node.values ?? [];
553553

554554
for (const value of valuesNodes) {
@@ -572,7 +572,7 @@ export function extendSchemaImpl(
572572
): Array<GraphQLInterfaceType> {
573573
const interfaces = [];
574574
for (const node of nodes) {
575-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
575+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
576576
const interfacesNodes = node.interfaces ?? [];
577577

578578
for (const type of interfacesNodes) {
@@ -591,7 +591,7 @@ export function extendSchemaImpl(
591591
): Array<GraphQLObjectType> {
592592
const types = [];
593593
for (const node of nodes) {
594-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
594+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
595595
const typeNodes = node.types ?? [];
596596

597597
for (const type of typeNodes) {

src/validation/rules/KnownArgumentNamesRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function KnownArgumentNamesOnDirectivesRule(
6464
const astDefinitions = context.getDocument().definitions;
6565
for (const def of astDefinitions) {
6666
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
67-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
67+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
6868
const argsNodes = def.arguments ?? [];
6969

7070
directiveArgs[def.name.value] = argsNodes.map((arg) => arg.name.value);

src/validation/rules/OverlappingFieldsCanBeMergedRule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ function findConflict(
571571
];
572572
}
573573

574-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
574+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
575575
const args1 = node1.arguments ?? [];
576-
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
576+
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
577577
const args2 = node2.arguments ?? [];
578578
// Two field calls must have the same arguments.
579579
if (!sameArguments(args1, args2)) {

0 commit comments

Comments
 (0)