Skip to content

Commit

Permalink
manual linting fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Apr 24, 2018
1 parent e9448a3 commit c099757
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
1 change: 0 additions & 1 deletion bin/micro.js
Expand Up @@ -82,7 +82,6 @@ let file = flags._[0];

if (!file) {
try {
// eslint-disable-next-line import/no-dynamic-require
const packageJson = require(path.resolve(process.cwd(), 'package.json'));
file = packageJson.main || 'index.js';
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion examples/external-api-call/index.js
@@ -1,6 +1,6 @@
const fetch = require('node-fetch');

module.exports = async function (req, res) {
module.exports = async () => {
const response = await fetch('https://api.example.com');
const json = await response.json();

Expand Down
2 changes: 1 addition & 1 deletion examples/json-body-parsing/index.js
@@ -1,6 +1,6 @@
const {json} = require('micro');

module.exports = async function (req, res) {
module.exports = async req => {
const data = await json(req);
console.log(data);

Expand Down
2 changes: 1 addition & 1 deletion examples/urlencoded-body-parsing/index.js
@@ -1,6 +1,6 @@
const parse = require('urlencoded-body-parser');

module.exports = async function (req, res) {
module.exports = async req => {
const data = await parse(req);
console.log(data);

Expand Down
2 changes: 1 addition & 1 deletion examples/with-graphql-request/index.js
Expand Up @@ -13,7 +13,7 @@ const query = `
}
`;

module.exports = async function (req, res) {
module.exports = async () => {
// Perform query
const data = await request(endpoint, query, {title: 'Inception'});

Expand Down
1 change: 0 additions & 1 deletion lib/handler.js
Expand Up @@ -5,7 +5,6 @@ module.exports = async file => {
let mod;

try {
// eslint-disable-next-line import/no-dynamic-require
mod = await require(file); // Await to support exporting Promises

if (mod && typeof mod === 'object') {
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Expand Up @@ -102,7 +102,8 @@ exports.run = (req, res, fn) =>

// Send value if it is not undefined, otherwise assume res.end
// will be called later
if (undefined !== val) {
// eslint-disable-next-line no-undefined
if (val !== undefined) {
send(res, res.statusCode || 200, val);
}
})
Expand All @@ -125,6 +126,7 @@ exports.buffer = (req, {limit = '1mb', encoding} = {}) =>
const type = req.headers['content-type'] || 'text/plain';
const length = req.headers['content-length'];

// eslint-disable-next-line no-undefined
if (encoding === undefined) {
encoding = contentType.parse(type).parameters.charset;
}
Expand Down
4 changes: 3 additions & 1 deletion test/handler.js
Expand Up @@ -20,7 +20,9 @@ test.afterEach(() => {
process.exit.restore();
try {
String.prototype.split.restore();
} catch (err) {}
} catch (err) {
// swallow
}
});

test('handle a PromiseInstance', async t => {
Expand Down
9 changes: 5 additions & 4 deletions test/index.js
Expand Up @@ -271,9 +271,9 @@ test('custom error', async t => {
throw new Error('500 from test (expected)');
};

const handleErrors = fn => (req, res) => {
const handleErrors = ofn => (req, res) => {
try {
return fn(req, res);
return ofn(req, res);
} catch (err) {
send(res, 200, 'My custom error!');
}
Expand All @@ -291,9 +291,9 @@ test('custom async error', async t => {
throw new Error('500 from test (expected)');
};

const handleErrors = fn => async (req, res) => {
const handleErrors = ofn => async (req, res) => {
try {
return await fn(req, res);
return await ofn(req, res);
} catch (err) {
send(res, 200, 'My custom error!');
}
Expand Down Expand Up @@ -525,6 +525,7 @@ test('json from rawBodyMap works', async t => {

test('statusCode defaults to 200', async t => {
const fn = (req, res) => {
// eslint-disable-next-line no-undefined
res.statusCode = undefined;
return 'woot';
};
Expand Down

0 comments on commit c099757

Please sign in to comment.