Merge pull request #1994 from clarkdo/examples_lint

refactor: add examples to lint
This commit is contained in:
Sébastien Chopin 2017-10-31 15:02:13 +01:00 committed by GitHub
commit a99ecda752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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: {
routes: [
'/posts/1',
'/posts/1'
]
}
}

View File

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

View File

@ -1,6 +1,5 @@
const app = require('express')()
const { Nuxt, Builder } = require('nuxt')
const chalk = require('chalk')
const host = process.env.HOST || '127.0.0.1'
const port = process.env.PORT || 3000
@ -22,4 +21,3 @@ app.use(nuxt.render)
// Start express server
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()
img.onload = () => {
this.loaded = true
};
}
img.src = this.data
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,15 +7,14 @@
<script>
import DoughnutChart from '~/components/doughnut-chart'
import axios from 'axios'
import moment from 'moment'
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
var letters = '0123456789ABCDEF'
var color = '#'
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 {

View File

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

View File

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

View File

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

View File

@ -1,20 +1,20 @@
'use strict';
'use strict'
const path = require('path');
const compress = require('compression');
const cors = require('cors');
const feathers = require('feathers');
const configuration = require('feathers-configuration');
const hooks = require('feathers-hooks');
const rest = require('feathers-rest');
const bodyParser = require('body-parser');
const socketio = require('feathers-socketio');
const middleware = require('./middleware');
const services = require('./services');
const path = require('path')
const compress = require('compression')
const cors = require('cors')
const feathers = require('feathers')
const configuration = require('feathers-configuration')
const hooks = require('feathers-hooks')
const rest = require('feathers-rest')
const bodyParser = require('body-parser')
const socketio = require('feathers-socketio')
const middleware = require('./middleware')
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())
.options('*', cors())
@ -25,6 +25,6 @@ app.use(compress())
.configure(rest())
.configure(socketio())
.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.
//
@ -8,6 +8,6 @@
exports.myHook = function (options) {
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 port = app.get('port');
const app = require('./app')
const port = app.get('port')
process.on('nuxt:build:done', (err) => {
if (err) {
console.error(err);
process.exit(1);
console.error(err) // eslint-disable-line no-console
process.exit(1)
}
const server = app.listen(port);
const server = app.listen(port)
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 () {
// Add your custom middleware here. Remember, that
// just like Express the order matters, so error
// 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';
const authentication = require('feathers-authentication');
'use strict'
const authentication = require('feathers-authentication')
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';
const authentication = require('./authentication');
const user = require('./user');
'use strict'
const authentication = require('./authentication')
const user = require('./user')
module.exports = function () {
const app = this;
const app = this
app.configure(authentication);
app.configure(user);
};
app.configure(authentication)
app.configure(user)
}

View File

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

View File

@ -1,17 +1,17 @@
'use strict';
'use strict'
const path = require('path');
const NeDB = require('nedb');
const service = require('feathers-nedb');
const hooks = require('./hooks');
const path = require('path')
const NeDB = require('nedb')
const service = require('feathers-nedb')
const hooks = require('./hooks')
module.exports = function () {
const app = this;
const app = this
const db = new NeDB({
filename: path.join(app.get('nedb'), 'users.db'),
autoload: true
});
})
let options = {
Model: db,
@ -19,17 +19,17 @@ module.exports = function(){
default: 5,
max: 25
}
};
}
// 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
const userService = app.service('/users');
const userService = app.service('/users')
// Set up our before hooks
userService.before(hooks.before);
userService.before(hooks.before)
// 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 request = require('request');
const app = require('../src/app');
const assert = require('assert')
const request = require('request')
const app = require('../src/app')
describe('Feathers application tests', function () {
before(function (done) {
this.server = app.listen(3030);
this.server.once('listening', () => done());
});
this.server = app.listen(3030)
this.server.once('listening', () => done())
})
after(function (done) {
this.server.close(done);
});
this.server.close(done)
})
it('starts and shows the index page', function (done) {
request('http://localhost:3030', function (err, res, body) {
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1);
done(err);
});
});
assert.ok(body.indexOf('<h1>Welcome!</h1>') !== -1)
done(err)
})
})
describe('404', function () {
it('shows a 404 HTML page', function (done) {
@ -29,10 +29,10 @@ describe('Feathers application tests', function() {
'Accept': 'text/html'
}
}, function (err, res, body) {
assert.equal(res.statusCode, 404);
assert.ok(body.indexOf('This page could not be found.') !== -1);
done(err);
});
});
});
});
assert.equal(res.statusCode, 404)
assert.ok(body.indexOf('This page could not be found.') !== -1)
done(err)
})
})
})
})

View File

@ -1,10 +1,10 @@
'use strict';
'use strict'
const assert = require('assert');
const app = require('../../../src/app');
const assert = require('assert')
const app = require('../../../src/app')
describe('user service', function () {
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']
};
}

View File

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

View File

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

View File

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

View File

@ -49,7 +49,7 @@
"scripts": {
"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",
"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:nuxt": "rollup -c build/rollup.config.js --environment TARGET:nuxt",
"build:core": "rollup -c build/rollup.config.js --environment TARGET:core",