Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b87ca3b

Browse files
committed
Fix lint errors
1 parent 615561c commit b87ca3b

3 files changed

Lines changed: 52 additions & 53 deletions

File tree

script/graphql/build-changelog.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { diff, ChangeType } = require('@graphql-inspector/core')
22
const { loadSchema } = require('@graphql-tools/load')
33
const fs = require('fs')
4-
const yaml = require('js-yaml')
54

65
/**
76
* Tag `changelogEntry` with `date: YYYY-mm-dd`, then prepend it to the JSON
@@ -10,7 +9,7 @@ const yaml = require('js-yaml')
109
* @param {string} targetPath
1110
* @return {void}
1211
*/
13-
function prependDatedEntry(changelogEntry, targetPath) {
12+
function prependDatedEntry (changelogEntry, targetPath) {
1413
// Build a `yyyy-mm-dd`-formatted date string
1514
// and tag the changelog entry with it
1615
const today = new Date()
@@ -39,7 +38,7 @@ function prependDatedEntry(changelogEntry, targetPath) {
3938
* @param {Array<object>} [newUpcomingChanges]
4039
* @return {object?}
4140
*/
42-
async function createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges) {
41+
async function createChangelogEntry (oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges) {
4342
// Create schema objects out of the strings
4443
const oldSchema = await loadSchema(oldSchemaString)
4544
const newSchema = await loadSchema(newSchemaString)
@@ -53,7 +52,7 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
5352
} else if (CHANGES_TO_IGNORE.includes(change.type)) {
5453
// Do nothing
5554
} else {
56-
throw "This change type should be added to CHANGES_TO_REPORT or CHANGES_TO_IGNORE: " + change.type
55+
throw new Error('This change type should be added to CHANGES_TO_REPORT or CHANGES_TO_IGNORE: ' + change.type)
5756
}
5857
})
5958

@@ -63,9 +62,9 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
6362
// Manually check each of `newUpcomingChanges` for an equivalent entry
6463
// in `oldUpcomingChanges`.
6564
return !oldUpcomingChanges.find(function (oldChange) {
66-
return (oldChange.location == change.location &&
67-
oldChange.date == change.date &&
68-
oldChange.description == change.description
65+
return (oldChange.location === change.location &&
66+
oldChange.date === change.date &&
67+
oldChange.description === change.description
6968
)
7069
})
7170
})
@@ -75,7 +74,7 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
7574
const changelogEntry = {
7675
schemaChanges: [],
7776
previewChanges: [],
78-
upcomingChanges: [],
77+
upcomingChanges: []
7978
}
8079

8180
const schemaChange = {
@@ -86,23 +85,23 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
8685
changelogEntry.schemaChanges.push(schemaChange)
8786

8887
for (const previewTitle in previewChangesToReport) {
89-
let previewChanges = previewChangesToReport[previewTitle]
90-
let cleanTitle = cleanPreviewTitle(previewTitle)
91-
let entryTitle = "The [" + cleanTitle + "](/graphql/overview/schema-previews#" + previewAnchor(cleanTitle) + ") includes these changes:"
88+
const previewChanges = previewChangesToReport[previewTitle]
89+
const cleanTitle = cleanPreviewTitle(previewTitle)
90+
const entryTitle = 'The [' + cleanTitle + '](/graphql/overview/schema-previews#' + previewAnchor(cleanTitle) + ') includes these changes:'
9291
changelogEntry.previewChanges.push({
9392
title: entryTitle,
94-
changes: cleanMessagesFromChanges(previewChanges.changes),
93+
changes: cleanMessagesFromChanges(previewChanges.changes)
9594
})
9695
}
9796

9897
if (addedUpcomingChanges.length > 0) {
9998
changelogEntry.upcomingChanges.push({
100-
title: "The following changes will be made to the schema:",
99+
title: 'The following changes will be made to the schema:',
101100
changes: addedUpcomingChanges.map(function (change) {
102101
const location = change.location
103102
const description = change.description
104-
const date = change.date.split("T")[0]
105-
return "On member `" + location + "`:" + description + " **Effective " + date + "**."
103+
const date = change.date.split('T')[0]
104+
return 'On member `' + location + '`:' + description + ' **Effective ' + date + '**.'
106105
})
107106
})
108107
}
@@ -119,13 +118,13 @@ async function createChangelogEntry(oldSchemaString, newSchemaString, previews,
119118
* @param {string} title
120119
* @return {string}
121120
*/
122-
function cleanPreviewTitle(title) {
123-
if (title == "UpdateRefsPreview") {
124-
title = "Update refs preview"
125-
} else if (title == "MergeInfoPreview") {
126-
title = "Merge info preview"
127-
} else if (!title.endsWith("preview")) {
128-
title = title + " preview"
121+
function cleanPreviewTitle (title) {
122+
if (title === 'UpdateRefsPreview') {
123+
title = 'Update refs preview'
124+
} else if (title === 'MergeInfoPreview') {
125+
title = 'Merge info preview'
126+
} else if (!title.endsWith('preview')) {
127+
title = title + ' preview'
129128
}
130129
return title
131130
}
@@ -136,7 +135,7 @@ function cleanPreviewTitle(title) {
136135
* @param {string} [previewTitle]
137136
* @return {string}
138137
*/
139-
function previewAnchor(previewTitle) {
138+
function previewAnchor (previewTitle) {
140139
return previewTitle
141140
.toLowerCase()
142141
.replace(/ /g, '-')
@@ -148,11 +147,11 @@ function previewAnchor(previewTitle) {
148147
* @param {Array<object>} changes
149148
* @return {Array<string>}
150149
*/
151-
function cleanMessagesFromChanges(changes) {
150+
function cleanMessagesFromChanges (changes) {
152151
return changes.map(function (change) {
153152
// replace single quotes around graphql names with backticks,
154153
// to match previous behavior from graphql-schema-comparator
155-
return change.message.replace(/'([a-zA-Z\. :!]+)'/g, '`$1`')
154+
return change.message.replace(/'([a-zA-Z. :!]+)'/g, '`$1`')
156155
})
157156
}
158157

@@ -165,7 +164,7 @@ function cleanMessagesFromChanges(changes) {
165164
* @param {object} previews
166165
* @return {object}
167166
*/
168-
function segmentPreviewChanges(changesToReport, previews) {
167+
function segmentPreviewChanges (changesToReport, previews) {
169168
// Build a map of `{ path => previewTitle` }
170169
// for easier lookup of change to preview
171170
const pathToPreview = {}
@@ -180,12 +179,12 @@ function segmentPreviewChanges(changesToReport, previews) {
180179
changesToReport.forEach(function (change) {
181180
// For each change, see if its path _or_ one of its ancestors
182181
// is covered by a preview. If it is, mark this change as belonging to a preview
183-
const pathParts = change.path.split(".")
182+
const pathParts = change.path.split('.')
184183
let testPath = null
185184
let previewTitle = null
186185
let previewChanges = null
187186
while (pathParts.length > 0 && !previewTitle) {
188-
testPath = pathParts.join(".")
187+
testPath = pathParts.join('.')
189188
previewTitle = pathToPreview[testPath]
190189
// If that path didn't find a match, then we'll
191190
// check the next ancestor.
@@ -227,7 +226,7 @@ const CHANGES_TO_REPORT = [
227226
ChangeType.UnionMemberAdded,
228227
ChangeType.SchemaQueryTypeChanged,
229228
ChangeType.SchemaMutationTypeChanged,
230-
ChangeType.SchemaSubscriptionTypeChanged,
229+
ChangeType.SchemaSubscriptionTypeChanged
231230
]
232231

233232
const CHANGES_TO_IGNORE = [
@@ -259,7 +258,7 @@ const CHANGES_TO_IGNORE = [
259258
ChangeType.InputFieldDescriptionChanged,
260259
ChangeType.TypeDescriptionChanged,
261260
ChangeType.TypeDescriptionRemoved,
262-
ChangeType.TypeDescriptionAdded,
261+
ChangeType.TypeDescriptionAdded
263262
]
264263

265264
module.exports = { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry }

script/graphql/update-files.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const processPreviews = require('./utils/process-previews')
1414
const processUpcomingChanges = require('./utils/process-upcoming-changes')
1515
const processSchemas = require('./utils/process-schemas')
1616
const prerenderObjects = require('./utils/prerender-objects')
17-
const { prependDatedEntry, createChangelogEntry } = require("./build-changelog")
17+
const { prependDatedEntry, createChangelogEntry } = require('./build-changelog')
1818

1919
// check for required PAT
2020
if (!process.env.GITHUB_TOKEN) {
@@ -60,7 +60,7 @@ async function main () {
6060
const upcomingChangesPath = getDataFilepath('upcomingChanges', graphqlVersion)
6161
let previousUpcomingChanges = null
6262
if (fs.existsSync(upcomingChangesPath)) {
63-
previousUpcomingChanges = yaml.safeLoad(fs.readFileSync(upcomingChangesPath, "utf8"))
63+
previousUpcomingChanges = yaml.safeLoad(fs.readFileSync(upcomingChangesPath, 'utf8'))
6464
}
6565
const safeForPublicChanges = await getRemoteRawContent(upcomingChangesPath, graphqlVersion)
6666
updateFile(upcomingChangesPath, safeForPublicChanges)
@@ -71,7 +71,7 @@ async function main () {
7171
const schemaPath = getDataFilepath('schemas', graphqlVersion)
7272
let previousSchemaString = null
7373
if (fs.existsSync(upcomingChangesPath)) {
74-
previousSchemaString = fs.readFileSync(schemaPath, "utf8")
74+
previousSchemaString = fs.readFileSync(schemaPath, 'utf8')
7575
}
7676
const latestSchema = await getRemoteRawContent(schemaPath, graphqlVersion)
7777
const safeForPublicSchema = removeHiddenMembers(schemaPath, latestSchema)
@@ -90,7 +90,7 @@ async function main () {
9090
safeForPublicSchema,
9191
safeForPublicPreviews,
9292
previousUpcomingChanges.upcoming_changes,
93-
yaml.safeLoad(safeForPublicChanges).upcoming_changes,
93+
yaml.safeLoad(safeForPublicChanges).upcoming_changes
9494
)
9595
if (changelogEntry) {
9696
prependDatedEntry(changelogEntry, path.join(process.cwd(), 'lib/graphql/static/changelog.json'))

tests/graphql/build-changelog-test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const yaml = require("js-yaml")
1+
const yaml = require('js-yaml')
22
const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog')
3-
const fs = require("fs")
3+
const fs = require('fs')
44

55
describe('creating a changelog from old schema and new schema', () => {
66
it('finds a diff of schema changes, upcoming changes, and preview changes', async () => {
@@ -37,7 +37,7 @@ describe('creating a changelog from old schema and new schema', () => {
3737
}
3838
`
3939

40-
previews = yaml.safeLoad(`
40+
const previews = yaml.safeLoad(`
4141
- title: Test preview
4242
description: This preview is just for test
4343
toggled_by: ':test_preview'
@@ -50,14 +50,14 @@ describe('creating a changelog from old schema and new schema', () => {
5050
- '@github/engineering'
5151
`)
5252

53-
oldUpcomingChanges = yaml.safeLoad(`
53+
const oldUpcomingChanges = yaml.safeLoad(`
5454
upcoming_changes:
5555
- location: EnterprisePendingCollaboratorEdge.isUnlicensed
5656
description: '\`isUnlicensed\` will be removed.'
5757
date: '2021-01-01T00:00:00+00:00'
5858
`).upcoming_changes
5959

60-
newUpcomingChanges = yaml.safeLoad(`
60+
const newUpcomingChanges = yaml.safeLoad(`
6161
upcoming_changes:
6262
- location: Query.stableField
6363
description: '\`stableField\` will be removed.'
@@ -82,35 +82,35 @@ upcoming_changes:
8282
})
8383
})
8484

85-
describe("Preparing preview links", () => {
86-
it("fixes preview names", () => {
85+
describe('Preparing preview links', () => {
86+
it('fixes preview names', () => {
8787
// These two are special cases
88-
expect(cleanPreviewTitle("UpdateRefsPreview")).toEqual("Update refs preview")
89-
expect(cleanPreviewTitle("MergeInfoPreview")).toEqual("Merge info preview")
88+
expect(cleanPreviewTitle('UpdateRefsPreview')).toEqual('Update refs preview')
89+
expect(cleanPreviewTitle('MergeInfoPreview')).toEqual('Merge info preview')
9090
// Previews that don't end in " preview" have it added
91-
expect(cleanPreviewTitle("something interesting")).toEqual("something interesting preview")
91+
expect(cleanPreviewTitle('something interesting')).toEqual('something interesting preview')
9292
// Other things are left as-is
93-
expect(cleanPreviewTitle("nice preview")).toEqual("nice preview")
93+
expect(cleanPreviewTitle('nice preview')).toEqual('nice preview')
9494
})
9595

96-
it("creates anchors from preview titles", () => {
97-
expect(previewAnchor("Merge info preview")).toEqual("merge-info-preview")
98-
expect(previewAnchor("some.punct123 preview")).toEqual("somepunct123-preview")
96+
it('creates anchors from preview titles', () => {
97+
expect(previewAnchor('Merge info preview')).toEqual('merge-info-preview')
98+
expect(previewAnchor('some.punct123 preview')).toEqual('somepunct123-preview')
9999
})
100100
})
101101

102-
describe("updating the changelog file", () => {
103-
it("modifies the entry object and the file on disk", () => {
104-
const testTargetPath = "tests/graphql/example_changelog.json"
102+
describe('updating the changelog file', () => {
103+
it('modifies the entry object and the file on disk', () => {
104+
const testTargetPath = 'tests/graphql/example_changelog.json'
105105
const previousContents = fs.readFileSync(testTargetPath)
106106

107107
const exampleEntry = { someStuff: true }
108108
prependDatedEntry(exampleEntry, testTargetPath)
109-
const newContents = fs.readFileSync(testTargetPath, "utf8")
109+
const newContents = fs.readFileSync(testTargetPath, 'utf8')
110110
// reset the file:
111111
fs.writeFileSync(testTargetPath, previousContents)
112112

113-
const expectedDate = (new Date).toISOString().split("T")[0]
113+
const expectedDate = (new Date()).toISOString().split('T')[0]
114114
expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate })
115115
expect(newContents).toMatchSnapshot()
116116
})

0 commit comments

Comments
 (0)