Skip to content

Commit de4005b

Browse files
authored
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
1 parent b74e3bc commit de4005b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+718
-413
lines changed

.eslintignore

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,14 @@
55
# specifically un-ignore the source code, configuration files, etc.
66
#
77
# First: ignore FILES (not folders!)
8+
/{packages,examples}/**/*.{js,jsx,ts,tsx}
89

9-
/packages/**/*.js
10-
/packages/**/*.jsx
11-
/packages/**/*.ts
12-
/packages/**/*.tsx
13-
14-
/examples/**/*.js
15-
/examples/**/*.jsx
16-
/examples/**/*.ts
17-
/examples/**/*.tsx
1810
#
1911
# Now un-ignore source code, tests, configuration, etc
20-
!/packages/*/src/**
21-
!/packages/*/cypress/**
22-
!/packages/*/test/**
23-
!/packages/codemirror-graphql/resources/**
12+
!/{packages,examples}/*/{src,cypress,resources}/**
13+
2414
!.eslintrc.js
2515
!babel.config.js
26-
!/examples/**/{src,resources,cypress}/*
2716
#
2817
# End of the ignore dance.
2918
#
@@ -33,7 +22,7 @@
3322

3423
# ESLint automatically ignores node_modules _in the root_, so we only need to specify nested node_modules
3524
**/node_modules
36-
/examples/graphiql-cdn/graphiql*
25+
/packages/graphiql/graphiql.*
3726

3827
# Build artifacts
3928
**/flow-typed

.eslintrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868
'no-regex-spaces': 1,
6969
'no-sparse-arrays': 1,
7070
'no-template-curly-in-string': 0,
71-
'no-unexpected-multiline': 1,
71+
'no-unexpected-multiline': 0, // prettier --list-different
7272
'no-unreachable': 1,
7373
'no-unsafe-finally': 1,
7474
'no-unsafe-negation': 1,
@@ -102,7 +102,7 @@ module.exports = {
102102
'no-extra-bind': 1,
103103
'no-extra-label': 1,
104104
'no-fallthrough': 1,
105-
'no-floating-decimal': 1,
105+
'no-floating-decimal': 0, // prettier --list-different
106106
'no-global-assign': 1,
107107
'no-implicit-coercion': 1,
108108
'no-implicit-globals': 0,
@@ -187,7 +187,7 @@ module.exports = {
187187
'id-match': 0,
188188
indent: 0,
189189
'line-comment-position': 0,
190-
'linebreak-style': 1,
190+
'linebreak-style': 0, // prettier --list-different
191191
'lines-around-comment': 0,
192192
'lines-around-directive': 0,
193193
'max-depth': 0,
@@ -246,7 +246,7 @@ module.exports = {
246246
'no-useless-rename': 1,
247247
'no-var': 1,
248248
'object-shorthand': 1,
249-
'prefer-arrow-callback': [1, { allowNamedFunctions: true }],
249+
'prefer-arrow-callback': [0, { allowNamedFunctions: true }], // prettier --list-different
250250
'prefer-const': 1,
251251
'prefer-numeric-literals': 0,
252252
'prefer-rest-params': 0,
@@ -316,7 +316,7 @@ module.exports = {
316316
files: ['*.js', '*.jsx'],
317317
rules: {
318318
// flowtype (https://github.com/gajus/eslint-plugin-flowtype)
319-
'flowtype/boolean-style': 1,
319+
'flowtype/boolean-style': 0, // prettier --list-different
320320
'flowtype/define-flow-type': 1,
321321
'flowtype/no-dupe-keys': 0,
322322
'flowtype/no-primitive-constructor-types': 1,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ As of December 2019 we are officially supporting Windows OS for development tool
102102
3. `yarn build-bundles` - builds webpack bundles that are used for releases
103103
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.
104104
5. `yarn test` - runs all of the above alongside linting and checks, jest mocha Cypress etc.
105-
6. `yarn pretty` - autoformats
105+
6. `yarn format` - autoformats with eslint --fix and prettier
106106
7. `yarn lint` - checks for linting issues
107107
8. `yarn e2e` - runs cypress headlessly against the minified bundle and a local schema server, like in CI.
108108
9. `yarn jest` - runs global jest commands across the entire monorepo; try `yarn jest --watch` or `yarn jest DocExplorer` for example :D

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@
55
"packages/*",
66
"examples/*"
77
],
8+
"lint-staged": {
9+
"*.{js,ts,jsx,tsx,md}": [
10+
"eslint --fix",
11+
"prettier --write"
12+
]
13+
},
814
"husky": {
915
"hooks": {
10-
"pre-commit": "yarn lint",
16+
"pre-commit": "lint-staged",
1117
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
1218
}
1319
},
@@ -23,12 +29,14 @@
2329
"e2e": "yarn workspace graphiql e2e",
2430
"cypress-open": "yarn workspace graphiql cypress-open",
2531
"t": "yarn run testonly",
26-
"lint": "eslint --ext=ts,js,jsx,tsx . || (printf '\\033[33mTry: \\033[7m yarn format \\033[0m\\n' && exit 1)",
27-
"lint-fix": "eslint --ext=ts,js,jsx,tsx . --fix",
32+
"eslint": "eslint --ext=ts,js,jsx,tsx .",
33+
"lint": "yarn eslint && yarn lint-check && yarn pretty-check",
34+
"lint-fix": "yarn eslint --fix",
2835
"lint-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
2936
"check": "flow check --show-all-errors",
3037
"pretty": "node resources/pretty.js",
3138
"pretty-check": "node resources/pretty.js --check",
39+
"format": "yarn eslint --fix && yarn pretty",
3240
"version-release": "lerna version",
3341
"version-prerelease": "lerna version --conventional-prerelease",
3442
"version-graduate": "lerna version --conventional-graduate"
@@ -73,6 +81,7 @@
7381
"jest-environment-jsdom": "^24.8.0",
7482
"jest-environment-jsdom-global": "^1.2.0",
7583
"lerna": "^3.16.4",
84+
"lint-staged": "^10.0.0-beta.8",
7685
"mkdirp": "^0.5.1",
7786
"mocha": "6.1.4",
7887
"prettier": "^1.18.2",

packages/codemirror-graphql/resources/watch.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ function checkFiles(filepaths) {
101101
.then(testSuccess =>
102102
lintFiles(filepaths).then(lintSuccess =>
103103
typecheckStatus().then(
104-
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess
105-
)
106-
)
104+
typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess,
105+
),
106+
),
107107
)
108108
.catch(() => false)
109109
.then(success => {
110110
process.stdout.write(
111-
'\n' + (success ? '' : '\x07') + green(invert('watching...'))
111+
'\n' + (success ? '' : '\x07') + green(invert('watching...')),
112112
);
113113
});
114114
}
@@ -129,7 +129,7 @@ function parseFiles(filepaths) {
129129
srcPath(filepath),
130130
]);
131131
}
132-
})
132+
}),
133133
);
134134
}
135135

@@ -141,8 +141,8 @@ function runTests(filepaths) {
141141
['--reporter', 'progress', '--require', 'resources/mocha-bootload'].concat(
142142
allTests(filepaths)
143143
? filepaths.map(srcPath)
144-
: ['src/**/__tests__/**/*.js']
145-
)
144+
: ['src/**/__tests__/**/*.js'],
145+
),
146146
).catch(() => false);
147147
}
148148

@@ -158,14 +158,14 @@ function lintFiles(filepaths) {
158158
.catch(() => false)
159159
.then(success => {
160160
console.log(
161-
CLEARLINE + ' ' + (success ? CHECK : X) + ' ' + filepath
161+
CLEARLINE + ' ' + (success ? CHECK : X) + ' ' + filepath,
162162
);
163163
return prevSuccess && success;
164164
});
165165
}
166166
return prevSuccess;
167167
}),
168-
Promise.resolve(true)
168+
Promise.resolve(true),
169169
);
170170
}
171171

packages/codemirror-graphql/src/__tests__/hint-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('graphql-hint', () => {
5252
it('attaches a GraphQL hint function with correct mode/hint options', async () => {
5353
const editor = await createEditorWithHint();
5454
expect(editor.getHelpers(editor.getCursor(), 'hint')).to.not.have.lengthOf(
55-
0
55+
0,
5656
);
5757
});
5858

@@ -72,11 +72,11 @@ describe('graphql-hint', () => {
7272
const suggestions = await getHintSuggestions('{ ', { line: 0, ch: 2 });
7373
const fieldConfig = TestSchema.getQueryType().getFields();
7474
const fieldNames = Object.keys(fieldConfig).filter(
75-
name => !fieldConfig[name].isDeprecated
75+
name => !fieldConfig[name].isDeprecated,
7676
);
7777
checkSuggestions(
7878
fieldNames.concat(['__typename', '__schema', '__type']),
79-
suggestions.list
79+
suggestions.list,
8080
);
8181

8282
const fieldTypes = fieldNames.map(name => fieldConfig[name].type);
@@ -85,7 +85,7 @@ describe('graphql-hint', () => {
8585
item =>
8686
item.text !== '__schema' &&
8787
item.text !== '__type' &&
88-
item.text !== '__typename'
88+
item.text !== '__typename',
8989
)
9090
.map(item => item.type);
9191
expect(fieldTypes).to.deep.equal(expectedTypes);
@@ -99,7 +99,7 @@ describe('graphql-hint', () => {
9999
const fieldConfig = TestSchema.getType('First').getFields();
100100
checkSuggestions(
101101
[...Object.keys(fieldConfig), '__typename'],
102-
suggestions.list
102+
suggestions.list,
103103
);
104104
});
105105

@@ -161,7 +161,7 @@ describe('graphql-hint', () => {
161161
it('provides correct directive suggestions on args definitions', async () => {
162162
const suggestions = await getHintSuggestions(
163163
'type Type { field(arg: String @',
164-
{ line: 0, ch: 31 }
164+
{ line: 0, ch: 31 },
165165
);
166166
const directiveNames = ['onArg', 'onAllDefs'];
167167
checkSuggestions(directiveNames, suggestions.list);
@@ -209,23 +209,23 @@ describe('graphql-hint', () => {
209209
ch: 21,
210210
});
211211
const testInputNames = Object.keys(
212-
TestSchema.getType('TestInput').getFields()
212+
TestSchema.getType('TestInput').getFields(),
213213
);
214214
checkSuggestions(testInputNames, suggestions.list);
215215
});
216216

217217
it('provides fragment name suggestion', async () => {
218218
const suggestions = await getHintSuggestions(
219219
'fragment Foo on Test { id } query { ...',
220-
{ line: 0, ch: 40 }
220+
{ line: 0, ch: 40 },
221221
);
222222
checkSuggestions(['Foo'], suggestions.list);
223223
});
224224

225225
it('provides fragment names for fragments defined lower', async () => {
226226
const suggestions = await getHintSuggestions(
227227
'query { ... } fragment Foo on Test { id }',
228-
{ line: 0, ch: 11 }
228+
{ line: 0, ch: 11 },
229229
);
230230
checkSuggestions(['Foo'], suggestions.list);
231231
});
@@ -237,15 +237,15 @@ describe('graphql-hint', () => {
237237
'fragment Baz on Second { name } ' +
238238
'fragment Qux on TestUnion { name } ' +
239239
'fragment Nrf on Test { id }',
240-
{ line: 0, ch: 31 }
240+
{ line: 0, ch: 31 },
241241
);
242242
checkSuggestions(['Bar', 'Baz', 'Qux'], suggestions.list);
243243
});
244244

245245
it('provides correct field name suggestion inside inline fragment', async () => {
246246
const suggestions = await getHintSuggestions(
247247
'fragment Foo on TestUnion { ... on First { ',
248-
{ line: 0, ch: 43 }
248+
{ line: 0, ch: 43 },
249249
);
250250
const fieldNames = Object.keys(TestSchema.getType('First').getFields());
251251
fieldNames.push('__typename');
@@ -255,7 +255,7 @@ describe('graphql-hint', () => {
255255
it('provides correct field name suggestion inside typeless inline fragment', async () => {
256256
const suggestions = await getHintSuggestions(
257257
'fragment Foo on First { ... { ',
258-
{ line: 0, ch: 30 }
258+
{ line: 0, ch: 30 },
259259
);
260260
const fieldNames = Object.keys(TestSchema.getType('First').getFields());
261261
fieldNames.push('__typename');

packages/codemirror-graphql/src/__tests__/lint-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('graphql-lint', () => {
4444
it('attaches a GraphQL lint function with correct mode/lint options', () => {
4545
const editor = createEditorWithLint();
4646
expect(editor.getHelpers(editor.getCursor(), 'lint')).to.not.have.lengthOf(
47-
0
47+
0,
4848
);
4949
});
5050

packages/codemirror-graphql/src/__tests__/mode-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ describe('graphql-mode', () => {
3939

4040
it('parses Relay-style anonymous FragmentDefinitions', () => {
4141
CodeMirror.runMode('fragment on Test { id }', 'graphql', (token, style) =>
42-
expect(style).to.not.equal('invalidchar')
42+
expect(style).to.not.equal('invalidchar'),
4343
);
4444
});
4545

4646
it('parses inline fragments with optional syntax correctly', () => {
4747
CodeMirror.runMode(
4848
'{ ... on OptionalType { name } }',
4949
'graphql',
50-
(token, style) => expect(style).to.not.equal('invalidchar')
50+
(token, style) => expect(style).to.not.equal('invalidchar'),
5151
);
5252

5353
CodeMirror.runMode('{ ... { name } }', 'graphql', (token, style) =>
54-
expect(style).to.not.equal('invalidchar')
54+
expect(style).to.not.equal('invalidchar'),
5555
);
5656

5757
CodeMirror.runMode(
5858
'{ ... @optionalDirective { name } }',
5959
'graphql',
60-
(token, style) => expect(style).to.not.equal('invalidchar')
60+
(token, style) => expect(style).to.not.equal('invalidchar'),
6161
);
6262
});
6363

@@ -88,7 +88,7 @@ describe('graphql-mode', () => {
8888
it('parses schema-kitchen-sink query without invalidchar', () => {
8989
const schemaKitchenSink = readFileSync(
9090
join(__dirname, '/schema-kitchen-sink.graphql'),
91-
{ encoding: 'utf8' }
91+
{ encoding: 'utf8' },
9292
);
9393

9494
CodeMirror.runMode(schemaKitchenSink, 'graphql', (token, style) => {
@@ -110,7 +110,7 @@ describe('graphql-mode', () => {
110110
'graphql',
111111
(token, style) => {
112112
expect(style).to.not.equal('invalidchar');
113-
}
113+
},
114114
);
115115

116116
CodeMirror.runMode(
@@ -124,7 +124,7 @@ describe('graphql-mode', () => {
124124
'graphql',
125125
(token, style) => {
126126
expect(style).to.not.equal('invalidchar');
127-
}
127+
},
128128
);
129129
});
130130
});

packages/codemirror-graphql/src/hint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CodeMirror.registerHelper('hint', 'graphql', (editor, options) => {
3939
schema,
4040
editor.getValue(),
4141
cur,
42-
token
42+
token,
4343
);
4444
/**
4545
* GraphQL language service responds to the autocompletion request with

packages/codemirror-graphql/src/utils/SchemaReference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function getEnumValueReference(typeInfo: any): EnumValueReference {
103103
// though it defaults to the current type.
104104
export function getTypeReference(
105105
typeInfo: any,
106-
type?: GraphQLNamedType
106+
type?: GraphQLNamedType,
107107
): TypeReference {
108108
return {
109109
kind: 'Type',

0 commit comments

Comments
 (0)