Switch to eslint.

This ports over changes made in openstack-health to convert the
project from jshint to eslint, with the eslint-config-openstack
plugin.

Change-Id: Iaa0490d07603e2481e1c738136f9fda1be95dea8
This commit is contained in:
Tim Buckley 2015-11-18 15:36:36 -07:00
parent 42b83c81da
commit 7eab971d3f
18 changed files with 73 additions and 87 deletions

8
.eslintignore Normal file
View File

@ -0,0 +1,8 @@
cover
build
node_modules
coverage
doc
app/vendor-js
app/js/templates.js
gulp

14
.eslintrc Normal file
View File

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

View File

@ -1,20 +0,0 @@
{
"node": true,
"jasmine": true,
"browser": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"noarg": true,
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"newcap": false
}

7
app/.eslintrc Normal file
View File

@ -0,0 +1,7 @@
# Enable eslint-plugin-angular
plugins:
- angular
rules:
angular/module-setter: 0
angular/module-getter: 0

View File

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

View File

@ -52,10 +52,10 @@ var getDstatLanes = function(data, mins, maxes) {
if ('memory_usage_used' in row) { if ('memory_usage_used' in row) {
lanes.push([{ lanes.push([{
scale: d3.scale.linear().domain([0, maxes.memory_usage_used]), scale: d3.scale.linear().domain([0, maxes.memory_usage_used]),
value: function(d) { return d.memory_usage_used; }, value: function(d) { return d.memory_usage_used; },
color: "rgba(102, 140, 178, 0.75)", color: "rgba(102, 140, 178, 0.75)",
text: "Memory" text: "Memory"
}]); }]);
} }
@ -96,7 +96,7 @@ var getDstatLanes = function(data, mins, maxes) {
/** /**
* @ngInject * @ngInject
*/ */
function timeline(datasetService) { function timeline($log, datasetService) {
var link = function(scope, el, attrs) { var link = function(scope, el, attrs) {
var data = []; var data = [];
var dstat = {}; var dstat = {};
@ -578,7 +578,7 @@ function timeline(datasetService) {
// (dstat may not exist, but that's okay) // (dstat may not exist, but that's okay)
initData(raw, dstat); initData(raw, dstat);
}).catch(function(ex) { }).catch(function(ex) {
console.error(ex); $log.error(ex);
}); });
}); });
}; };

View File

@ -12,33 +12,25 @@ require('./services/_index');
require('./directives/_index'); require('./directives/_index');
require('./filters/_index'); require('./filters/_index');
var bootstrap = function() { var requires = [
'ui.router',
'ui.bootstrap',
'templates',
'app.controllers',
'app.services',
'app.directives',
'app.filters',
'picardy.fontawesome'
];
var requires = [ angular.module('app', requires);
'ui.router',
'ui.bootstrap',
'templates',
'app.controllers',
'app.services',
'app.directives',
'app.filters',
'picardy.fontawesome'
];
// mount on window for testing angular.module('app').constant('AppSettings', require('./constants'));
window.app = angular.module('app', requires);
angular.module('app').constant('AppSettings', require('./constants')); var onConfig = require('./on_config');
angular.module('app').config(onConfig);
angular.module('app').config(require('./on_config')); var onRun = require('./on_run');
angular.module('app').run(require('./on_run'));
angular.module('app').run(require('./on_run')); angular.bootstrap(document, ['app']);
angular.bootstrap(document, ['app']);
window.bootstrap = null;
};
// create and bootstrap application
angular.element(document).ready(bootstrap);
window.bootstrap = bootstrap;

View File

@ -6,10 +6,10 @@
function OnRun($rootScope, AppSettings) { function OnRun($rootScope, AppSettings) {
// change page title based on state // change page title based on state
$rootScope.$on('$stateChangeSuccess', function(event, toState) { var disable = $rootScope.$on('$stateChangeSuccess', function(event, toState) {
$rootScope.pageTitle = ''; $rootScope.pageTitle = '';
if ( toState.title ) { if (toState.title) {
$rootScope.pageTitle += toState.title; $rootScope.pageTitle += toState.title;
$rootScope.pageTitle += ' \u2014 '; $rootScope.pageTitle += ' \u2014 ';
} }
@ -17,6 +17,8 @@ function OnRun($rootScope, AppSettings) {
$rootScope.pageTitle += AppSettings.appTitle; $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', []); module.exports = angular.module('app.services', []);
bulk(__dirname, ['./**/!(*_index|*.spec).js']); bulk(__dirname, ['./**/!(*_index|*.spec).js']);

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

@ -6,7 +6,6 @@ var gulp = require('gulp');
gulp.task('watch', ['browserSync', 'server'], function() { gulp.task('watch', ['browserSync', 'server'], function() {
// Scripts are automatically watched and rebundled by Watchify inside Browserify task // 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.styles.src, ['styles']);
gulp.watch(config.images.src, ['images']); gulp.watch(config.images.src, ['images']);
gulp.watch(config.fonts.src, ['fonts']); gulp.watch(config.fonts.src, ['fonts']);

View File

@ -23,8 +23,9 @@
"d3": "^3.5.6", "d3": "^3.5.6",
"debowerify": "^1.2.0", "debowerify": "^1.2.0",
"del": "^0.1.3", "del": "^0.1.3",
"eslint": "^0.23.0", "eslint": "1.5.1",
"eslint-config-openstack": "1.2.0", "eslint-config-openstack": "1.2.2",
"eslint-plugin-angular": "0.12.0",
"express": "^4.7.2", "express": "^4.7.2",
"gulp": "^3.8.8", "gulp": "^3.8.8",
"gulp-angular-templatecache": "^1.3.0", "gulp-angular-templatecache": "^1.3.0",
@ -34,7 +35,6 @@
"gulp-gzip": "^0.0.8", "gulp-gzip": "^0.0.8",
"gulp-if": "^1.2.5", "gulp-if": "^1.2.5",
"gulp-imagemin": "^1.1.0", "gulp-imagemin": "^1.1.0",
"gulp-jshint": "^1.8.3",
"gulp-karma": "0.0.4", "gulp-karma": "0.0.4",
"gulp-notify": "^2.0.0", "gulp-notify": "^2.0.0",
"gulp-protractor": "0.0.11", "gulp-protractor": "0.0.11",
@ -49,7 +49,6 @@
"jasmine-ajax": "^3.1.1", "jasmine-ajax": "^3.1.1",
"jasmine-core": "^2.3.4", "jasmine-core": "^2.3.4",
"jasmine-fixture": "^1.3.2", "jasmine-fixture": "^1.3.2",
"jshint-stylish": "^1.0.0",
"karma": "~0.12.0", "karma": "~0.12.0",
"karma-babel-preprocessor": "^4.0.1", "karma-babel-preprocessor": "^4.0.1",
"karma-browserify": "^4.0.0", "karma-browserify": "^4.0.0",
@ -71,7 +70,7 @@
"scripts": { "scripts": {
"postinstall": "if [ ! -d .venv ]; then tox -epy27 --notest; fi", "postinstall": "if [ ! -d .venv ]; then tox -epy27 --notest; fi",
"test": "gulp unit", "test": "gulp unit",
"lint": "eslint --no-color stackviz/static" "lint": "eslint ./"
}, },
"dependencies": {} "dependencies": {}
} }

View File

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

View File

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

View File

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

View File

@ -2,8 +2,6 @@
'use strict'; 'use strict';
window.bootstrap && window.bootstrap();
describe('Unit: HomeCtrl', function() { describe('Unit: HomeCtrl', function() {
var ctrl; var ctrl;

View File

@ -2,8 +2,6 @@
'use strict'; 'use strict';
window.bootstrap && window.bootstrap();
describe('Unit: DatasetService', function() { describe('Unit: DatasetService', function() {
var service, httpBackend; var service, httpBackend;
@ -13,7 +11,7 @@ describe('Unit: DatasetService', function() {
"tree": "tempest_file_freshlog_0_tree.json", "tree": "tempest_file_freshlog_0_tree.json",
"id": 0, "id": 0,
"name": "Subunit File: freshlog"} "name": "Subunit File: freshlog"}
]}; ]};
beforeEach(function() { beforeEach(function() {
// instantiate the app module // instantiate the app module
@ -32,7 +30,7 @@ describe('Unit: DatasetService', function() {
it('should return config.json', function() { it('should return config.json', function() {
httpBackend.whenGET("data/config.json").respond(exampleConfig); httpBackend.whenGET("data/config.json").respond(exampleConfig);
service.list().then(function(config){ service.list().then(function(config) {
expect(config.data).toEqual(exampleConfig); expect(config.data).toEqual(exampleConfig);
}); });
httpBackend.flush(); httpBackend.flush();
@ -40,28 +38,28 @@ describe('Unit: DatasetService', function() {
it('should GET the raw file from a dataset', function() { it('should GET the raw file from a dataset', function() {
httpBackend.whenGET(exampleConfig.raw).respond(exampleConfig.raw); httpBackend.whenGET(exampleConfig.raw).respond(exampleConfig.raw);
service.raw(exampleConfig).then(function(raw){ service.raw(exampleConfig).then(function(raw) {
expect(raw).toEqual(exampleConfig.raw); expect(raw).toEqual(exampleConfig.raw);
}); });
}); });
it('should GET the details file from a dataset', function() { it('should GET the details file from a dataset', function() {
httpBackend.whenGET(exampleConfig.details).respond(exampleConfig.details); httpBackend.whenGET(exampleConfig.details).respond(exampleConfig.details);
service.details(exampleConfig).then(function(details){ service.details(exampleConfig).then(function(details) {
expect(details).toEqual(exampleConfig.details); expect(details).toEqual(exampleConfig.details);
}); });
}); });
it('should GET the tree file from a dataset', function() { it('should GET the tree file from a dataset', function() {
httpBackend.whenGET(exampleConfig.tree).respond(exampleConfig.tree); httpBackend.whenGET(exampleConfig.tree).respond(exampleConfig.tree);
service.tree(exampleConfig).then(function(tree){ service.tree(exampleConfig).then(function(tree) {
expect(tree).toEqual(exampleConfig.tree); expect(tree).toEqual(exampleConfig.tree);
}); });
}); });
it('should GET the dstat file from a dataset', function() { it('should GET the dstat file from a dataset', function() {
httpBackend.whenGET(exampleConfig.dstat).respond(exampleConfig.dstat); httpBackend.whenGET(exampleConfig.dstat).respond(exampleConfig.dstat);
service.dstat(exampleConfig).then(function(dstat){ service.dstat(exampleConfig).then(function(dstat) {
expect(dstat).toEqual(exampleConfig.dstat); expect(dstat).toEqual(exampleConfig.dstat);
}); });
}); });