From 2bea3cbcc4cc550d78d78dd08cb4a69f3398fb26 Mon Sep 17 00:00:00 2001 From: Matt Kubej Date: Wed, 15 Jul 2020 22:00:08 -0400 Subject: [PATCH] chore: fix grammatical and spelling errors in comments and tests --- lib/application.js | 1 + lib/request.js | 18 ++++++++++-------- lib/response.js | 7 +++++-- test/application/onerror.js | 2 +- test/application/respond.js | 2 +- test/application/use.js | 2 +- test/context/onerror.js | 2 +- test/request/accepts.js | 6 +++--- test/request/fresh.js | 2 +- test/request/hostname.js | 4 ++-- test/request/length.js | 2 +- test/request/query.js | 4 ++-- test/request/type.js | 2 +- test/request/whatwg-url.js | 20 +++++++++----------- test/response/attachment.js | 4 ++-- test/response/writable.js | 6 +++--- 16 files changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/application.js b/lib/application.js index 2761af204..e01019796 100644 --- a/lib/application.js +++ b/lib/application.js @@ -278,4 +278,5 @@ function respond(ctx) { * Make HttpError available to consumers of the library so that consumers don't * have a direct dependency upon `http-errors` */ + module.exports.HttpError = HttpError; diff --git a/lib/request.js b/lib/request.js index ddcace86e..e62afd606 100644 --- a/lib/request.js +++ b/lib/request.js @@ -146,7 +146,7 @@ module.exports = { }, /** - * Set pathname, retaining the query-string when present. + * Set pathname, retaining the query string when present. * * @param {String} path * @api public @@ -163,7 +163,7 @@ module.exports = { }, /** - * Get parsed query-string. + * Get parsed query string. * * @return {Object} * @api public @@ -176,7 +176,7 @@ module.exports = { }, /** - * Set query-string as an object. + * Set query string as an object. * * @param {Object} obj * @api public @@ -199,7 +199,7 @@ module.exports = { }, /** - * Set querystring. + * Set query string. * * @param {String} str * @api public @@ -216,7 +216,7 @@ module.exports = { }, /** - * Get the search string. Same as the querystring + * Get the search string. Same as the query string * except it includes the leading ?. * * @return {String} @@ -406,7 +406,7 @@ module.exports = { }, /** - * Short-hand for: + * Shorthand for: * * this.protocol == 'https' * @@ -422,7 +422,7 @@ module.exports = { * When `app.proxy` is `true`, parse * the "X-Forwarded-For" ip address list. * - * For example if the value were "client, proxy1, proxy2" + * For example if the value was "client, proxy1, proxy2" * you would receive the array `["client", "proxy1", "proxy2"]` * where "proxy2" is the furthest down-stream. * @@ -495,6 +495,7 @@ module.exports = { * @return {Object} * @api private */ + get accept() { return this._accept || (this._accept = accepts(this.req)); }, @@ -505,6 +506,7 @@ module.exports = { * @param {Object} * @api private */ + set accept(obj) { this._accept = obj; }, @@ -607,7 +609,7 @@ module.exports = { /** * Check if the incoming request contains the "Content-Type" - * header field, and it contains any of the give mime `type`s. + * header field and if it contains any of the given mime `type`s. * If there is no request body, `null` is returned. * If there is no content type, `false` is returned. * Otherwise, it returns the first `type` that matches. diff --git a/lib/response.js b/lib/response.js index 2f7e7a5f3..91be188e2 100644 --- a/lib/response.js +++ b/lib/response.js @@ -433,6 +433,7 @@ module.exports = { * @return {boolean} * @api public */ + has(field) { return typeof this.res.hasHeader === 'function' ? this.res.hasHeader(field) @@ -441,7 +442,7 @@ module.exports = { }, /** - * Set header `field` to `val`, or pass + * Set header `field` to `val` or pass * an object of header fields. * * Examples: @@ -564,8 +565,9 @@ module.exports = { }, /** - * Flush any set headers, and begin the body + * Flush any set headers and begin the body */ + flushHeaders() { this.res.flushHeaders(); } @@ -577,6 +579,7 @@ module.exports = { * @return {Object} * @api public */ + /* istanbul ignore else */ if (util.inspect.custom) { module.exports[util.inspect.custom] = module.exports.inspect; diff --git a/test/application/onerror.js b/test/application/onerror.js index 5968677d0..7dd4d1cad 100644 --- a/test/application/onerror.js +++ b/test/application/onerror.js @@ -66,7 +66,7 @@ describe('app.onerror(err)', () => { assert(msg === '\n Foo\n'); }); - it('should use err.toString() instad of err.stack', () => { + it('should use err.toString() instead of err.stack', () => { const app = new Koa(); app.env = 'dev'; diff --git a/test/application/respond.js b/test/application/respond.js index b0fd5964b..1f9a17118 100644 --- a/test/application/respond.js +++ b/test/application/respond.js @@ -238,7 +238,7 @@ describe('app.respond', () => { }); }); - describe('when no middleware are present', () => { + describe('when no middleware is present', () => { it('should 404', () => { const app = new Koa(); diff --git a/test/application/use.js b/test/application/use.js index 93988fd75..43cbf8aa4 100644 --- a/test/application/use.js +++ b/test/application/use.js @@ -98,7 +98,7 @@ describe('app.use(fn)', () => { .expect('generator'); }); - it('should throw error for non function', () => { + it('should throw error for non-function', () => { const app = new Koa(); [null, undefined, 0, false, 'not a function'].forEach(v => { diff --git a/test/context/onerror.js b/test/context/onerror.js index 2c03e27bd..098df8ad4 100644 --- a/test/context/onerror.js +++ b/test/context/onerror.js @@ -239,7 +239,7 @@ describe('ctx.onerror(err)', () => { }); describe('when non-error thrown', () => { - it('should response non-error thrown message', () => { + it('should respond with non-error thrown message', () => { const app = new Koa(); app.use((ctx, next) => { diff --git a/test/request/accepts.js b/test/request/accepts.js index 784b57863..4c680d942 100644 --- a/test/request/accepts.js +++ b/test/request/accepts.js @@ -62,7 +62,7 @@ describe('ctx.accepts(types)', () => { }); }); - describe('when present in Accept as an exact match', () => { + describe('when value present in Accept is an exact match', () => { it('should return the type', () => { const ctx = context(); ctx.req.headers.accept = 'text/plain, text/html'; @@ -71,7 +71,7 @@ describe('ctx.accepts(types)', () => { }); }); - describe('when present in Accept as a type match', () => { + describe('when value present in Accept is a type match', () => { it('should return the type', () => { const ctx = context(); ctx.req.headers.accept = 'application/json, */*'; @@ -81,7 +81,7 @@ describe('ctx.accepts(types)', () => { }); }); - describe('when present in Accept as a subtype match', () => { + describe('when value present in Accept is a subtype match', () => { it('should return the type', () => { const ctx = context(); ctx.req.headers.accept = 'application/json, text/*'; diff --git a/test/request/fresh.js b/test/request/fresh.js index 7a5363e63..b452c1d6c 100644 --- a/test/request/fresh.js +++ b/test/request/fresh.js @@ -36,7 +36,7 @@ describe('ctx.fresh', () => { }); }); - describe('and etag do not match', () => { + describe('and etag does not match', () => { it('should return false', () => { const ctx = context(); ctx.status = 200; diff --git a/test/request/hostname.js b/test/request/hostname.js index 13134d096..dd9c61da1 100644 --- a/test/request/hostname.js +++ b/test/request/hostname.js @@ -31,13 +31,13 @@ describe('req.hostname', () => { assert.equal(req.hostname, '[::1]'); }); - it('should parse localhost with non special schema port', () => { + it('should parse localhost with non-special schema port', () => { const req = request(); req.header.host = '[::1]:1337'; assert.equal(req.hostname, '[::1]'); }); - it('should reduce IPv6 with non special schema port, as hostname', () => { + it('should reduce IPv6 with non-special schema port as hostname', () => { const req = request(); req.header.host = '[2001:cdba:0000:0000:0000:0000:3257:9652]:1337'; assert.equal(req.hostname, '[2001:cdba::3257:9652]'); diff --git a/test/request/length.js b/test/request/length.js index 5f8e92d32..445ecd9e2 100644 --- a/test/request/length.js +++ b/test/request/length.js @@ -11,7 +11,7 @@ describe('ctx.length', () => { assert.equal(req.length, 10); }); - it('with no content-length present', () => { + it('should return undefined with no content-length present', () => { const req = request(); assert.equal(req.length, undefined); }); diff --git a/test/request/query.js b/test/request/query.js index f3c3ce445..217f98bf1 100644 --- a/test/request/query.js +++ b/test/request/query.js @@ -18,14 +18,14 @@ describe('ctx.query', () => { }); }); - it('should return a parsed query-string', () => { + it('should return a parsed query string', () => { const ctx = context({ url: '/?page=2' }); assert.equal(ctx.query.page, '2'); }); }); describe('ctx.query=', () => { - it('should stringify and replace the querystring and search', () => { + it('should stringify and replace the query string and search', () => { const ctx = context({ url: '/store/shoes' }); ctx.query = { page: 2, color: 'blue' }; assert.equal(ctx.url, '/store/shoes?page=2&color=blue'); diff --git a/test/request/type.js b/test/request/type.js index da3d536cb..625ee8333 100644 --- a/test/request/type.js +++ b/test/request/type.js @@ -11,7 +11,7 @@ describe('req.type', () => { assert.equal(req.type, 'text/html'); }); - it('with no host present', () => { + it('should return empty string with no host present', () => { const req = request(); assert.equal(req.type, ''); }); diff --git a/test/request/whatwg-url.js b/test/request/whatwg-url.js index 7a52a6910..05c1e106a 100644 --- a/test/request/whatwg-url.js +++ b/test/request/whatwg-url.js @@ -5,18 +5,16 @@ const request = require('../helpers/context').request; const assert = require('assert'); describe('req.URL', () => { - describe('should not throw when', () => { - it('host is void', () => { - // Accessing the URL should not throw. - request().URL; - }); + it('should not throw when host is void', () => { + // Accessing the URL should not throw. + request().URL; + }); - it('header.host is invalid', () => { - const req = request(); - req.header.host = 'invalid host'; - // Accessing the URL should not throw. - req.URL; - }); + it('should not throw when header.host is invalid', () => { + const req = request(); + req.header.host = 'invalid host'; + // Accessing the URL should not throw. + req.URL; }); it('should return empty object when invalid', () => { diff --git a/test/response/attachment.js b/test/response/attachment.js index 7ee16bdd6..450f74383 100644 --- a/test/response/attachment.js +++ b/test/response/attachment.js @@ -24,7 +24,7 @@ describe('ctx.attachment([filename])', () => { }); }); - describe('when given a no-ascii filename', () => { + describe('when given a non-ascii filename', () => { it('should set the encodeURI filename param', () => { const ctx = context(); ctx.attachment('path/to/include-no-ascii-char-中文名-ok.png'); @@ -168,7 +168,7 @@ describe('contentDisposition(filename, options)', () => { 'inline'); }); - it('should create a header with inline type & filename', () => { + it('should create a header with inline type and filename', () => { const ctx = context(); ctx.attachment('plans.pdf', { type: 'inline' }); assert.equal(ctx.response.header['content-disposition'], diff --git a/test/response/writable.js b/test/response/writable.js index 21aa25e1b..40b75ead3 100644 --- a/test/response/writable.js +++ b/test/response/writable.js @@ -21,7 +21,7 @@ describe('res.writable', () => { setTimeout(() => client.end(), 100); } - it('should always writable and response all requests', done => { + it('should always be writable and respond to all requests', done => { const app = new Koa(); let count = 0; app.use(ctx => { @@ -50,7 +50,7 @@ describe('res.writable', () => { }); } - it('should not writable', done => { + it('should not be writable', done => { const app = new Koa(); app.use(ctx => { sleep(1000) @@ -77,7 +77,7 @@ describe('res.writable', () => { }, 100); } - it('should not writable', done => { + it('should not be writable', done => { const app = new Koa(); app.use(ctx => { ctx.res.end();