diff --git a/.eslintrc.json b/.eslintrc.json index e5d9433bcf8..9aea2b33d46 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,9 @@ "no-underscore-dangle": 0, "no-console": 0, "no-use-before-define": 0, - "no-unused-vars": 0 + "no-unused-vars": 0, + "import/prefer-default-export": 0, + "no-mixed-operators": 0, + "import/no-extraneous-dependencies": 0 } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 3d9719883c2..fc602bde803 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "scripts": { - "test": "npm run lint && istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter spec --full-trace test/index.js", + "test": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter spec --full-trace test/index.js && npm run lint", "lint": "eslint .", "testonly": "mocha test/index.js", "prepublish": "rm -rf ./dist && babel ./src --ignore test --out-dir ./dist" @@ -48,23 +48,23 @@ "body-parser": "^1.15.0", "chai": "^3.5.0", "dataloader": "^1.1.0", - "eslint": "^2.4.0", - "eslint-config-airbnb": "^9.0.1", + "eslint": "^3.2.2", + "eslint-config-airbnb": "^10.0.0", "eslint-plugin-import": "^1.1.0", - "eslint-plugin-jsx-a11y": "^1.4.2", - "eslint-plugin-react": "^5.1.1", + "eslint-plugin-jsx-a11y": "^2.0.1", + "eslint-plugin-react": "^6.0.0", "express": "^4.13.4", "express3": "0.0.0", "fs": "0.0.2", "graphql": "^0.6.0", "istanbul": "1.0.0-alpha.2", "lodash": "^4.10.0", - "mocha": "^2.3.3", + "mocha": "^3.0.1", "multer": "^1.0.3", "nodemon": "^1.9.1", "request": "^2.72.0", - "request-promise": "^3.0.0", - "supertest": "^1.0.1", + "request-promise": "^4.1.0", + "supertest": "^2.0.0", "supertest-as-promised": "^3.1.0", "webpack": "^1.13.1" } diff --git a/src/mock.js b/src/mock.js index d4a1944b39c..87b9b69dd12 100644 --- a/src/mock.js +++ b/src/mock.js @@ -53,7 +53,7 @@ function addMockFunctionsToSchema({ schema, mocks = {}, preserveResolvers = fals const defaultMockMap = new Map(); defaultMockMap.set('Int', () => Math.round(Math.random() * 200) - 100); - defaultMockMap.set('Float', () => Math.random() * 200 - 100); + defaultMockMap.set('Float', () => (Math.random() * 200) - 100); defaultMockMap.set('String', () => 'Hello World'); defaultMockMap.set('Boolean', () => Math.random() > 0.5); defaultMockMap.set('ID', () => uuid.v4()); @@ -204,7 +204,7 @@ class MockList { mock(root, args, context, info, fieldType, mockTypeFunc) { function randint(low, high) { - return Math.floor(Math.random() * (high - low + 1) + low); + return Math.floor((Math.random() * ((high - low) + 1)) + low); } let arr; if (Array.isArray(this.len)) { diff --git a/src/schemaGenerator.js b/src/schemaGenerator.js index fee8000633c..f1c6f20539a 100644 --- a/src/schemaGenerator.js +++ b/src/schemaGenerator.js @@ -19,6 +19,7 @@ function SchemaError(message) { Error.captureStackTrace(this, this.constructor); this.message = message; } +// eslint-disable-next-line new-parens SchemaError.prototype = new Error; function generateSchema(...args) { @@ -99,13 +100,11 @@ function concatenateTypeDefs(typeDefinitionsAry, functionsCalled = {}) { concatenateTypeDefs(typeDef(), functionsCalled) ); } + } else if (typeof typeDef === 'string') { + resolvedTypeDefinitions.push(typeDef.trim()); } else { - if (typeof typeDef === 'string') { - resolvedTypeDefinitions.push(typeDef.trim()); - } else { - const type = typeof typeDef; - throw new SchemaError(`typeDef array must contain only strings and functions, got ${type}`); - } + const type = typeof typeDef; + throw new SchemaError(`typeDef array must contain only strings and functions, got ${type}`); } }); return uniq(resolvedTypeDefinitions.map((x) => x.trim())).join('\n'); @@ -115,7 +114,7 @@ function buildSchemaFromTypeDefinitions(typeDefinitions) { // TODO: accept only array here, otherwise interfaces get confusing. let myDefinitions = typeDefinitions; if (typeof myDefinitions !== 'string') { - if (! Array.isArray(myDefinitions)) { + if (!Array.isArray(myDefinitions)) { // TODO improve error message and say what type was actually found throw new SchemaError('`typeDefinitions` must be a string or array'); } diff --git a/test/circularSchemaA.js b/test/circularSchemaA.js index 2993f417d76..6dde4920e44 100644 --- a/test/circularSchemaA.js +++ b/test/circularSchemaA.js @@ -1,4 +1,5 @@ import TypeB from './circularSchemaB'; + export default () => [` type TypeA { id: ID diff --git a/test/circularSchemaB.js b/test/circularSchemaB.js index 3d8b992df56..a89a0f078ae 100644 --- a/test/circularSchemaB.js +++ b/test/circularSchemaB.js @@ -1,4 +1,5 @@ import TypeA from './circularSchemaA'; + export default () => [` type TypeB { id: ID diff --git a/test/index.js b/test/index.js index a6035325dcb..f3b4df1bac7 100644 --- a/test/index.js +++ b/test/index.js @@ -4,4 +4,4 @@ require('babel-core/register'); require('babel-polyfill'); // The tests, however, can and should be written with ECMAScript 2015. -require('./tests.js'); +require('./tests'); diff --git a/test/testDiscourseSchema.js b/test/testDiscourseSchema.js index 4881fc7f8e0..44327537830 100644 --- a/test/testDiscourseSchema.js +++ b/test/testDiscourseSchema.js @@ -1,7 +1,7 @@ import { readFile } from 'fs'; -import { makeExecutableSchema } from '../src/schemaGenerator.js'; import { assert } from 'chai'; import { graphql } from 'graphql'; +import { makeExecutableSchema } from '../src/schemaGenerator.js'; import resolveFunctions from './discourse-api/schema.js'; diff --git a/test/testLogger.js b/test/testLogger.js index 6e74643251e..d9f6c72741d 100644 --- a/test/testLogger.js +++ b/test/testLogger.js @@ -1,7 +1,8 @@ -import { makeExecutableSchema } from '../src/schemaGenerator.js'; import { assert } from 'chai'; import { graphql } from 'graphql'; import { Logger } from '../src/Logger.js'; +import { makeExecutableSchema } from '../src/schemaGenerator.js'; + describe('Logger', () => { it('logs the errors', (done) => { diff --git a/test/testMocking.js b/test/testMocking.js index 4760ad9ada0..21cb3a51893 100644 --- a/test/testMocking.js +++ b/test/testMocking.js @@ -1,3 +1,7 @@ +import { expect } from 'chai'; +import { + graphql, +} from 'graphql'; import { addMockFunctionsToSchema, MockList, @@ -7,10 +11,6 @@ import { buildSchemaFromTypeDefinitions, addResolveFunctionsToSchema, } from '../src/schemaGenerator'; -import { expect } from 'chai'; -import { - graphql, - } from 'graphql'; describe('Mock', () => { const shorthand = ` diff --git a/test/testSchemaGenerator.js b/test/testSchemaGenerator.js index 2951a22fc1f..f6abc352f76 100644 --- a/test/testSchemaGenerator.js +++ b/test/testSchemaGenerator.js @@ -1,7 +1,16 @@ // TODO: reduce code repetition in this file. // see https://github.com/apollostack/graphql-tools/issues/26 - +import { assert, expect } from 'chai'; +import { + graphql, + GraphQLInt, + GraphQLObjectType, + GraphQLSchema, +} from 'graphql'; +import { printSchema } from 'graphql/utilities'; +import { Logger } from '../src/Logger.js'; +import TypeA from './circularSchemaA'; import { makeExecutableSchema, SchemaError, @@ -10,11 +19,6 @@ import { attachConnectorsToContext, assertResolveFunctionsPresent, } from '../src/schemaGenerator.js'; -import { assert, expect } from 'chai'; -import { graphql, GraphQLInt, GraphQLObjectType, GraphQLSchema } from 'graphql'; -import { printSchema } from 'graphql/utilities'; -import { Logger } from '../src/Logger.js'; -import TypeA from './circularSchemaA'; const testSchema = ` @@ -85,7 +89,7 @@ describe('generating schema from shorthand', () => { }), SchemaError); }); - it('can generate a schema', (done) => { + it('can generate a schema', () => { const shorthand = ` type BirdSpecies { name: String!, @@ -204,10 +208,9 @@ describe('generating schema from shorthand', () => { const jsSchema = makeExecutableSchema({ typeDefs: shorthand, resolvers: resolve }); const resultPromise = graphql(jsSchema, introspectionQuery); - return resultPromise.then((result) => { - assert.deepEqual(result, solution); - done(); - }); + return resultPromise.then(result => + assert.deepEqual(result, solution) + ); }); it('can generate a schema from an array of types', () => { @@ -275,11 +278,14 @@ describe('generating schema from shorthand', () => { } `, TypeA]; - const jsSchema = makeExecutableSchema({ typeDefs: typeDefAry, resolvers: { - Query: { foo: () => null }, - TypeA: { b: () => null }, - TypeB: { a: () => null }, - } }); + const jsSchema = makeExecutableSchema({ + typeDefs: typeDefAry, + resolvers: { + Query: { foo: () => null }, + TypeA: { b: () => null }, + TypeB: { a: () => null }, + }, + }); expect(jsSchema.getQueryType().name).to.equal('Query'); });