From 7eab971d3f4c9cd2016ef397518f756995d961ba Mon Sep 17 00:00:00 2001 From: Tim Buckley Date: Wed, 18 Nov 2015 15:36:36 -0700 Subject: [PATCH] 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 --- .eslintignore | 8 ++++++ .eslintrc | 14 ++++++++++ .jshintrc | 20 -------------- app/.eslintrc | 7 +++++ app/js/controllers/_index.js | 2 +- app/js/directives/_index.js | 2 +- app/js/directives/timeline.js | 12 ++++----- app/js/main.js | 42 ++++++++++++------------------ app/js/on_run.js | 8 +++--- app/js/services/_index.js | 2 +- gulp/tasks/lint.js | 11 -------- gulp/tasks/watch.js | 1 - package.json | 9 +++---- test/e2e/example_spec.js | 2 +- test/e2e/routes_spec.js | 2 +- test/protractor.conf.js | 2 +- test/unit/controllers/test-home.js | 2 -- test/unit/services/test-dataset.js | 14 +++++----- 18 files changed, 73 insertions(+), 87 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc delete mode 100644 .jshintrc create mode 100644 app/.eslintrc delete mode 100644 gulp/tasks/lint.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..cdffdcf --- /dev/null +++ b/.eslintignore @@ -0,0 +1,8 @@ +cover +build +node_modules +coverage +doc +app/vendor-js +app/js/templates.js +gulp diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..0aec8de --- /dev/null +++ b/.eslintrc @@ -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 diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index b93054e..0000000 --- a/.jshintrc +++ /dev/null @@ -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 -} diff --git a/app/.eslintrc b/app/.eslintrc new file mode 100644 index 0000000..81006b0 --- /dev/null +++ b/app/.eslintrc @@ -0,0 +1,7 @@ +# Enable eslint-plugin-angular +plugins: + - angular + +rules: + angular/module-setter: 0 + angular/module-getter: 0 diff --git a/app/js/controllers/_index.js b/app/js/controllers/_index.js index 5dae729..bdd98a9 100644 --- a/app/js/controllers/_index.js +++ b/app/js/controllers/_index.js @@ -5,4 +5,4 @@ var bulk = require('bulk-require'); module.exports = angular.module('app.controllers', []); -bulk(__dirname, ['./**/!(*_index|*.spec).js']); \ No newline at end of file +bulk(__dirname, ['./**/!(*_index|*.spec).js']); diff --git a/app/js/directives/_index.js b/app/js/directives/_index.js index 689cbb9..55e142c 100644 --- a/app/js/directives/_index.js +++ b/app/js/directives/_index.js @@ -5,4 +5,4 @@ var bulk = require('bulk-require'); module.exports = angular.module('app.directives', []); -bulk(__dirname, ['./**/!(*_index|*.spec).js']); \ No newline at end of file +bulk(__dirname, ['./**/!(*_index|*.spec).js']); diff --git a/app/js/directives/timeline.js b/app/js/directives/timeline.js index dad8a59..a978a7e 100644 --- a/app/js/directives/timeline.js +++ b/app/js/directives/timeline.js @@ -52,10 +52,10 @@ var getDstatLanes = function(data, mins, maxes) { if ('memory_usage_used' in row) { lanes.push([{ - scale: d3.scale.linear().domain([0, maxes.memory_usage_used]), - value: function(d) { return d.memory_usage_used; }, - color: "rgba(102, 140, 178, 0.75)", - text: "Memory" + scale: d3.scale.linear().domain([0, maxes.memory_usage_used]), + value: function(d) { return d.memory_usage_used; }, + color: "rgba(102, 140, 178, 0.75)", + text: "Memory" }]); } @@ -96,7 +96,7 @@ var getDstatLanes = function(data, mins, maxes) { /** * @ngInject */ -function timeline(datasetService) { +function timeline($log, datasetService) { var link = function(scope, el, attrs) { var data = []; var dstat = {}; @@ -578,7 +578,7 @@ function timeline(datasetService) { // (dstat may not exist, but that's okay) initData(raw, dstat); }).catch(function(ex) { - console.error(ex); + $log.error(ex); }); }); }; diff --git a/app/js/main.js b/app/js/main.js index 16efaba..0b5e003 100644 --- a/app/js/main.js +++ b/app/js/main.js @@ -12,33 +12,25 @@ require('./services/_index'); require('./directives/_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 = [ - 'ui.router', - 'ui.bootstrap', - 'templates', - 'app.controllers', - 'app.services', - 'app.directives', - 'app.filters', - 'picardy.fontawesome' - ]; +angular.module('app', requires); - // mount on window for testing - window.app = angular.module('app', requires); +angular.module('app').constant('AppSettings', require('./constants')); - 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']); - - window.bootstrap = null; -}; - -// create and bootstrap application -angular.element(document).ready(bootstrap); -window.bootstrap = bootstrap; +angular.bootstrap(document, ['app']); diff --git a/app/js/on_run.js b/app/js/on_run.js index e9c0122..44aae2c 100644 --- a/app/js/on_run.js +++ b/app/js/on_run.js @@ -6,10 +6,10 @@ 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,8 @@ function OnRun($rootScope, AppSettings) { $rootScope.pageTitle += AppSettings.appTitle; }); + $rootScope.$on('$destroy', disable); + } -module.exports = OnRun; \ No newline at end of file +module.exports = OnRun; diff --git a/app/js/services/_index.js b/app/js/services/_index.js index c72fc15..a69ce26 100644 --- a/app/js/services/_index.js +++ b/app/js/services/_index.js @@ -5,4 +5,4 @@ var bulk = require('bulk-require'); module.exports = angular.module('app.services', []); -bulk(__dirname, ['./**/!(*_index|*.spec).js']); \ No newline at end of file +bulk(__dirname, ['./**/!(*_index|*.spec).js']); diff --git a/gulp/tasks/lint.js b/gulp/tasks/lint.js deleted file mode 100644 index 730595b..0000000 --- a/gulp/tasks/lint.js +++ /dev/null @@ -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')); -}); \ No newline at end of file diff --git a/gulp/tasks/watch.js b/gulp/tasks/watch.js index e144a50..ca53817 100644 --- a/gulp/tasks/watch.js +++ b/gulp/tasks/watch.js @@ -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.images.src, ['images']); gulp.watch(config.fonts.src, ['fonts']); diff --git a/package.json b/package.json index 8d54dce..8741ead 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,9 @@ "d3": "^3.5.6", "debowerify": "^1.2.0", "del": "^0.1.3", - "eslint": "^0.23.0", - "eslint-config-openstack": "1.2.0", + "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", @@ -34,7 +35,6 @@ "gulp-gzip": "^0.0.8", "gulp-if": "^1.2.5", "gulp-imagemin": "^1.1.0", - "gulp-jshint": "^1.8.3", "gulp-karma": "0.0.4", "gulp-notify": "^2.0.0", "gulp-protractor": "0.0.11", @@ -49,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", @@ -71,7 +70,7 @@ "scripts": { "postinstall": "if [ ! -d .venv ]; then tox -epy27 --notest; fi", "test": "gulp unit", - "lint": "eslint --no-color stackviz/static" + "lint": "eslint ./" }, "dependencies": {} } diff --git a/test/e2e/example_spec.js b/test/e2e/example_spec.js index d68cb4a..09fec70 100644 --- a/test/e2e/example_spec.js +++ b/test/e2e/example_spec.js @@ -18,4 +18,4 @@ describe('E2E: Example', function() { expect(element.getText()).toEqual('1234'); }); -}); \ No newline at end of file +}); diff --git a/test/e2e/routes_spec.js b/test/e2e/routes_spec.js index 3cedaca..f2a73df 100644 --- a/test/e2e/routes_spec.js +++ b/test/e2e/routes_spec.js @@ -9,4 +9,4 @@ describe('E2E: Routes', function() { expect(browser.getLocationAbsUrl()).toMatch('/'); }); -}); \ No newline at end of file +}); diff --git a/test/protractor.conf.js b/test/protractor.conf.js index 406cfba..abda3b4 100644 --- a/test/protractor.conf.js +++ b/test/protractor.conf.js @@ -29,4 +29,4 @@ exports.config = { 'e2e/**/*.js' ] -}; \ No newline at end of file +}; diff --git a/test/unit/controllers/test-home.js b/test/unit/controllers/test-home.js index 9dd2e9e..3d013e4 100644 --- a/test/unit/controllers/test-home.js +++ b/test/unit/controllers/test-home.js @@ -2,8 +2,6 @@ 'use strict'; -window.bootstrap && window.bootstrap(); - describe('Unit: HomeCtrl', function() { var ctrl; diff --git a/test/unit/services/test-dataset.js b/test/unit/services/test-dataset.js index 52154c7..1b6d5a5 100644 --- a/test/unit/services/test-dataset.js +++ b/test/unit/services/test-dataset.js @@ -2,8 +2,6 @@ 'use strict'; -window.bootstrap && window.bootstrap(); - describe('Unit: DatasetService', function() { var service, httpBackend; @@ -13,7 +11,7 @@ describe('Unit: DatasetService', function() { "tree": "tempest_file_freshlog_0_tree.json", "id": 0, "name": "Subunit File: freshlog"} - ]}; + ]}; beforeEach(function() { // instantiate the app module @@ -32,7 +30,7 @@ describe('Unit: DatasetService', function() { it('should return config.json', function() { httpBackend.whenGET("data/config.json").respond(exampleConfig); - service.list().then(function(config){ + service.list().then(function(config) { expect(config.data).toEqual(exampleConfig); }); httpBackend.flush(); @@ -40,28 +38,28 @@ describe('Unit: DatasetService', function() { it('should GET the raw file from a dataset', function() { httpBackend.whenGET(exampleConfig.raw).respond(exampleConfig.raw); - service.raw(exampleConfig).then(function(raw){ + service.raw(exampleConfig).then(function(raw) { expect(raw).toEqual(exampleConfig.raw); }); }); it('should GET the details file from a dataset', function() { httpBackend.whenGET(exampleConfig.details).respond(exampleConfig.details); - service.details(exampleConfig).then(function(details){ + service.details(exampleConfig).then(function(details) { expect(details).toEqual(exampleConfig.details); }); }); it('should GET the tree file from a dataset', function() { httpBackend.whenGET(exampleConfig.tree).respond(exampleConfig.tree); - service.tree(exampleConfig).then(function(tree){ + service.tree(exampleConfig).then(function(tree) { expect(tree).toEqual(exampleConfig.tree); }); }); it('should GET the dstat file from a dataset', function() { httpBackend.whenGET(exampleConfig.dstat).respond(exampleConfig.dstat); - service.dstat(exampleConfig).then(function(dstat){ + service.dstat(exampleConfig).then(function(dstat) { expect(dstat).toEqual(exampleConfig.dstat); }); });