Use standard for linting rules

This commit is contained in:
Adrian Obelmejias
2016-08-30 16:58:35 -04:00
parent df481a5229
commit de550f31df
11 changed files with 23 additions and 28 deletions
+1 -11
View File
@@ -1,16 +1,6 @@
{ {
"parser": "babel-eslint", "parser": "babel-eslint",
"extends": "airbnb", "extends": "standard",
"plugins": [
"react"
],
"rules": {
"semi": [2, "never"],
"no-param-reassign": [2, { "props": false }],
"strict": 0,
"comma-dangle": [2, "never"],
"max-len": [2, 80, 2, { "ignoreComments": true }]
},
"env": { "env": {
"node": true, "node": true,
"mocha": true "mocha": true
+3
View File
@@ -1,4 +1,6 @@
#koa2-api-boilerplate #koa2-api-boilerplate
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)
Boilerplate for building APIs with [koa2](https://github.com/koajs/koa/tree/v2.x) and mongodb. Boilerplate for building APIs with [koa2](https://github.com/koajs/koa/tree/v2.x) and mongodb.
This project covers basic necessities of most APIs. This project covers basic necessities of most APIs.
@@ -6,6 +8,7 @@ This project covers basic necessities of most APIs.
* Database (mongoose) * Database (mongoose)
* Testing (mocha) * Testing (mocha)
* Doc generation with apidoc * Doc generation with apidoc
* linting using standard
##Requirements ##Requirements
* node __^4.0.0__ * node __^4.0.0__
+3 -1
View File
@@ -57,7 +57,9 @@
"babel-register": "^6.5.1", "babel-register": "^6.5.1",
"chai": "^3.5.0", "chai": "^3.5.0",
"eslint": "^3.4.0", "eslint": "^3.4.0",
"eslint-config-airbnb": "^10.0.1", "eslint-config-standard": "^6.0.0",
"eslint-plugin-promise": "^2.0.1",
"eslint-plugin-standard": "^2.0.0",
"mocha": "^3.0.2", "mocha": "^3.0.2",
"nodemon": "^1.8.1", "nodemon": "^1.8.1",
"supertest": "^2.0.0" "supertest": "^2.0.0"
+1 -1
View File
@@ -1,4 +1,4 @@
export function errorMiddleware() { export function errorMiddleware () {
return async (ctx, next) => { return async (ctx, next) => {
try { try {
await next() await next()
+1 -1
View File
@@ -3,7 +3,7 @@ import config from '../../config'
import { getToken } from '../utils/auth' import { getToken } from '../utils/auth'
import { verify } from 'jsonwebtoken' import { verify } from 'jsonwebtoken'
export async function ensureUser(ctx, next) { export async function ensureUser (ctx, next) {
const token = getToken(ctx) const token = getToken(ctx)
if (!token) { if (!token) {
+3 -3
View File
@@ -10,7 +10,7 @@ const User = new mongoose.Schema({
password: { type: String, required: true } password: { type: String, required: true }
}) })
User.pre('save', function preSave(next) { User.pre('save', function preSave (next) {
const user = this const user = this
if (!user.isModified('password')) { if (!user.isModified('password')) {
@@ -35,7 +35,7 @@ User.pre('save', function preSave(next) {
.catch(err => next(err)) .catch(err => next(err))
}) })
User.methods.validatePassword = function validatePassword(password) { User.methods.validatePassword = function validatePassword (password) {
const user = this const user = this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -47,7 +47,7 @@ User.methods.validatePassword = function validatePassword(password) {
}) })
} }
User.methods.generateToken = function generateToken() { User.methods.generateToken = function generateToken () {
const user = this const user = this
return jwt.sign({ id: user.id }, config.token) return jwt.sign({ id: user.id }, config.token)
+1 -1
View File
@@ -50,7 +50,7 @@ import passport from 'koa-passport'
* } * }
*/ */
export async function authUser(ctx, next) { export async function authUser (ctx, next) {
return passport.authenticate('local', (user) => { return passport.authenticate('local', (user) => {
if (!user) { if (!user) {
ctx.throw(401) ctx.throw(401)
+1 -1
View File
@@ -1,7 +1,7 @@
import glob from 'glob' import glob from 'glob'
import Router from 'koa-router' import Router from 'koa-router'
exports = module.exports = function initModules(app) { exports = module.exports = function initModules (app) {
glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => { glob(`${__dirname}/*`, { ignore: '**/index.js' }, (err, matches) => {
if (err) { throw err } if (err) { throw err }
+6 -6
View File
@@ -38,7 +38,7 @@ import User from '../../models/users'
* "error": "Unprocessable Entity" * "error": "Unprocessable Entity"
* } * }
*/ */
export async function createUser(ctx) { export async function createUser (ctx) {
const user = new User(ctx.request.body.user) const user = new User(ctx.request.body.user)
try { try {
await user.save() await user.save()
@@ -84,7 +84,7 @@ export async function createUser(ctx) {
* *
* @apiUse TokenError * @apiUse TokenError
*/ */
export async function getUsers(ctx) { export async function getUsers (ctx) {
const users = await User.find({}, '-password') const users = await User.find({}, '-password')
ctx.body = { users } ctx.body = { users }
} }
@@ -116,7 +116,7 @@ export async function getUsers(ctx) {
* *
* @apiUse TokenError * @apiUse TokenError
*/ */
export async function getUser(ctx, next) { export async function getUser (ctx, next) {
try { try {
const user = await User.findById(ctx.params.id, '-password') const user = await User.findById(ctx.params.id, '-password')
if (!user) { if (!user) {
@@ -134,7 +134,7 @@ export async function getUser(ctx, next) {
ctx.throw(500) ctx.throw(500)
} }
if(next) return next() if (next) { return next() }
} }
/** /**
@@ -177,7 +177,7 @@ export async function getUser(ctx, next) {
* *
* @apiUse TokenError * @apiUse TokenError
*/ */
export async function updateUser(ctx) { export async function updateUser (ctx) {
const user = ctx.body.user const user = ctx.body.user
Object.assign(user, ctx.request.body.user) Object.assign(user, ctx.request.body.user)
@@ -210,7 +210,7 @@ export async function updateUser(ctx) {
* @apiUse TokenError * @apiUse TokenError
*/ */
export async function deleteUser(ctx) { export async function deleteUser (ctx) {
const user = ctx.body.user const user = ctx.body.user
await user.remove() await user.remove()
+1 -1
View File
@@ -1,4 +1,4 @@
export function getToken(ctx) { export function getToken (ctx) {
const header = ctx.request.header.authorization const header = ctx.request.header.authorization
if (!header) { if (!header) {
return null return null
+2 -2
View File
@@ -1,6 +1,6 @@
import mongoose from 'mongoose' import mongoose from 'mongoose'
export function cleanDb() { export function cleanDb () {
for (const collection in mongoose.connection.collections) { for (const collection in mongoose.connection.collections) {
if (mongoose.connection.collections.hasOwnProperty(collection)) { if (mongoose.connection.collections.hasOwnProperty(collection)) {
mongoose.connection.collections[collection].remove() mongoose.connection.collections[collection].remove()
@@ -8,7 +8,7 @@ export function cleanDb() {
} }
} }
export function authUser(agent, callback) { export function authUser (agent, callback) {
agent agent
.post('/users') .post('/users')
.set('Accept', 'application/json') .set('Accept', 'application/json')