diff --git a/.eslintrc.yml b/.eslintrc.yml index 3d2e1c34..3c65ee95 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -171,7 +171,7 @@ rules: no-loss-of-precision: error no-misleading-character-class: error no-obj-calls: error - no-promise-executor-return: off # TODO + no-promise-executor-return: error no-prototype-builtins: error no-regex-spaces: error no-setter-return: error @@ -256,7 +256,7 @@ rules: no-void: error no-warning-comments: off no-with: error - prefer-named-capture-group: off # ES2018 + prefer-named-capture-group: error prefer-promise-reject-errors: error prefer-regex-literals: error radix: error @@ -322,7 +322,7 @@ rules: no-restricted-syntax: off no-tabs: error no-ternary: off - no-underscore-dangle: off # TODO + no-underscore-dangle: error no-unneeded-ternary: error one-var: [error, never] operator-assignment: error @@ -503,9 +503,9 @@ overrides: '@typescript-eslint/no-var-requires': error '@typescript-eslint/prefer-as-const': off # TODO consider '@typescript-eslint/prefer-enum-initializers': off # TODO consider - '@typescript-eslint/prefer-for-of': off # TODO switch to error after TS migration + '@typescript-eslint/prefer-for-of': error '@typescript-eslint/prefer-function-type': error - '@typescript-eslint/prefer-includes': off # TODO switch to error after IE11 drop + '@typescript-eslint/prefer-includes': error '@typescript-eslint/prefer-literal-enum-member': error '@typescript-eslint/prefer-namespace-keyword': error '@typescript-eslint/prefer-nullish-coalescing': error @@ -515,13 +515,13 @@ overrides: '@typescript-eslint/prefer-reduce-type-parameter': error '@typescript-eslint/prefer-regexp-exec': error '@typescript-eslint/prefer-ts-expect-error': error - '@typescript-eslint/prefer-string-starts-ends-with': off # TODO switch to error after IE11 drop + '@typescript-eslint/prefer-string-starts-ends-with': error '@typescript-eslint/promise-function-async': off '@typescript-eslint/require-array-sort-compare': error '@typescript-eslint/restrict-plus-operands': [error, { checkCompoundAssignments: true }] '@typescript-eslint/restrict-template-expressions': error - '@typescript-eslint/strict-boolean-expressions': off # TODO consider + '@typescript-eslint/strict-boolean-expressions': error '@typescript-eslint/switch-exhaustiveness-check': error '@typescript-eslint/triple-slash-reference': error '@typescript-eslint/typedef': off diff --git a/resources/build-npm.js b/resources/build-npm.js index a3a9217e..4cc27d2e 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -52,12 +52,12 @@ function buildPackageJSON() { delete packageJSON.devDependencies; const { version } = packageJSON; - const versionMatch = /^\d+\.\d+\.\d+-?(.*)?$/.exec(version); + const versionMatch = /^\d+\.\d+\.\d+-?(?.*)?$/.exec(version); if (!versionMatch) { throw new Error('Version does not match semver spec: ' + version); } - const [, preReleaseTag] = versionMatch; + const { preReleaseTag } = versionMatch.groups; if (preReleaseTag != null) { const [tag] = preReleaseTag.split('.'); diff --git a/resources/gen-changelog.js b/resources/gen-changelog.js index 7449c179..48a3cf36 100644 --- a/resources/gen-changelog.js +++ b/resources/gen-changelog.js @@ -47,14 +47,14 @@ if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') { process.exit(1); } -const repoURLMatch = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec( +const repoURLMatch = /https:\/\/github.com\/(?[^/]+)\/(?[^/]+).git/.exec( packageJSON.repository.url, ); if (repoURLMatch == null) { console.error('Cannot extract organization and repo name from repo URL!'); process.exit(1); } -const [, githubOrg, githubRepo] = repoURLMatch; +const { githubOrg, githubRepo } = repoURLMatch.groups; getChangeLog() .then((changelog) => process.stdout.write(changelog)) @@ -275,9 +275,9 @@ function commitsInfoToPRs(commits) { (pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`, ); if (associatedPRs.length === 0) { - const match = / \(#([0-9]+)\)$/m.exec(commit.message); + const match = / \(#(?[0-9]+)\)$/m.exec(commit.message); if (match) { - prs[parseInt(match[1], 10)] = true; + prs[parseInt(match.groups.prNumber, 10)] = true; continue; } throw new Error( diff --git a/src/index.ts b/src/index.ts index 23b4d930..a185ff99 100644 --- a/src/index.ts +++ b/src/index.ts @@ -186,7 +186,7 @@ type Middleware = (request: Request, response: Response) => Promise; * configure behavior, and returns an express middleware. */ export function graphqlHTTP(options: Options): Middleware { - if (!options) { + if (options == null) { throw new Error('GraphQL middleware requires options.'); } diff --git a/src/parseBody.ts b/src/parseBody.ts index 32b1f968..3cac4c3d 100644 --- a/src/parseBody.ts +++ b/src/parseBody.ts @@ -83,7 +83,7 @@ async function readBody( const charset = typeInfo.parameters.charset?.toLowerCase() ?? 'utf-8'; // Assert charset encoding per JSON RFC 7159 sec 8.1 - if (charset.slice(0, 4) !== 'utf-') { + if (!charset.startsWith('utf-')) { throw httpError(415, `Unsupported charset "${charset.toUpperCase()}".`); }