From c35ed5b8fd1ef3c84582905015147ead16b298f2 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 4 Jul 2016 11:07:58 +0200 Subject: [PATCH] add linter --- gulpfile.js | 24 ++++++++++++------------ package.json | 16 ++++++++++++++-- password-generator.js | 18 +++++++----------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index c2cf622..102b60c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; var gulp = require('gulp'); var del = require('del'); @@ -7,21 +7,21 @@ var autoprefixer = require('gulp-autoprefixer'); var minifyCss = require('gulp-cssnano'); var paths = { - build: "dist/", + build: 'dist/', html: [ 'index.html' ], js: [ 'password-generator.js' ], - js_vendors: [ + jsVendors: [ 'node_modules/lesspass/dist/lesspass.min.js', 'node_modules/clipboard/dist/clipboard.min.js' ], styles: [ 'style.css' ], - styles_vendors: [ + stylesVendors: [ 'node_modules/bootstrap/dist/css/bootstrap.min.css', 'node_modules/font-awesome/css/font-awesome.min.css', 'node_modules/hint.css/hint.min.css' @@ -61,8 +61,8 @@ gulp.task('styles', function () { .pipe(gulp.dest(paths.build + '/styles')); }); -gulp.task('styles_vendors', function () { - return gulp.src(paths.styles_vendors) +gulp.task('stylesVendors', function () { + return gulp.src(paths.stylesVendors) .pipe(gulp.dest(paths.build + 'styles/')); }); @@ -71,20 +71,20 @@ gulp.task('js', function () { .pipe(gulp.dest(paths.build + 'js/')); }); -gulp.task('js_vendors', function () { - return gulp.src(paths.js_vendors) +gulp.task('jsVendors', function () { + return gulp.src(paths.jsVendors) .pipe(gulp.dest(paths.build + 'js/')); }); gulp.task('build', ['clean'], function () { - gulp.start('js', 'js_vendors', 'html', 'styles', 'styles_vendors', 'fonts', 'images'); + gulp.start('js', 'jsVendors', 'html', 'styles', 'stylesVendors', 'fonts', 'images'); }); gulp.task('watch', ['build'], function () { gulp.watch(paths.js, ['js']); - gulp.watch(paths.js_vendors, ['js_vendors']); + gulp.watch(paths.jsVendors, ['jsVendors']); gulp.watch(paths.styles, ['styles']); - gulp.watch(paths.styles_vendors, ['styles_vendors']); + gulp.watch(paths.stylesVendors, ['stylesVendors']); gulp.watch(paths.html, ['html']); gulp.watch(paths.images, ['images']); gulp.watch(paths.fonts, ['fonts']); @@ -92,4 +92,4 @@ gulp.task('watch', ['build'], function () { gulp.task('default', ['watch'], function () { -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index dc6112d..29e1148 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "scripts": { "build": "gulp build", - "build:watch": "gulp" + "build:watch": "gulp", + "test": "xo" }, "dependencies": { "bootstrap": "^4.0.0-alpha.2", @@ -15,6 +16,17 @@ "gulp": "^3.9.1", "gulp-autoprefixer": "^3.1.0", "gulp-concat": "^2.6.0", - "gulp-cssnano": "^2.1.2" + "gulp-cssnano": "^2.1.2", + "xo": "^0.16.0" + }, + "xo": { + "space": true, + "envs": [ + "browser", + "webextensions" + ], + "ignores": [ + "dist/**" + ] } } diff --git a/password-generator.js b/password-generator.js index bbda477..b6ea7b4 100644 --- a/password-generator.js +++ b/password-generator.js @@ -1,3 +1,5 @@ +/* global lesspass Clipboard */ + function showTooltip(elem, msg) { var classNames = elem.className; elem.setAttribute('class', classNames + ' hint--top'); @@ -39,7 +41,6 @@ function displayPasswordIndication() { }); } - document.getElementById('copyPasswordButton').addEventListener('click', generatePassword); document.getElementById('generatedPasswordForm').addEventListener('change', generatePassword); document.getElementById('passwordLength').addEventListener('input', generatePassword); @@ -83,17 +84,15 @@ function generatePassword() { }); } - document.getElementById('displayMasterPasswordButton').addEventListener('click', toggleMasterPassword); function toggleMasterPassword() { - if (document.getElementById('masterPassword').type == 'password') { + if (document.getElementById('masterPassword').type === 'password') { document.getElementById('masterPassword').type = 'text'; } else { document.getElementById('masterPassword').type = 'password'; } } - var clipboard = new Clipboard('.btn-copy'); clipboard.on('success', function (e) { @@ -102,17 +101,14 @@ clipboard.on('success', function (e) { e.clearSelection(); } }); -clipboard.on('error', function (e) { -}); - document.getElementById('displayOptionsButton').addEventListener('click', toggleBlocks); -function toggle_visibility(className) { +function toggleVisibility(className) { var elements = document.getElementsByClassName(className); for (var i = 0; i < elements.length; i++) { var e = elements[i]; - if (e.style.display == 'block') { + if (e.style.display === 'block') { e.style.display = 'none'; } else { e.style.display = 'block'; @@ -121,5 +117,5 @@ function toggle_visibility(className) { } function toggleBlocks() { - toggle_visibility('option-block'); -} \ No newline at end of file + toggleVisibility('option-block'); +}