From de4005b0fd486d5d81b50dcdc226f990c181ec4b Mon Sep 17 00:00:00 2001 From: Rikki Schulte Date: Mon, 16 Dec 2019 16:29:27 -0500 Subject: [PATCH] fix: linting issues, trailingCommas: all (#1099) * improve eslinting situation, added extensions for prettier * add trailing commas * simplify lint/fix/check/pretty/pre-commit * lint-staged with yarn eslint --fix, prettier --write * also disable conflicting rules prefer-arrow-callback, multiline, etc --- .eslintignore | 19 +- .eslintrc.js | 10 +- README.md | 2 +- package.json | 15 +- .../codemirror-graphql/resources/watch.js | 18 +- .../src/__tests__/hint-test.js | 24 +- .../src/__tests__/lint-test.js | 2 +- .../src/__tests__/mode-test.js | 14 +- packages/codemirror-graphql/src/hint.js | 2 +- .../src/utils/SchemaReference.js | 2 +- .../src/utils/__tests__/jsonParse-test.js | 6 +- .../codemirror-graphql/src/utils/hintList.js | 6 +- .../src/utils/info-addon.js | 3 +- .../src/utils/jump-addon.js | 2 +- .../src/variables/__tests__/hint-test.js | 24 +- .../src/variables/__tests__/lint-test.js | 8 +- .../codemirror-graphql/src/variables/hint.js | 8 +- .../codemirror-graphql/src/variables/lint.js | 6 +- packages/graphiql/package.json | 13 - packages/graphiql/postcss.config.js | 2 +- packages/graphiql/resources/renderExample.js | 8 +- .../src/components/DocExplorer/SearchBox.js | 4 +- .../components/DocExplorer/SearchResults.js | 4 +- .../src/components/DocExplorer/TypeLink.js | 8 +- .../DocExplorer/__tests__/FieldDoc.spec.js | 10 +- .../DocExplorer/__tests__/TypeDoc.spec.js | 18 +- packages/graphiql/src/components/GraphiQL.js | 46 +-- .../graphiql/src/components/HistoryQuery.js | 8 +- .../graphiql/src/components/QueryHistory.js | 6 +- .../graphiql/src/components/ResultViewer.js | 2 +- .../graphiql/src/components/ToolbarSelect.js | 2 +- .../src/components/__tests__/GraphiQL.spec.js | 76 +++-- packages/graphiql/src/utility/QueryStore.js | 14 +- packages/graphiql/src/utility/StorageAPI.js | 8 +- .../src/utility/__tests__/QueryStore.spec.js | 28 +- .../src/utility/__tests__/StorageAPI.spec.js | 18 +- .../utility/__tests__/getQueryFacts.spec.js | 4 +- packages/graphiql/src/utility/find.js | 2 +- .../src/utility/getSelectedOperationName.js | 2 +- packages/graphiql/src/utility/mergeAst.js | 4 +- .../graphiql/src/utility/onHasCompletion.js | 2 +- .../src/GraphQLLanguageService.ts | 8 +- .../src/getAutocompleteSuggestions.ts | 10 +- .../src/getDiagnostics.ts | 8 +- .../src/getHoverInformation.ts | 14 +- .../src/getOutline.ts | 10 +- .../src/RuleHelpers.ts | 8 +- .../src/Rules.ts | 3 - .../src/GraphQLCache.js | 82 ++--- .../src/GraphQLWatchman.js | 8 +- .../src/Logger.js | 2 +- .../src/MessageProcessor.js | 114 +++---- .../src/__mocks__/MockWatchmanClient.js | 2 +- .../src/__tests__/GraphQLCache-test.js | 20 +- .../src/__tests__/MessageProcessor-test.js | 4 +- .../src/findGraphQLTags.js | 8 +- .../src/startServer.js | 38 +-- .../src/Range.ts | 15 +- .../src/validateWithCustomRules.ts | 5 +- packages/graphql-language-service/src/cli.js | 8 +- .../graphql-language-service/src/client.js | 8 +- resources/pretty.js | 12 +- resources/runTests.js | 2 +- yarn.lock | 282 +++++++++++++++++- 64 files changed, 718 insertions(+), 413 deletions(-) diff --git a/.eslintignore b/.eslintignore index 170cc31418e..83d6bde09ba 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,25 +5,14 @@ # specifically un-ignore the source code, configuration files, etc. # # First: ignore FILES (not folders!) +/{packages,examples}/**/*.{js,jsx,ts,tsx} -/packages/**/*.js -/packages/**/*.jsx -/packages/**/*.ts -/packages/**/*.tsx - -/examples/**/*.js -/examples/**/*.jsx -/examples/**/*.ts -/examples/**/*.tsx # # Now un-ignore source code, tests, configuration, etc -!/packages/*/src/** -!/packages/*/cypress/** -!/packages/*/test/** -!/packages/codemirror-graphql/resources/** +!/{packages,examples}/*/{src,cypress,resources}/** + !.eslintrc.js !babel.config.js -!/examples/**/{src,resources,cypress}/* # # End of the ignore dance. # @@ -33,7 +22,7 @@ # ESLint automatically ignores node_modules _in the root_, so we only need to specify nested node_modules **/node_modules -/examples/graphiql-cdn/graphiql* +/packages/graphiql/graphiql.* # Build artifacts **/flow-typed diff --git a/.eslintrc.js b/.eslintrc.js index f3304a7d693..bcce6cacc32 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,7 +68,7 @@ module.exports = { 'no-regex-spaces': 1, 'no-sparse-arrays': 1, 'no-template-curly-in-string': 0, - 'no-unexpected-multiline': 1, + 'no-unexpected-multiline': 0, // prettier --list-different 'no-unreachable': 1, 'no-unsafe-finally': 1, 'no-unsafe-negation': 1, @@ -102,7 +102,7 @@ module.exports = { 'no-extra-bind': 1, 'no-extra-label': 1, 'no-fallthrough': 1, - 'no-floating-decimal': 1, + 'no-floating-decimal': 0, // prettier --list-different 'no-global-assign': 1, 'no-implicit-coercion': 1, 'no-implicit-globals': 0, @@ -187,7 +187,7 @@ module.exports = { 'id-match': 0, indent: 0, 'line-comment-position': 0, - 'linebreak-style': 1, + 'linebreak-style': 0, // prettier --list-different 'lines-around-comment': 0, 'lines-around-directive': 0, 'max-depth': 0, @@ -246,7 +246,7 @@ module.exports = { 'no-useless-rename': 1, 'no-var': 1, 'object-shorthand': 1, - 'prefer-arrow-callback': [1, { allowNamedFunctions: true }], + 'prefer-arrow-callback': [0, { allowNamedFunctions: true }], // prettier --list-different 'prefer-const': 1, 'prefer-numeric-literals': 0, 'prefer-rest-params': 0, @@ -316,7 +316,7 @@ module.exports = { files: ['*.js', '*.jsx'], rules: { // flowtype (https://github.com/gajus/eslint-plugin-flowtype) - 'flowtype/boolean-style': 1, + 'flowtype/boolean-style': 0, // prettier --list-different 'flowtype/define-flow-type': 1, 'flowtype/no-dupe-keys': 0, 'flowtype/no-primitive-constructor-types': 1, diff --git a/README.md b/README.md index cc0a2864d85..61dec84736a 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ As of December 2019 we are officially supporting Windows OS for development tool 3. `yarn build-bundles` - builds webpack bundles that are used for releases 4. `yarn build-demo` - builds demo projects for netlify; we run this on CI to make sure webpack can consume our project in a standalone project. 5. `yarn test` - runs all of the above alongside linting and checks, jest mocha Cypress etc. -6. `yarn pretty` - autoformats +6. `yarn format` - autoformats with eslint --fix and prettier 7. `yarn lint` - checks for linting issues 8. `yarn e2e` - runs cypress headlessly against the minified bundle and a local schema server, like in CI. 9. `yarn jest` - runs global jest commands across the entire monorepo; try `yarn jest --watch` or `yarn jest DocExplorer` for example :D diff --git a/package.json b/package.json index a0dadbbef47..476a78643f6 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,15 @@ "packages/*", "examples/*" ], + "lint-staged": { + "*.{js,ts,jsx,tsx,md}": [ + "eslint --fix", + "prettier --write" + ] + }, "husky": { "hooks": { - "pre-commit": "yarn lint", + "pre-commit": "lint-staged", "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" } }, @@ -23,12 +29,14 @@ "e2e": "yarn workspace graphiql e2e", "cypress-open": "yarn workspace graphiql cypress-open", "t": "yarn run testonly", - "lint": "eslint --ext=ts,js,jsx,tsx . || (printf '\\033[33mTry: \\033[7m yarn format \\033[0m\\n' && exit 1)", - "lint-fix": "eslint --ext=ts,js,jsx,tsx . --fix", + "eslint": "eslint --ext=ts,js,jsx,tsx .", + "lint": "yarn eslint && yarn lint-check && yarn pretty-check", + "lint-fix": "yarn eslint --fix", "lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check", "check": "flow check --show-all-errors", "pretty": "node resources/pretty.js", "pretty-check": "node resources/pretty.js --check", + "format": "yarn eslint --fix && yarn pretty", "version-release": "lerna version", "version-prerelease": "lerna version --conventional-prerelease", "version-graduate": "lerna version --conventional-graduate" @@ -73,6 +81,7 @@ "jest-environment-jsdom": "^24.8.0", "jest-environment-jsdom-global": "^1.2.0", "lerna": "^3.16.4", + "lint-staged": "^10.0.0-beta.8", "mkdirp": "^0.5.1", "mocha": "6.1.4", "prettier": "^1.18.2", diff --git a/packages/codemirror-graphql/resources/watch.js b/packages/codemirror-graphql/resources/watch.js index 8e56a74fb5c..2c4cb024632 100644 --- a/packages/codemirror-graphql/resources/watch.js +++ b/packages/codemirror-graphql/resources/watch.js @@ -101,14 +101,14 @@ function checkFiles(filepaths) { .then(testSuccess => lintFiles(filepaths).then(lintSuccess => typecheckStatus().then( - typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess - ) - ) + typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess, + ), + ), ) .catch(() => false) .then(success => { process.stdout.write( - '\n' + (success ? '' : '\x07') + green(invert('watching...')) + '\n' + (success ? '' : '\x07') + green(invert('watching...')), ); }); } @@ -129,7 +129,7 @@ function parseFiles(filepaths) { srcPath(filepath), ]); } - }) + }), ); } @@ -141,8 +141,8 @@ function runTests(filepaths) { ['--reporter', 'progress', '--require', 'resources/mocha-bootload'].concat( allTests(filepaths) ? filepaths.map(srcPath) - : ['src/**/__tests__/**/*.js'] - ) + : ['src/**/__tests__/**/*.js'], + ), ).catch(() => false); } @@ -158,14 +158,14 @@ function lintFiles(filepaths) { .catch(() => false) .then(success => { console.log( - CLEARLINE + ' ' + (success ? CHECK : X) + ' ' + filepath + CLEARLINE + ' ' + (success ? CHECK : X) + ' ' + filepath, ); return prevSuccess && success; }); } return prevSuccess; }), - Promise.resolve(true) + Promise.resolve(true), ); } diff --git a/packages/codemirror-graphql/src/__tests__/hint-test.js b/packages/codemirror-graphql/src/__tests__/hint-test.js index 98a86cb6466..1d17336071d 100644 --- a/packages/codemirror-graphql/src/__tests__/hint-test.js +++ b/packages/codemirror-graphql/src/__tests__/hint-test.js @@ -52,7 +52,7 @@ describe('graphql-hint', () => { it('attaches a GraphQL hint function with correct mode/hint options', async () => { const editor = await createEditorWithHint(); expect(editor.getHelpers(editor.getCursor(), 'hint')).to.not.have.lengthOf( - 0 + 0, ); }); @@ -72,11 +72,11 @@ describe('graphql-hint', () => { const suggestions = await getHintSuggestions('{ ', { line: 0, ch: 2 }); const fieldConfig = TestSchema.getQueryType().getFields(); const fieldNames = Object.keys(fieldConfig).filter( - name => !fieldConfig[name].isDeprecated + name => !fieldConfig[name].isDeprecated, ); checkSuggestions( fieldNames.concat(['__typename', '__schema', '__type']), - suggestions.list + suggestions.list, ); const fieldTypes = fieldNames.map(name => fieldConfig[name].type); @@ -85,7 +85,7 @@ describe('graphql-hint', () => { item => item.text !== '__schema' && item.text !== '__type' && - item.text !== '__typename' + item.text !== '__typename', ) .map(item => item.type); expect(fieldTypes).to.deep.equal(expectedTypes); @@ -99,7 +99,7 @@ describe('graphql-hint', () => { const fieldConfig = TestSchema.getType('First').getFields(); checkSuggestions( [...Object.keys(fieldConfig), '__typename'], - suggestions.list + suggestions.list, ); }); @@ -161,7 +161,7 @@ describe('graphql-hint', () => { it('provides correct directive suggestions on args definitions', async () => { const suggestions = await getHintSuggestions( 'type Type { field(arg: String @', - { line: 0, ch: 31 } + { line: 0, ch: 31 }, ); const directiveNames = ['onArg', 'onAllDefs']; checkSuggestions(directiveNames, suggestions.list); @@ -209,7 +209,7 @@ describe('graphql-hint', () => { ch: 21, }); const testInputNames = Object.keys( - TestSchema.getType('TestInput').getFields() + TestSchema.getType('TestInput').getFields(), ); checkSuggestions(testInputNames, suggestions.list); }); @@ -217,7 +217,7 @@ describe('graphql-hint', () => { it('provides fragment name suggestion', async () => { const suggestions = await getHintSuggestions( 'fragment Foo on Test { id } query { ...', - { line: 0, ch: 40 } + { line: 0, ch: 40 }, ); checkSuggestions(['Foo'], suggestions.list); }); @@ -225,7 +225,7 @@ describe('graphql-hint', () => { it('provides fragment names for fragments defined lower', async () => { const suggestions = await getHintSuggestions( 'query { ... } fragment Foo on Test { id }', - { line: 0, ch: 11 } + { line: 0, ch: 11 }, ); checkSuggestions(['Foo'], suggestions.list); }); @@ -237,7 +237,7 @@ describe('graphql-hint', () => { 'fragment Baz on Second { name } ' + 'fragment Qux on TestUnion { name } ' + 'fragment Nrf on Test { id }', - { line: 0, ch: 31 } + { line: 0, ch: 31 }, ); checkSuggestions(['Bar', 'Baz', 'Qux'], suggestions.list); }); @@ -245,7 +245,7 @@ describe('graphql-hint', () => { it('provides correct field name suggestion inside inline fragment', async () => { const suggestions = await getHintSuggestions( 'fragment Foo on TestUnion { ... on First { ', - { line: 0, ch: 43 } + { line: 0, ch: 43 }, ); const fieldNames = Object.keys(TestSchema.getType('First').getFields()); fieldNames.push('__typename'); @@ -255,7 +255,7 @@ describe('graphql-hint', () => { it('provides correct field name suggestion inside typeless inline fragment', async () => { const suggestions = await getHintSuggestions( 'fragment Foo on First { ... { ', - { line: 0, ch: 30 } + { line: 0, ch: 30 }, ); const fieldNames = Object.keys(TestSchema.getType('First').getFields()); fieldNames.push('__typename'); diff --git a/packages/codemirror-graphql/src/__tests__/lint-test.js b/packages/codemirror-graphql/src/__tests__/lint-test.js index 9c86ad03f5e..5ddcb34a806 100644 --- a/packages/codemirror-graphql/src/__tests__/lint-test.js +++ b/packages/codemirror-graphql/src/__tests__/lint-test.js @@ -44,7 +44,7 @@ describe('graphql-lint', () => { it('attaches a GraphQL lint function with correct mode/lint options', () => { const editor = createEditorWithLint(); expect(editor.getHelpers(editor.getCursor(), 'lint')).to.not.have.lengthOf( - 0 + 0, ); }); diff --git a/packages/codemirror-graphql/src/__tests__/mode-test.js b/packages/codemirror-graphql/src/__tests__/mode-test.js index 3fd625d41eb..8ec5554ab97 100644 --- a/packages/codemirror-graphql/src/__tests__/mode-test.js +++ b/packages/codemirror-graphql/src/__tests__/mode-test.js @@ -39,7 +39,7 @@ describe('graphql-mode', () => { it('parses Relay-style anonymous FragmentDefinitions', () => { CodeMirror.runMode('fragment on Test { id }', 'graphql', (token, style) => - expect(style).to.not.equal('invalidchar') + expect(style).to.not.equal('invalidchar'), ); }); @@ -47,17 +47,17 @@ describe('graphql-mode', () => { CodeMirror.runMode( '{ ... on OptionalType { name } }', 'graphql', - (token, style) => expect(style).to.not.equal('invalidchar') + (token, style) => expect(style).to.not.equal('invalidchar'), ); CodeMirror.runMode('{ ... { name } }', 'graphql', (token, style) => - expect(style).to.not.equal('invalidchar') + expect(style).to.not.equal('invalidchar'), ); CodeMirror.runMode( '{ ... @optionalDirective { name } }', 'graphql', - (token, style) => expect(style).to.not.equal('invalidchar') + (token, style) => expect(style).to.not.equal('invalidchar'), ); }); @@ -88,7 +88,7 @@ describe('graphql-mode', () => { it('parses schema-kitchen-sink query without invalidchar', () => { const schemaKitchenSink = readFileSync( join(__dirname, '/schema-kitchen-sink.graphql'), - { encoding: 'utf8' } + { encoding: 'utf8' }, ); CodeMirror.runMode(schemaKitchenSink, 'graphql', (token, style) => { @@ -110,7 +110,7 @@ describe('graphql-mode', () => { 'graphql', (token, style) => { expect(style).to.not.equal('invalidchar'); - } + }, ); CodeMirror.runMode( @@ -124,7 +124,7 @@ describe('graphql-mode', () => { 'graphql', (token, style) => { expect(style).to.not.equal('invalidchar'); - } + }, ); }); }); diff --git a/packages/codemirror-graphql/src/hint.js b/packages/codemirror-graphql/src/hint.js index 9519225cf76..2c0c486c28b 100644 --- a/packages/codemirror-graphql/src/hint.js +++ b/packages/codemirror-graphql/src/hint.js @@ -39,7 +39,7 @@ CodeMirror.registerHelper('hint', 'graphql', (editor, options) => { schema, editor.getValue(), cur, - token + token, ); /** * GraphQL language service responds to the autocompletion request with diff --git a/packages/codemirror-graphql/src/utils/SchemaReference.js b/packages/codemirror-graphql/src/utils/SchemaReference.js index 2ec4c5888c2..a04501d3da0 100644 --- a/packages/codemirror-graphql/src/utils/SchemaReference.js +++ b/packages/codemirror-graphql/src/utils/SchemaReference.js @@ -103,7 +103,7 @@ export function getEnumValueReference(typeInfo: any): EnumValueReference { // though it defaults to the current type. export function getTypeReference( typeInfo: any, - type?: GraphQLNamedType + type?: GraphQLNamedType, ): TypeReference { return { kind: 'Type', diff --git a/packages/codemirror-graphql/src/utils/__tests__/jsonParse-test.js b/packages/codemirror-graphql/src/utils/__tests__/jsonParse-test.js index 342098cabb7..934c2e3e298 100644 --- a/packages/codemirror-graphql/src/utils/__tests__/jsonParse-test.js +++ b/packages/codemirror-graphql/src/utils/__tests__/jsonParse-test.js @@ -23,17 +23,17 @@ describe('jsonParse', () => { checkEscapedString( '{ "test": "\\"" }', { kind: 'String', start: 2, end: 8, value: 'test' }, - { kind: 'String', start: 10, end: 14, value: '"' } + { kind: 'String', start: 10, end: 14, value: '"' }, ); checkEscapedString( '{ "test": "\\\\" }', { kind: 'String', start: 2, end: 8, value: 'test' }, - { kind: 'String', start: 10, end: 14, value: '\\' } + { kind: 'String', start: 10, end: 14, value: '\\' }, ); checkEscapedString( '{ "slash": "\\/" }', { kind: 'String', start: 2, end: 9, value: 'slash' }, - { kind: 'String', start: 11, end: 15, value: '/' } + { kind: 'String', start: 11, end: 15, value: '/' }, ); }); }); diff --git a/packages/codemirror-graphql/src/utils/hintList.js b/packages/codemirror-graphql/src/utils/hintList.js index fedd10cc791..7aeb4765e03 100644 --- a/packages/codemirror-graphql/src/utils/hintList.js +++ b/packages/codemirror-graphql/src/utils/hintList.js @@ -40,14 +40,14 @@ function filterAndSortList(list, text) { const conciseMatches = filterNonEmpty( filterNonEmpty(byProximity, pair => pair.proximity <= 2), - pair => !pair.entry.isDeprecated + pair => !pair.entry.isDeprecated, ); const sortedMatches = conciseMatches.sort( (a, b) => (a.entry.isDeprecated ? 1 : 0) - (b.entry.isDeprecated ? 1 : 0) || a.proximity - b.proximity || - a.entry.text.length - b.entry.text.length + a.entry.text.length - b.entry.text.length, ); return sortedMatches.map(pair => pair.entry); @@ -113,7 +113,7 @@ function lexicalDistance(a, b) { d[i][j] = Math.min( d[i - 1][j] + 1, d[i][j - 1] + 1, - d[i - 1][j - 1] + cost + d[i - 1][j - 1] + cost, ); if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) { diff --git a/packages/codemirror-graphql/src/utils/info-addon.js b/packages/codemirror-graphql/src/utils/info-addon.js index 2ed8a70e651..067734e776f 100644 --- a/packages/codemirror-graphql/src/utils/info-addon.js +++ b/packages/codemirror-graphql/src/utils/info-addon.js @@ -69,10 +69,9 @@ function onMouseOver(cm, e) { onMouseHover(cm, box); }; - const hoverTime = getHoverTime(cm); state.hoverTimeout = setTimeout(onHover, hoverTime); - + CodeMirror.on(document, 'mousemove', onMouseMove); CodeMirror.on(cm.getWrapperElement(), 'mouseout', onMouseOut); } diff --git a/packages/codemirror-graphql/src/utils/jump-addon.js b/packages/codemirror-graphql/src/utils/jump-addon.js index 350f9def20f..e4f006068cc 100644 --- a/packages/codemirror-graphql/src/utils/jump-addon.js +++ b/packages/codemirror-graphql/src/utils/jump-addon.js @@ -134,7 +134,7 @@ function enableJumpMode(cm) { const marker = cm.markText( { line: pos.line, ch: token.start }, { line: pos.line, ch: token.end }, - { className: 'CodeMirror-jump-token' } + { className: 'CodeMirror-jump-token' }, ); cm.state.jump.marker = marker; diff --git a/packages/codemirror-graphql/src/variables/__tests__/hint-test.js b/packages/codemirror-graphql/src/variables/__tests__/hint-test.js index 23f082dc0ab..ee98c590624 100644 --- a/packages/codemirror-graphql/src/variables/__tests__/hint-test.js +++ b/packages/codemirror-graphql/src/variables/__tests__/hint-test.js @@ -54,7 +54,7 @@ describe('graphql-variables-hint', () => { it('attaches a GraphQL hint function with correct mode/hint options', async () => { const editor = await createEditorWithHint('{ f }'); expect(editor.getHelpers(editor.getCursor(), 'hint')).to.not.have.lengthOf( - 0 + 0, ); }); @@ -68,7 +68,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($foo: String!, $bar: Int) { f }', '{ ', - { line: 0, ch: 2 } + { line: 0, ch: 2 }, ); checkSuggestions(['"foo": ', '"bar": '], suggestions.list); }); @@ -77,7 +77,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($foo: String!, $bar: Int) { f }', '{\n ', - { line: 1, ch: 2 } + { line: 1, ch: 2 }, ); expect(suggestions.from).to.deep.equal({ line: 1, ch: 2, sticky: null }); expect(suggestions.to).to.deep.equal({ line: 1, ch: 2, sticky: null }); @@ -87,7 +87,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($foo: String!, $bar: Int) { f }', '{\n ba', - { line: 1, ch: 4 } + { line: 1, ch: 4 }, ); checkSuggestions(['"bar": '], suggestions.list); expect(suggestions.from).to.deep.equal({ line: 1, ch: 2, sticky: null }); @@ -98,7 +98,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($foo: String!, $bar: Int) { f }', '{\n "', - { line: 1, ch: 4 } + { line: 1, ch: 4 }, ); checkSuggestions(['"foo": ', '"bar": '], suggestions.list); expect(suggestions.from).to.deep.equal({ line: 1, ch: 2, sticky: null }); @@ -109,12 +109,12 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($myEnum: TestEnum) { f }', '{\n "myEnum": ', - { line: 1, ch: 12 } + { line: 1, ch: 12 }, ); const TestEnum = TestSchema.getType('TestEnum'); checkSuggestions( TestEnum.getValues().map(value => `"${value.name}"`), - suggestions.list + suggestions.list, ); }); @@ -122,7 +122,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($myInput: TestInput) { f }', '{\n "myInput": ', - { line: 1, ch: 13 } + { line: 1, ch: 13 }, ); checkSuggestions(['{'], suggestions.list); }); @@ -131,12 +131,12 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($myInput: TestInput) { f }', '{\n "myInput": {\n ', - { line: 2, ch: 4 } + { line: 2, ch: 4 }, ); const TestInput = TestSchema.getType('TestInput'); checkSuggestions( Object.keys(TestInput.getFields()).map(name => `"${name}": `), - suggestions.list + suggestions.list, ); expect(suggestions.from).to.deep.equal({ line: 2, ch: 4, sticky: null }); expect(suggestions.to).to.deep.equal({ line: 2, ch: 4, sticky: null }); @@ -146,7 +146,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($myInput: TestInput) { f }', '{\n "myInput": {\n bool', - { line: 2, ch: 8 } + { line: 2, ch: 8 }, ); checkSuggestions(['"boolean": ', '"listBoolean": '], suggestions.list); expect(suggestions.from).to.deep.equal({ line: 2, ch: 4, sticky: null }); @@ -157,7 +157,7 @@ describe('graphql-variables-hint', () => { const suggestions = await getHintSuggestions( 'query ($myInput: TestInput) { f }', '{\n "myInput": {\n "boolean": ', - { line: 2, ch: 15 } + { line: 2, ch: 15 }, ); checkSuggestions(['true', 'false'], suggestions.list); }); diff --git a/packages/codemirror-graphql/src/variables/__tests__/lint-test.js b/packages/codemirror-graphql/src/variables/__tests__/lint-test.js index 05d2edf1eaa..ab0c7b02a1f 100644 --- a/packages/codemirror-graphql/src/variables/__tests__/lint-test.js +++ b/packages/codemirror-graphql/src/variables/__tests__/lint-test.js @@ -46,20 +46,20 @@ describe('graphql-variables-lint', () => { it('attaches a GraphQL lint function with correct mode/lint options', () => { const editor = createEditorWithLint(); expect(editor.getHelpers(editor.getCursor(), 'lint')).to.not.have.lengthOf( - 0 + 0, ); }); it('catches syntax errors', async () => { expect((await printLintErrors(null, '{ foo: "bar" }'))[0].message).to.equal( - 'Expected String but found `foo`.' + 'Expected String but found `foo`.', ); }); it('catches type validation errors', async () => { const errors = await printLintErrors( 'query ($foo: Int) { f }', - ' { "foo": "NaN" }' + ' { "foo": "NaN" }', ); expect(errors[0]).to.deep.equal({ @@ -74,7 +74,7 @@ describe('graphql-variables-lint', () => { it('reports unknown variable names', async () => { const errors = await printLintErrors( 'query ($foo: Int) { f }', - ' { "food": "NaN" }' + ' { "food": "NaN" }', ); expect(errors[0]).to.deep.equal({ diff --git a/packages/codemirror-graphql/src/variables/hint.js b/packages/codemirror-graphql/src/variables/hint.js index 6fbe68befac..c5ef86e781e 100644 --- a/packages/codemirror-graphql/src/variables/hint.js +++ b/packages/codemirror-graphql/src/variables/hint.js @@ -80,7 +80,7 @@ function getVariablesHint(cur, token, options) { variableNames.map(name => ({ text: `"${name}": `, type: variableToType[name], - })) + })), ); } @@ -88,7 +88,7 @@ function getVariablesHint(cur, token, options) { if (kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) { if (typeInfo.fields) { const inputFields = Object.keys(typeInfo.fields).map( - fieldName => typeInfo.fields[fieldName] + fieldName => typeInfo.fields[fieldName], ); return hintList( cur, @@ -97,7 +97,7 @@ function getVariablesHint(cur, token, options) { text: `"${field.name}": `, type: field.type, description: field.description, - })) + })), ); } } @@ -125,7 +125,7 @@ function getVariablesHint(cur, token, options) { text: `"${value.name}"`, type: namedInputType, description: value.description, - })) + })), ); } else if (namedInputType === GraphQLBoolean) { return hintList(cur, token, [ diff --git a/packages/codemirror-graphql/src/variables/lint.js b/packages/codemirror-graphql/src/variables/lint.js index e3a3a530c76..1761783bbf5 100644 --- a/packages/codemirror-graphql/src/variables/lint.js +++ b/packages/codemirror-graphql/src/variables/lint.js @@ -58,7 +58,7 @@ CodeMirror.registerHelper( // Then highlight any issues with the provided variables. return validateVariables(editor, variableToType, ast); - } + }, ); // Given a variableToType object, a source text, and a JSON AST, produces a @@ -74,8 +74,8 @@ function validateVariables(editor, variableToType, variablesAST) { lintError( editor, member.key, - `Variable "$${variableName}" does not appear in any GraphQL query.` - ) + `Variable "$${variableName}" does not appear in any GraphQL query.`, + ), ); } else { validateValue(type, member.value).forEach(([node, message]) => { diff --git a/packages/graphiql/package.json b/packages/graphiql/package.json index 2809ce93f4d..84f2e6993b4 100644 --- a/packages/graphiql/package.json +++ b/packages/graphiql/package.json @@ -21,13 +21,6 @@ "graphiql.css", "graphiql.min.css" ], - "nyc": { - "report-dir": "coverage/cypress", - "reporter": [ - "lcov", - "json" - ] - }, "scripts": { "webpack": "webpack --config resources/webpack.config.js", "analyze-bundle": "cross-env NODE_ENV=production CDN=1 ANALYZE=1 yarn webpack -p", @@ -47,12 +40,6 @@ "e2e-server": "start-server-and-test 'cross-env PORT=8080 node test/e2e-server' 'http-get://localhost:8080/graphql?query={test { id }}'", "test": "cross-env ENZYME=true node ../../resources/runTests" }, - "lint-staged": { - "*.js": [ - "prettier --write", - "git add" - ] - }, "dependencies": { "codemirror": "^5.47.0", "codemirror-graphql": "^0.11.6", diff --git a/packages/graphiql/postcss.config.js b/packages/graphiql/postcss.config.js index 69dc9024021..dea966bec86 100644 --- a/packages/graphiql/postcss.config.js +++ b/packages/graphiql/postcss.config.js @@ -1,4 +1,4 @@ -module.exports = ({ file, options, env }) => ({ +module.exports = ({ file, options }) => ({ plugins: { 'postcss-import': { root: file.dirname }, // contains autoprefixer, etc diff --git a/packages/graphiql/resources/renderExample.js b/packages/graphiql/resources/renderExample.js index e8398a3df8f..0132d235e48 100644 --- a/packages/graphiql/resources/renderExample.js +++ b/packages/graphiql/resources/renderExample.js @@ -17,7 +17,7 @@ search var eq = entry.indexOf('='); if (eq >= 0) { parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent( - entry.slice(eq + 1) + entry.slice(eq + 1), ); } }); @@ -28,7 +28,7 @@ if (parameters.variables) { parameters.variables = JSON.stringify( JSON.parse(parameters.variables), null, - 2 + 2, ); } catch (e) { // Do nothing, we want to display the invalid JSON as a string, rather @@ -77,7 +77,7 @@ function graphQLFetcher(graphQLParams) { // In a PR preview, it connects to the Star Wars API externally. // Change this to point wherever you host your GraphQL server. const isDev = !window.location.hostname.match( - /(^|\.)netlify\.com$|(^|\.)graphql\.org$/ + /(^|\.)netlify\.com$|(^|\.)graphql\.org$/, ); const api = isDev ? '/graphql' : 'https://swapi.graph.cool/'; return fetch(api, { @@ -116,5 +116,5 @@ ReactDOM.render( defaultVariableEditorOpen: true, onEditOperationName: onEditOperationName, }), - document.getElementById('graphiql') + document.getElementById('graphiql'), ); diff --git a/packages/graphiql/src/components/DocExplorer/SearchBox.js b/packages/graphiql/src/components/DocExplorer/SearchBox.js index 1d0b7dd5b8d..2bf6581403c 100644 --- a/packages/graphiql/src/components/DocExplorer/SearchBox.js +++ b/packages/graphiql/src/components/DocExplorer/SearchBox.js @@ -26,7 +26,9 @@ export default class SearchBox extends React.Component { render() { return (