Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linting for istanbul ignore comments #2565

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins:
- graphql-internal
- flowtype
- node
- istanbul
- import

rules:
Expand Down Expand Up @@ -67,6 +68,14 @@ rules:
flowtype/space-before-type-colon: off
flowtype/union-intersection-spacing: off

##############################################################################
# `eslint-plugin-istanbul` rule list based on `v0.1.1`
# https://github.com/istanbuljs/eslint-plugin-istanbul#rules
##############################################################################

istanbul/no-ignore-file: error
istanbul/prefer-ignore-reason: error

##############################################################################
# `eslint-plugin-node` rule list based on `v11.1.x`
##############################################################################
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"eslint-plugin-flowtype": "5.1.0",
"eslint-plugin-graphql-internal": "file:./resources/eslint-rules",
"eslint-plugin-import": "2.20.2",
"eslint-plugin-istanbul": "0.1.1",
"eslint-plugin-node": "11.1.0",
"flow-bin": "0.125.1",
"mocha": "7.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ describe('Version', () => {
expect(minor).to.be.a('number');
expect(patch).to.be.a('number');

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

expect(
`${major}.${minor}.${patch}` +
/* istanbul ignore next (Can't be verified on all versions) */
// istanbul ignore next (Can't be verified on all versions)
(preReleaseTag !== null ? '-' + preReleaseTag : ''),
).to.equal(version);
});
Expand Down
2 changes: 1 addition & 1 deletion src/error/GraphQLError.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class GraphQLError extends Error {
return;
}

/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, GraphQLError);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export function buildExecutionContext(
return [new GraphQLError('Must provide an operation.')];
}

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

const coercedVariableValues = getVariableValues(
Expand Down
2 changes: 1 addition & 1 deletion src/execution/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function getArgumentValues(
): { [argument: string]: mixed, ... } {
const coercedValues = {};

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

Expand Down
7 changes: 4 additions & 3 deletions src/jsutils/__tests__/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ describe('inspect', () => {

it('function', () => {
const unnamedFuncStr = inspect(
/* istanbul ignore next */ () => invariant(false),
// istanbul ignore next (never called and used as a placeholder)
() => invariant(false),
);
expect(unnamedFuncStr).to.equal('[function]');

/* istanbul ignore next */
// istanbul ignore next (never called and used as a placeholder)
function namedFunc() {
invariant(false);
}
Expand Down Expand Up @@ -107,7 +108,7 @@ describe('inspect', () => {

it('custom symbol inspect is take precedence', () => {
const object = {
/* istanbul ignore next */
// istanbul ignore next (never called and use just as a placeholder)
inspect() {
invariant(false);
},
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/__tests__/isCollection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('isCollection', () => {
const iterator = { [Symbol.iterator]: identityFunc };
expect(isCollection(iterator)).to.equal(true);

// istanbul ignore next
// istanbul ignore next (never called and use just as a placeholder)
function* generatorFunc() {
/* do nothing */
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/dedent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function dedent(
for (let i = 0; i < strings.length; ++i) {
str += strings[i];
if (i < values.length) {
/* istanbul ignore next (ignore else inside Babel generated code) */
// istanbul ignore next (ignore else inside Babel generated code)
const value = values[i];

str += value; // interpolation
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/defineInspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function defineInspect(

classObject.prototype.inspect = fn;

/* istanbul ignore else (See: https://github.com/graphql/graphql-js/issues/2317) */
// istanbul ignore else (See: https://github.com/graphql/graphql-js/issues/2317)
if (nodejsCustomInspectSymbol) {
classObject.prototype[nodejsCustomInspectSymbol] = fn;
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/devAssert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export default function devAssert(condition: mixed, message: string): void {
const booleanCondition = Boolean(condition);
/* istanbul ignore else (see transformation done in './resources/inlineInvariant.js') */
// istanbul ignore else (see transformation done in './resources/inlineInvariant.js')
if (!booleanCondition) {
throw new Error(message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/instanceOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare function instanceOf(
// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
// See: https://webpack.js.org/guides/production/
export default process.env.NODE_ENV === 'production'
? /* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
? // istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
// eslint-disable-next-line no-shadow
function instanceOf(value: mixed, constructor: mixed) {
return value instanceof constructor;
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/invariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export default function invariant(condition: mixed, message?: string): void {
const booleanCondition = Boolean(condition);
/* istanbul ignore else (see transformation done in './resources/inlineInvariant.js') */
// istanbul ignore else (see transformation done in './resources/inlineInvariant.js')
if (!booleanCondition) {
throw new Error(
message != null ? message : 'Unexpected invariant triggered.',
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/nodejsCustomInspectSymbol.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow strict

/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
const nodejsCustomInspectSymbol =
typeof Symbol === 'function' && typeof Symbol.for === 'function'
? Symbol.for('nodejs.util.inspect.custom')
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/visitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ describe('Visitor', () => {
return BREAK;
}
},
/* istanbul ignore next */
// istanbul ignore next (never called and used as a placeholder)
leave() {
invariant(false);
},
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/arrayFrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const arrayFrom =
result.push(mapFn.call(thisArg, step.value, i));
// Infinite Iterators could cause forEach to run forever.
// After a very large number of iterations, produce an error.
/* istanbul ignore if */
// istanbul ignore if (too big to actually test)
if (i > 9999999) {
throw new TypeError('Near-infinite iteration.');
}
Expand Down
6 changes: 3 additions & 3 deletions src/polyfills/symbols.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// @flow strict

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

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

/* istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317) */
// istanbul ignore next (See: https://github.com/graphql/graphql-js/issues/2317)
export const SYMBOL_TO_STRING_TAG: string =
// $FlowFixMe Flow doesn't define `Symbol.toStringTag` yet
typeof Symbol === 'function' ? Symbol.toStringTag : '@@toStringTag';
8 changes: 4 additions & 4 deletions src/subscription/__tests__/mapAsyncIterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('mapAsyncIterator', () => {
yield 1;
yield 2;

/* istanbul ignore next (shouldn't be reached) */
// istanbul ignore next (shouldn't be reached)
yield 3;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ describe('mapAsyncIterator', () => {
yield 1;
yield 2;

/* istanbul ignore next (shouldn't be reached) */
// istanbul ignore next (shouldn't be reached)
yield 3;
} finally {
yield 'Done';
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('mapAsyncIterator', () => {
yield 1;
yield 2;

/* istanbul ignore next (shouldn't be reached) */
// istanbul ignore next (shouldn't be reached)
yield 3;
} catch (e) {
yield e;
Expand Down Expand Up @@ -311,7 +311,7 @@ describe('mapAsyncIterator', () => {
yield 1;
yield 2;

/* istanbul ignore next (shouldn't be reached) */
// istanbul ignore next (shouldn't be reached)
yield 3;
} finally {
didVisitFinally = true;
Expand Down
4 changes: 2 additions & 2 deletions src/subscription/__tests__/subscribe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function createSubscription(
async function expectPromiseToThrow(promise, message) {
try {
await promise();
/* istanbul ignore next */
// istanbul ignore next(shouldn't be reached)
expect.fail('promise should have thrown but did not');
} catch (error) {
expect(error).to.be.an.instanceOf(Error);
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('Subscription Initialization Phase', () => {
},
nonImportantEmail: {
type: EmailEventType,
/* istanbul ignore next (shouldn't be called) */
// istanbul ignore next (shouldn't be called)
subscribe() {
didResolveNonImportantEmail = true;
return eventEmitterAsyncIterator(new EventEmitter(), 'event');
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const NonNullScalarType = GraphQLNonNull(ScalarType);
const ListOfNonNullScalarsType = GraphQLList(NonNullScalarType);
const NonNullListOfScalars = GraphQLNonNull(ListOfScalarsType);

/* istanbul ignore next */
// istanbul ignore next (never called and used as a placeholder)
const dummyFunc = () => {
/* empty */
};
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/introspection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ describe('Introspection', () => {
const schema = new GraphQLSchema({ query: QueryRoot });
const source = getIntrospectionQuery({ directiveIsRepeatable: true });

/* istanbul ignore next */
// istanbul ignore next (called only to fail test)
function fieldResolver(_1, _2, _3, info) {
invariant(false, `Called on ${info.parentType.name}::${info.fieldName}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/type/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function getAllSubNodes<T: ASTNode, K: ASTNode, L: ASTNode>(
object: SDLDefinedObject<T, K>,
getter: (T | K) => ?(L | $ReadOnlyArray<L>),
): $ReadOnlyArray<L> {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
return flatMap(getAllNodes(object), (item) => getter(item) ?? []);
}

Expand Down
3 changes: 1 addition & 2 deletions src/utilities/__tests__/stripIgnoredCharacters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ function lexValue(str) {
return value;
}

// Called only to make error messages for failing tests
/* istanbul ignore next */
// istanbul ignore next (called only to make error messages for failing tests)
function inspectStr(str) {
return (JSON.stringify(str) ?? '')
.replace(/^"|"$/g, '`')
Expand Down
14 changes: 7 additions & 7 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export function extendSchemaImpl(
|} {
const opTypes = {};
for (const node of nodes) {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
const operationTypesNodes = node.operationTypes ?? [];

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

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

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

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

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

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

for (const type of typeNodes) {
Expand Down
2 changes: 1 addition & 1 deletion src/validation/rules/KnownArgumentNamesRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function KnownArgumentNamesOnDirectivesRule(
const astDefinitions = context.getDocument().definitions;
for (const def of astDefinitions) {
if (def.kind === Kind.DIRECTIVE_DEFINITION) {
/* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */
// istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203)
const argsNodes = def.arguments ?? [];

directiveArgs[def.name.value] = argsNodes.map((arg) => arg.name.value);
Expand Down
4 changes: 2 additions & 2 deletions src/validation/rules/OverlappingFieldsCanBeMergedRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ function findConflict(
];
}

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