Skip to content

Commit 4b451a9

Browse files
authored
fix no-var and prefer-const ESLint errors (#1679)
* fix `no-var` and `prefer-const` ESLint errors * more * more * fix build
1 parent 9a7a46b commit 4b451a9

File tree

10 files changed

+57
-70
lines changed

10 files changed

+57
-70
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ module.exports = {
3333
],
3434
},
3535
],
36+
'prefer-const': ['error', { destructuring: 'all' }],
3637
// TODO: fix below
37-
"no-var": "off",
3838
"no-useless-escape": "off",
39-
"prefer-const": "off",
4039
"prefer-rest-params": "off",
4140
"prefer-spread": "off",
4241
"@typescript-eslint/no-explicit-any": "off",

scripts/update-code-data/organize-code-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export type List = {
1212
export async function organizeCodeData(
1313
codeData: CodeData,
1414
): Promise<{ languageList: List[]; toolList: List[]; serviceList: Library[] }> {
15-
let languageList: List[] = []
16-
let toolList: List[] = []
15+
const languageList: List[] = []
16+
const toolList: List[] = []
1717
let serviceList: Library[] = []
1818
await Promise.all([
1919
...Object.keys(codeData.Languages).map(async languageName => {

scripts/update-code-data/update-code-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function updateCodeData(
2424
markdownFilePaths: string[],
2525
slugMap: string,
2626
): Promise<CodeData> {
27-
let codeData = {} as CodeData
27+
const codeData = {} as CodeData
2828
await Promise.all(
2929
markdownFilePaths.map(async markdownFilePath => {
3030
const markdownFileContent = await readFile(markdownFilePath, "utf-8")

src/app/conf/2023/_data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function getSchedule(): Promise<ScheduleSession[]> {
6363
)
6464

6565
const result = sessions.map(session => {
66-
let { description } = session
66+
const { description } = session
6767
if (description?.includes("<")) {
6868
// console.log(`Found HTML element in about field for session "${session.name}"`)
6969
}

src/app/conf/2023/gallery/page.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ export const metadata: Metadata = {
88
}
99

1010
function chunk<T>(arr: T[], len: number): T[][] {
11-
let chunks = [],
12-
i = 0,
13-
n = arr.length
11+
const chunks = []
12+
let i = 0
1413

15-
while (i < n) {
14+
while (i < arr.length) {
1615
chunks.push(arr.slice(i, (i += len)))
1716
}
1817

src/components/marked/index.tsx

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function Marked(props: { children: string }) {
1818
* Block-Level Grammar
1919
*/
2020

21-
var block = {
21+
const block = {
2222
newline: /^\n+/,
2323
code: /^( {4}[^\n]+\n*)+/,
2424
fences: noop,
@@ -124,7 +124,7 @@ Lexer.rules = block
124124
*/
125125

126126
Lexer.lex = function (src, options) {
127-
var lexer = new Lexer(options)
127+
const lexer = new Lexer(options)
128128
return lexer.lex(src)
129129
}
130130

@@ -147,16 +147,8 @@ Lexer.prototype.lex = function (src) {
147147
*/
148148

149149
Lexer.prototype.token = function (src, top) {
150-
var src = src.replace(/^ +$/gm, ""),
151-
next,
152-
loose,
153-
cap,
154-
bull,
155-
b,
156-
item,
157-
space,
158-
i,
159-
l
150+
src = src.replace(/^ +$/gm, "")
151+
let next, loose, cap, bull, b, item, space, i, l
160152

161153
while (src) {
162154
// newline
@@ -437,7 +429,7 @@ Lexer.prototype.token = function (src, top) {
437429
* Inline-Level Grammar
438430
*/
439431

440-
var inline = {
432+
const inline = {
441433
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
442434
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
443435
url: noop,
@@ -533,7 +525,7 @@ InlineLexer.rules = inline
533525
*/
534526

535527
InlineLexer.output = function (src, links, options) {
536-
var inline = new InlineLexer(links, options)
528+
const inline = new InlineLexer(links, options)
537529
return inline.output(src)
538530
}
539531

@@ -542,11 +534,8 @@ InlineLexer.output = function (src, links, options) {
542534
*/
543535

544536
InlineLexer.prototype.output = function (src) {
545-
var out = [],
546-
link,
547-
text,
548-
href,
549-
cap
537+
const out = []
538+
let link, text, href, cap
550539

551540
while (src) {
552541
// escape
@@ -686,7 +675,7 @@ InlineLexer.prototype.output = function (src) {
686675
InlineLexer.prototype.sanitizeUrl = function (url) {
687676
if (this.options.sanitize) {
688677
try {
689-
var prot = decodeURIComponent(url)
678+
const prot = decodeURIComponent(url)
690679
.replace(/[^A-Za-z0-9:]/g, "")
691680
.toLowerCase()
692681
if (prot.indexOf("javascript:") === 0) {
@@ -705,7 +694,7 @@ InlineLexer.prototype.sanitizeUrl = function (url) {
705694

706695
InlineLexer.prototype.outputLink = function (cap, link) {
707696
if (cap[0][0] !== "!") {
708-
var shouldOpenInNewWindow =
697+
const shouldOpenInNewWindow =
709698
link.href.charAt(0) !== "/" && link.href.charAt(0) !== "#"
710699

711700
return createElement(
@@ -762,7 +751,7 @@ function Parser(options) {
762751
*/
763752

764753
Parser.parse = function (src, options) {
765-
var parser = new Parser(options)
754+
const parser = new Parser(options)
766755
return parser.parse(src)
767756
}
768757

@@ -774,7 +763,7 @@ Parser.prototype.parse = function (src) {
774763
this.inline = new InlineLexer(src.links, this.options)
775764
this.tokens = src.reverse()
776765

777-
var out = []
766+
const out = []
778767
while (this.next()) {
779768
out.push(this.tok())
780769
}
@@ -803,7 +792,7 @@ Parser.prototype.peek = function () {
803792
*/
804793

805794
Parser.prototype.parseText = function () {
806-
var body = this.token.text
795+
let body = this.token.text
807796

808797
while (this.peek().type === "text") {
809798
body += "\n" + this.next().text
@@ -820,18 +809,18 @@ Parser.prototype.tok = function () {
820809
switch (this.token.type) {
821810
case "code": {
822811
if (this.token.lang === "graphql") {
823-
var lines = this.token.text.split("\n")
824-
var firstLine = lines.shift().match(/^\s*#\s*({.*})$/)
812+
const lines = this.token.text.split("\n")
813+
const firstLine = lines.shift().match(/^\s*#\s*({.*})$/)
825814
if (firstLine) {
826-
var metaData
815+
let metaData
827816
try {
828817
metaData = JSON.parse(firstLine[1])
829818
} catch (e) {
830819
console.error("Invalid Metadata JSON:", firstLine[1])
831820
}
832821
if (metaData) {
833-
var query = lines.join("\n")
834-
var variables = metaData.variables
822+
const query = lines.join("\n")
823+
const variables = metaData.variables
835824
? JSON.stringify(metaData.variables, null, 2)
836825
: ""
837826
const schemaMap = {
@@ -871,7 +860,7 @@ function noop() {}
871860
noop.exec = noop
872861

873862
function merge(obj) {
874-
var i = 1,
863+
let i = 1,
875864
target,
876865
key
877866

@@ -900,8 +889,8 @@ function marked(src, opt, callback) {
900889

901890
if (opt) opt = merge({}, marked.defaults, opt)
902891

903-
var highlight = opt.highlight,
904-
tokens,
892+
const highlight = opt.highlight
893+
let tokens,
905894
pending,
906895
i = 0
907896

@@ -913,8 +902,8 @@ function marked(src, opt, callback) {
913902

914903
pending = tokens.length
915904

916-
var done = function (hi) {
917-
var out, err
905+
const done = function (hi) {
906+
let out, err
918907

919908
if (hi !== true) {
920909
delete opt.highlight

src/components/marked/mini-graphiQL.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class MiniGraphiQL extends Component {
7676

7777
async _runQuery() {
7878
this._editorQueryID++
79-
var queryID = this._editorQueryID
79+
const queryID = this._editorQueryID
8080
try {
8181
const result = await graphql({
8282
schema: this.props.schema,
@@ -139,7 +139,7 @@ class QueryEditor extends Component {
139139
}
140140

141141
componentDidMount() {
142-
var CodeMirror = require("codemirror")
142+
const CodeMirror = require("codemirror")
143143
require("codemirror/addon/hint/show-hint")
144144
require("codemirror/addon/comment/comment")
145145
require("codemirror/addon/edit/matchbrackets")
@@ -230,7 +230,7 @@ class QueryEditor extends Component {
230230
}
231231

232232
_onKeyUp(cm, event) {
233-
var code = event.keyCode
233+
const code = event.keyCode
234234
if (
235235
(code >= 65 && code <= 90) || // letters
236236
(!event.shiftKey && code >= 48 && code <= 57) || // numbers
@@ -272,7 +272,7 @@ class QueryEditor extends Component {
272272
*/
273273
class ResultViewer extends Component {
274274
componentDidMount() {
275-
var CodeMirror = require("codemirror")
275+
const CodeMirror = require("codemirror")
276276
require("codemirror-graphql/results/mode")
277277

278278
this.viewer = CodeMirror(this.domNode, {
@@ -464,28 +464,28 @@ class VariableEditor extends Component {
464464
* about the type and description for the selected context.
465465
*/
466466
function onHasCompletion(cm, data, onHintInformationRender) {
467-
var CodeMirror = require("codemirror")
468-
var wrapper
469-
var information
467+
const CodeMirror = require("codemirror")
468+
let wrapper
469+
let information
470470

471471
// When a hint result is selected, we touch the UI.
472472
CodeMirror.on(data, "select", (ctx, el) => {
473473
// Only the first time (usually when the hint UI is first displayed)
474474
// do we create the wrapping node.
475475
if (!wrapper) {
476476
// Wrap the existing hint UI, so we have a place to put information.
477-
var hintsUl = el.parentNode
478-
var container = hintsUl.parentNode
477+
const hintsUl = el.parentNode
478+
const container = hintsUl.parentNode
479479
wrapper = document.createElement("div")
480480
container.appendChild(wrapper)
481481

482482
// CodeMirror vertically inverts the hint UI if there is not enough
483483
// space below the cursor. Since this modified UI appends to the bottom
484484
// of CodeMirror's existing UI, it could cover the cursor. This adjusts
485485
// the positioning of the hint UI to accomodate.
486-
var top = hintsUl.style.top
487-
var bottom = ""
488-
var cursorTop = cm.cursorCoords().top
486+
let top = hintsUl.style.top
487+
let bottom = ""
488+
const cursorTop = cm.cursorCoords().top
489489
if (parseInt(top, 10) < cursorTop) {
490490
top = ""
491491
bottom = window.innerHeight - cursorTop + 3 + "px"
@@ -516,7 +516,7 @@ function onHasCompletion(cm, data, onHintInformationRender) {
516516
// When CodeMirror attempts to remove the hint UI, we detect that it was
517517
// removed from our wrapper and in turn remove the wrapper from the
518518
// original container.
519-
var onRemoveFn
519+
let onRemoveFn
520520
wrapper.addEventListener(
521521
"DOMNodeRemoved",
522522
(onRemoveFn = event => {
@@ -532,10 +532,10 @@ function onHasCompletion(cm, data, onHintInformationRender) {
532532
}
533533

534534
// Now that the UI has been set up, add info to information.
535-
var description = ctx.description
535+
const description = ctx.description
536536
? marked(ctx.description, { smartypants: true })
537537
: "Self descriptive."
538-
var type = ctx.type
538+
const type = ctx.type
539539
? '<span class="infoType">' + String(ctx.type) + "</span>"
540540
: ""
541541
information.innerHTML =

src/components/marked/users-schema.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "graphql"
1010

1111
// Example data set
12-
var data = ppl({
12+
const data = ppl({
1313
1572451031: "Daniel Schafer",
1414
4802170: "Lee Byron",
1515
37000641: "Nick Schrock",
@@ -46,7 +46,7 @@ function makePic(user, size) {
4646

4747
// @ts-expect-error -- fixme
4848
function friends(user, first) {
49-
var allFriends = Object.keys(data)
49+
const allFriends = Object.keys(data)
5050
.map(id => data[id])
5151
.filter(v => v !== user)
5252
return {
@@ -55,7 +55,7 @@ function friends(user, first) {
5555
}
5656
}
5757

58-
var ImageType = new GraphQLObjectType({
58+
const ImageType = new GraphQLObjectType({
5959
name: "Image",
6060
fields: {
6161
width: { type: GraphQLInt },
@@ -65,7 +65,7 @@ var ImageType = new GraphQLObjectType({
6565
})
6666

6767
// @ts-expect-error -- fixme
68-
var FriendConnection = new GraphQLObjectType({
68+
const FriendConnection = new GraphQLObjectType({
6969
name: "FriendConnection",
7070
fields: () => ({
7171
totalCount: { type: GraphQLInt },
@@ -74,7 +74,7 @@ var FriendConnection = new GraphQLObjectType({
7474
})
7575

7676
// @ts-expect-error -- fixme
77-
var UserType = new GraphQLObjectType({
77+
const UserType = new GraphQLObjectType({
7878
name: "User",
7979
fields: {
8080
id: { type: GraphQLID },

0 commit comments

Comments
 (0)