Switched from jshint to eslint

Both jshint and jslint contain the 'do no evil' license which
makes it unusable for OpenStack. This patch switches this project
to use eslint, the published eslint-config-openstack rules, and
the john-papa eslint style guides. It also adds the 'npm run lint'
command used by infra in the javascript-jobs macro.

Change-Id: I724d3a12fb5b9c85446adcd07c03a676e966bd41
This commit is contained in:
Michael Krotscheck 2015-10-02 08:42:34 -07:00
parent 5eb5c3a68e
commit b324cd3b6b
28 changed files with 70 additions and 61 deletions

6
.eslintignore Normal file
View File

@ -0,0 +1,6 @@
cover
build
node_modules
coverage
doc
app/vendor-js

11
.eslintrc Normal file
View File

@ -0,0 +1,11 @@
# Use eslint-config-openstack
extends: openstack
# Set up globals
globals:
angular: false
module: false
env:
browser: true
jasmine: true

3
app/.eslintrc Normal file
View File

@ -0,0 +1,3 @@
# Enable eslint-plugin-angular
plugins:
- angular

View File

@ -5,4 +5,4 @@ var bulk = require('bulk-require');
module.exports = angular.module('app.controllers', []);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);

View File

@ -5,4 +5,4 @@ var bulk = require('bulk-require');
module.exports = angular.module('app.directives', []);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);

View File

@ -3,13 +3,13 @@
/**
* @ngInject
*/
function OnRun($rootScope, AppSettings) {
function OnRun ($rootScope, AppSettings) {
// change page title based on state
$rootScope.$on('$stateChangeSuccess', function(event, toState) {
var disable = $rootScope.$on('$stateChangeSuccess', function(event, toState) {
$rootScope.pageTitle = '';
if ( toState.title ) {
if (toState.title) {
$rootScope.pageTitle += toState.title;
$rootScope.pageTitle += ' \u2014 ';
}
@ -17,6 +17,7 @@ function OnRun($rootScope, AppSettings) {
$rootScope.pageTitle += AppSettings.appTitle;
});
$rootScope.$on('$destroy', disable);
}
module.exports = OnRun;
module.exports = OnRun;

View File

@ -5,4 +5,4 @@ var bulk = require('bulk-require');
module.exports = angular.module('app.services', []);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);
bulk(__dirname, ['./**/!(*_index|*.spec).js']);

View File

@ -6,4 +6,4 @@ var tasks = fs.readdirSync('./gulp/tasks/').filter(onlyScripts);
tasks.forEach(function(task) {
require('./tasks/' + task);
});
});

View File

@ -1,15 +1,15 @@
'use strict';
var config = require('../config');
var config = require('../config');
var browserSync = require('browser-sync');
var gulp = require('gulp');
var gulp = require('gulp');
gulp.task('browserSync', function() {
browserSync({
port: config.browserPort,
ui: {
port: config.UIPort
port: config.browserPort,
ui: {
port: config.UIPort
},
proxy: 'localhost:' + config.serverPort
});

View File

@ -6,4 +6,4 @@ gulp.task('deploy', ['prod'], function() {
// Any deployment logic should go here
});
});

View File

@ -1,11 +0,0 @@
'use strict';
var config = require('../config');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
gulp.task('lint', function() {
return gulp.src([config.scripts.src, '!app/js/templates.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});

View File

@ -1,10 +1,10 @@
'use strict';
var gulp = require('gulp');
var protractor = require('gulp-protractor').protractor;
var webdriver = require('gulp-protractor').webdriver;
var gulp = require('gulp');
var protractor = require('gulp-protractor').protractor;
var webdriver = require('gulp-protractor').webdriver;
var webdriverUpdate = require('gulp-protractor').webdriver_update;
var config = require('../config');
var config = require('../config');
gulp.task('webdriver-update', webdriverUpdate);
gulp.task('webdriver', webdriver);
@ -13,11 +13,11 @@ gulp.task('protractor', ['webdriver-update', 'webdriver', 'server'], function()
return gulp.src('test/e2e/**/*.js')
.pipe(protractor({
configFile: config.test.protractor
configFile: config.test.protractor
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
});

View File

@ -1,11 +1,11 @@
'use strict';
var config = require('../config');
var http = require('http');
var config = require('../config');
var http = require('http');
var express = require('express');
var gulp = require('gulp');
var gutil = require('gulp-util');
var morgan = require('morgan');
var gulp = require('gulp');
var gutil = require('gulp-util');
var morgan = require('morgan');
gulp.task('server', function() {
@ -17,13 +17,13 @@ gulp.task('server', function() {
// Serve index.html for all routes to leave routing up to Angular
server.all('/*', function(req, res) {
res.sendFile('index.html', { root: 'build' });
res.sendFile('index.html', {root: 'build'});
});
// Start webserver if not already running
var s = http.createServer(server);
s.on('error', function(err){
if(err.code === 'EADDRINUSE'){
s.on('error', function(err) {
if (err.code === 'EADDRINUSE') {
gutil.log('Development server is already started at port ' + config.serverPort);
}
else {
@ -33,4 +33,4 @@ gulp.task('server', function() {
s.listen(config.serverPort);
});
});

View File

@ -21,4 +21,4 @@ gulp.task('styles', function () {
.pipe(gulp.dest(config.styles.dest))
.pipe(browserSync.reload({ stream: true }));
});
});

View File

@ -7,4 +7,4 @@ gulp.task('test', ['server'], function() {
return runSequence('unit', 'protractor');
});
});

View File

@ -18,4 +18,4 @@ gulp.task('unit', ['views'], function() {
throw err;
});
});
});

View File

@ -18,4 +18,4 @@ gulp.task('views', function() {
}))
.pipe(gulp.dest(config.views.dest));
});
});

View File

@ -6,7 +6,6 @@ var gulp = require('gulp');
gulp.task('watch', ['browserSync', 'server'], function() {
// Scripts are automatically watched and rebundled by Watchify inside Browserify task
gulp.watch(config.scripts.src, ['lint']);
gulp.watch(config.styles.src, ['styles']);
gulp.watch(config.fonts.src, ['fonts']);
gulp.watch(config.data.src, ['data']);

View File

@ -22,4 +22,4 @@ module.exports = {
gutil.log('Finished', gutil.colors.green('\'bundle\''), 'in', gutil.colors.magenta(prettyTime));
}
};
};

View File

@ -4,7 +4,7 @@ var notify = require('gulp-notify');
module.exports = function(error) {
if( !global.isProd ) {
if (!global.isProd) {
var args = Array.prototype.slice.call(arguments);
@ -20,8 +20,6 @@ module.exports = function(error) {
} else {
// Log the error and stop the process
// to prevent broken code from building
console.log(error);
process.exit(1);
throw Error(error);
}
};
};

View File

@ -8,4 +8,4 @@ module.exports = function(name) {
return /(\.(js)$)/i.test(path.extname(name));
};
};

View File

@ -23,6 +23,9 @@
"bulkify": "^1.1.1",
"d3": "^3.5.6",
"del": "^0.1.3",
"eslint": "1.5.1",
"eslint-config-openstack": "1.2.2",
"eslint-plugin-angular": "0.12.0",
"express": "^4.7.2",
"gulp": "^3.8.8",
"gulp-angular-templatecache": "^1.3.0",
@ -32,7 +35,6 @@
"gulp-filter": "^3.0.1",
"gulp-gzip": "^0.0.8",
"gulp-if": "^1.2.5",
"gulp-jshint": "^1.8.3",
"gulp-karma": "0.0.4",
"gulp-notify": "^2.0.0",
"gulp-protractor": "0.0.11",
@ -47,7 +49,6 @@
"jasmine-ajax": "^3.1.1",
"jasmine-core": "^2.3.4",
"jasmine-fixture": "^1.3.2",
"jshint-stylish": "^1.0.0",
"karma": "~0.12.0",
"karma-babel-preprocessor": "^4.0.1",
"karma-browserify": "^4.0.0",
@ -72,7 +73,8 @@
"pretest": "npm install",
"test": "karma start test/karma.conf.js",
"preprotractor": "npm run update-webdriver",
"protractor": "npm run protractor test/protractor.conf.js"
"protractor": "npm run protractor test/protractor.conf.js",
"lint": "eslint ./"
},
"dependencies": {},
"browserify": {

View File

@ -18,4 +18,4 @@ describe('E2E: Example', function() {
expect(element.getText()).toEqual('1234');
});
});
});

View File

@ -9,4 +9,4 @@ describe('E2E: Routes', function() {
expect(browser.getLocationAbsUrl()).toMatch('/');
});
});
});

View File

@ -29,4 +29,4 @@ exports.config = {
'e2e/**/*.js'
]
};
};

View File

@ -24,4 +24,4 @@ describe('Unit: Constants', function() {
expect(constants.appTitle).toEqual('Example Application');
});
});
});

View File

@ -27,4 +27,4 @@ describe('Unit: ExampleCtrl', function() {
expect(ctrl.title).toEqual('AngularJS, Gulp, and Browserify!');
});
});
});

View File

@ -20,4 +20,4 @@ describe('Unit: ExampleService', function() {
expect(service).toBeDefined();
});
});
});