refactor: add examples to lint

This commit is contained in:
Clark Du 2017-10-31 21:43:55 +08:00
parent b132decf9d
commit 3e637c5d83
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
94 changed files with 360 additions and 330 deletions

4
.eslintignore Normal file
View File

@ -0,0 +1,4 @@
app
node_modules
dist
.nuxt

View File

@ -12,7 +12,7 @@ module.exports = {
}, },
generate: { generate: {
routes: [ routes: [
'/posts/1', '/posts/1'
] ]
} }
} }

View File

@ -1,7 +1,6 @@
{ {
"name": "nuxt-custom-server", "name": "nuxt-custom-server",
"dependencies": { "dependencies": {
"chalk": "^2.2.0",
"express": "^4.15.3", "express": "^4.15.3",
"nuxt": "latest" "nuxt": "latest"
}, },

View File

@ -1,6 +1,5 @@
const app = require('express')() const app = require('express')()
const { Nuxt, Builder } = require('nuxt') const { Nuxt, Builder } = require('nuxt')
const chalk = require('chalk')
const host = process.env.HOST || '127.0.0.1' const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000 const port = process.env.PORT || 3000
@ -22,4 +21,3 @@ app.use(nuxt.render)
// Start express server // Start express server
app.listen(port, host) app.listen(port, host)
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${host}:${port}`))

View File

@ -18,7 +18,7 @@ export default {
const img = new Image() const img = new Image()
img.onload = () => { img.onload = () => {
this.loaded = true this.loaded = true
}; }
img.src = this.data img.src = this.data
} }
} }

View File

@ -7,6 +7,6 @@
<script> <script>
export default { export default {
layout: ({ isMobile }) => isMobile ? 'mobile' : 'default', layout: ({ isMobile }) => isMobile ? 'mobile' : 'default'
} }
</script> </script>

View File

@ -6,7 +6,7 @@ module.exports = {
router: { router: {
middleware: 'i18n' middleware: 'i18n'
}, },
plugins: ['~/plugins/i18n.js',], plugins: ['~/plugins/i18n.js'],
generate: { generate: {
routes: ['/', '/about', '/fr', '/fr/about'] routes: ['/', '/about', '/fr', '/fr/about']
} }

View File

@ -9,10 +9,10 @@
</template> </template>
// **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object // **PLEASE NOTE** All "Nuxt Class Components" require at minimum a script tag that exports a default object
<script lang="ts"> <script lang="ts">
import Vue from "vue" import Vue from 'vue'
import Component from "nuxt-class-component" import Component from 'nuxt-class-component'
import { Prop } from 'vue-property-decorator' import { Prop } from 'vue-property-decorator'
import { Action } from "vuex-class" import { Action } from 'vuex-class'
@Component({}) @Component({})
export default class Card extends Vue { export default class Card extends Vue {

View File

@ -2,11 +2,11 @@ module.exports = function(options) {
// Extend build // Extend build
this.extendBuild(config => { this.extendBuild(config => {
const tsLoader = { const tsLoader = {
loader: "ts-loader", loader: 'ts-loader',
options: { options: {
appendTsSuffixTo: [/\.vue$/] appendTsSuffixTo: [/\.vue$/]
} }
}; }
// Add TypeScript loader // Add TypeScript loader
config.module.rules.push( config.module.rules.push(
Object.assign( Object.assign(
@ -15,12 +15,12 @@ module.exports = function(options) {
}, },
tsLoader tsLoader
) )
); )
// Add TypeScript loader for vue files // Add TypeScript loader for vue files
for (let rule of config.module.rules) { for (let rule of config.module.rules) {
if (rule.loader === "vue-loader") { if (rule.loader === 'vue-loader') {
rule.options.loaders.ts = tsLoader; rule.options.loaders.ts = tsLoader
} }
} }
}); })
}; }

View File

@ -14,10 +14,10 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from "vue"; import Vue from 'vue'
import Component from "nuxt-class-component" import Component from 'nuxt-class-component'
import Card from "~/components/Card" import Card from '~/components/Card'
import { State, Getter } from "vuex-class" import { State, Getter } from 'vuex-class'
@Component({ @Component({
components: { components: {

View File

@ -2,4 +2,4 @@ import UIkit from 'uikit'
import Icons from 'uikit/dist/js/uikit-icons' import Icons from 'uikit/dist/js/uikit-icons'
// loads the Icon plugin // loads the Icon plugin
UIkit.use(Icons); UIkit.use(Icons)

View File

@ -7,15 +7,14 @@
<script> <script>
import DoughnutChart from '~/components/doughnut-chart' import DoughnutChart from '~/components/doughnut-chart'
import axios from 'axios' import axios from 'axios'
import moment from 'moment'
function getRandomColor() { function getRandomColor() {
var letters = '0123456789ABCDEF'; var letters = '0123456789ABCDEF'
var color = '#'; var color = '#'
for (var i = 0; i < 6; i++) { for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)]; color += letters[Math.floor(Math.random() * 16)]
} }
return color; return color
} }
export default { export default {

View File

@ -34,7 +34,7 @@ export default class Base extends Vue {
// method // method
greet() { greet() {
console.log('base greeting: ' + this.msg) console.log('base greeting: ' + this.msg) // eslint-disable-line no-console
} }
} }
</script> </script>

View File

@ -17,7 +17,7 @@ import Base from '@/components/Base'
export default class Child extends Base { export default class Child extends Base {
// override parent method // override parent method
greet() { greet() {
console.log('child greeting: ' + this.msg) console.log('child greeting: ' + this.msg) // eslint-disable-line no-console
} }
} }
</script> </script>

View File

@ -0,0 +1,36 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
node: true,
mocha: true
},
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
rules: {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
// do not allow console.logs etc...
'no-console': 2,
'space-before-function-paren': [
2,
{
anonymous: 'always',
named: 'never'
}
],
},
globals: {}
}

View File

@ -2,4 +2,4 @@ module.exports = {
loading: { loading: {
color: 'purple' color: 'purple'
} }
}; }

View File

@ -37,6 +37,7 @@
"winston": "^2.3.0" "winston": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"jshint": "^2.9.4", "jshint": "^2.9.4",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"nodemon": "^1.11.0", "nodemon": "^1.11.0",

View File

@ -1,20 +1,20 @@
'use strict'; 'use strict'
const path = require('path'); const path = require('path')
const compress = require('compression'); const compress = require('compression')
const cors = require('cors'); const cors = require('cors')
const feathers = require('feathers'); const feathers = require('feathers')
const configuration = require('feathers-configuration'); const configuration = require('feathers-configuration')
const hooks = require('feathers-hooks'); const hooks = require('feathers-hooks')
const rest = require('feathers-rest'); const rest = require('feathers-rest')
const bodyParser = require('body-parser'); const bodyParser = require('body-parser')
const socketio = require('feathers-socketio'); const socketio = require('feathers-socketio')
const middleware = require('./middleware'); const middleware = require('./middleware')
const services = require('./services'); const services = require('./services')
const app = feathers(); const app = feathers()
app.configure(configuration(path.join(__dirname, '..'))); app.configure(configuration(path.join(__dirname, '..')))
app.use(compress()) app.use(compress())
.options('*', cors()) .options('*', cors())
@ -25,6 +25,6 @@ app.use(compress())
.configure(rest()) .configure(rest())
.configure(socketio()) .configure(socketio())
.configure(services) .configure(services)
.configure(middleware); .configure(middleware)
module.exports = app; module.exports = app

View File

@ -1,4 +1,4 @@
'use strict'; 'use strict'
// Add any common hooks you want to share across services in here. // Add any common hooks you want to share across services in here.
// //
@ -8,6 +8,6 @@
exports.myHook = function (options) { exports.myHook = function (options) {
return function (hook) { return function (hook) {
console.log('My custom global hook ran. Feathers is awesome!'); console.log('My custom global hook ran. Feathers is awesome!') // eslint-disable-line no-console
}; }
}; }

View File

@ -1,15 +1,15 @@
'use strict'; 'use strict'
const app = require('./app'); const app = require('./app')
const port = app.get('port'); const port = app.get('port')
process.on('nuxt:build:done', (err) => { process.on('nuxt:build:done', (err) => {
if (err) { if (err) {
console.error(err); console.error(err) // eslint-disable-line no-console
process.exit(1); process.exit(1)
} }
const server = app.listen(port); const server = app.listen(port)
server.on('listening', () => server.on('listening', () =>
console.log(`Feathers application started on ${app.get('host')}:${port}`) console.log(`Feathers application started on ${app.get('host')}:${port}`) // eslint-disable-line no-console
); )
}); })

View File

@ -1,12 +1,12 @@
'use strict'; 'use strict'
const nuxt = require('./nuxt'); const nuxt = require('./nuxt')
module.exports = function () { module.exports = function () {
// Add your custom middleware here. Remember, that // Add your custom middleware here. Remember, that
// just like Express the order matters, so error // just like Express the order matters, so error
// handling middleware should go last. // handling middleware should go last.
const app = this; const app = this
app.use(nuxt); app.use(nuxt)
}; }

View File

@ -1,14 +1,11 @@
'use strict'; 'use strict'
const authentication = require('feathers-authentication');
const authentication = require('feathers-authentication')
module.exports = function () { module.exports = function () {
const app = this; const app = this
let config = app.get('auth'); let config = app.get('auth')
app.configure(authentication(config))
}
app.configure(authentication(config));
};

View File

@ -1,11 +1,10 @@
'use strict'; 'use strict'
const authentication = require('./authentication'); const authentication = require('./authentication')
const user = require('./user'); const user = require('./user')
module.exports = function () { module.exports = function () {
const app = this; const app = this
app.configure(authentication)
app.configure(authentication); app.configure(user)
app.configure(user); }
};

View File

@ -1,8 +1,8 @@
'use strict'; 'use strict'
const globalHooks = require('../../../hooks'); require('../../../hooks')
const hooks = require('feathers-hooks'); const hooks = require('feathers-hooks')
const auth = require('feathers-authentication').hooks; const auth = require('feathers-authentication').hooks
exports.before = { exports.before = {
all: [], all: [],
@ -38,7 +38,7 @@ exports.before = {
auth.restrictToAuthenticated(), auth.restrictToAuthenticated(),
auth.restrictToOwner({ ownerField: '_id' }) auth.restrictToOwner({ ownerField: '_id' })
] ]
}; }
exports.after = { exports.after = {
all: [hooks.remove('password')], all: [hooks.remove('password')],
@ -48,4 +48,4 @@ exports.after = {
update: [], update: [],
patch: [], patch: [],
remove: [] remove: []
}; }

View File

@ -1,17 +1,17 @@
'use strict'; 'use strict'
const path = require('path'); const path = require('path')
const NeDB = require('nedb'); const NeDB = require('nedb')
const service = require('feathers-nedb'); const service = require('feathers-nedb')
const hooks = require('./hooks'); const hooks = require('./hooks')
module.exports = function () { module.exports = function () {
const app = this; const app = this
const db = new NeDB({ const db = new NeDB({
filename: path.join(app.get('nedb'), 'users.db'), filename: path.join(app.get('nedb'), 'users.db'),
autoload: true autoload: true
}); })
let options = { let options = {
Model: db, Model: db,
@ -19,17 +19,17 @@ module.exports = function(){
default: 5, default: 5,
max: 25 max: 25
} }
}; }
// Initialize our service with any options it requires // Initialize our service with any options it requires
app.use('/users', service(options)); app.use('/users', service(options))
// Get our initialize service to that we can bind hooks // Get our initialize service to that we can bind hooks
const userService = app.service('/users'); const userService = app.service('/users')
// Set up our before hooks // Set up our before hooks
userService.before(hooks.before); userService.before(hooks.before)
// Set up our after hooks // Set up our after hooks
userService.after(hooks.after); userService.after(hooks.after)
}; }

View File

@ -1,25 +1,25 @@
'use strict'; 'use strict'
const assert = require('assert'); const assert = require('assert')
const request = require('request'); const request = require('request')
const app = require('../src/app'); const app = require('../src/app')
describe('Feathers application tests', function () { describe('Feathers application tests', function () {
before(function (done) { before(function (done) {
this.server = app.listen(3030); this.server = app.listen(3030)
this.server.once('listening', () => done()); this.server.once('listening', () => done())
}); })
after(function (done) { after(function (done) {
this.server.close(done); this.server.close(done)
}); })
it('starts and shows the index page', function (done) { it('starts and shows the index page', function (done) {
request('http://localhost:3030', function (err, res, body) { request('http://localhost:3030', function (err, res, body) {
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1); assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1)
done(err); done(err)
}); })
}); })
describe('404', function () { describe('404', function () {
it('shows a 404 HTML page', function (done) { it('shows a 404 HTML page', function (done) {
@ -29,10 +29,10 @@ describe('Feathers application tests', function() {
'Accept': 'text/html' 'Accept': 'text/html'
} }
}, function (err, res, body) { }, function (err, res, body) {
assert.equal(res.statusCode, 404); assert.equal(res.statusCode, 404)
assert.ok(body.indexOf('This page could not be found.') !== -1); assert.ok(body.indexOf('This page could not be found.') !== -1)
done(err); done(err)
}); })
}); })
}); })
}); })

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict'
const assert = require('assert'); const assert = require('assert')
const app = require('../../../src/app'); const app = require('../../../src/app')
describe('user service', function () { describe('user service', function () {
it('registered the users service', () => { it('registered the users service', () => {
assert.ok(app.service('users')); assert.ok(app.service('users'))
}); })
}); })

View File

@ -23,4 +23,4 @@ module.exports = {
] ]
}, },
plugins: ['~/plugins/museui'] plugins: ['~/plugins/museui']
}; }

View File

@ -30,7 +30,7 @@
}, },
methods: { methods: {
toggle(flag) { toggle(flag) {
this.open = !this.open; this.open = !this.open
} }
} }
} }

View File

@ -1,4 +1,4 @@
import Vue from 'vue'; import Vue from 'vue'
import MuseUI from 'muse-ui'; import MuseUI from 'muse-ui'
Vue.use(MuseUI); Vue.use(MuseUI)

View File

@ -1,6 +1,3 @@
const { join } = require('path')
module.exports = { module.exports = {
/* /*
** Head elements ** Head elements

View File

@ -49,7 +49,7 @@
"scripts": { "scripts": {
"test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html", "test": "npm run lint && cross-env NODE_ENV=test npm run build:nuxt && nyc ava --verbose --serial test/ -- && nyc report --reporter=html",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint --ext .js,.vue bin/** lib/** test/** --ignore-pattern app --ignore-pattern node_modules --ignore-pattern dist/", "lint": "eslint --ext .js,.vue bin/** lib/** test/*.js examples/**",
"build": "rimraf dist/ && npm run build:nuxt && npm run build:core", "build": "rimraf dist/ && npm run build:nuxt && npm run build:core",
"build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt", "build:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core", "build:core": "rollup -c build/rollup.config.js --environment TARGET:core",