GUI: Added ESLint to gulp tasks
GUI: Linted files
Fixed an error in the build script
JIRA-TASKS: ONOS-6522, ONOS-6521
Change-Id: Ie72abfe6cbe21c8946f219be6193344b67ec6dd1
diff --git a/tools/gui/gulp-tasks/lint/esconfig.json b/tools/gui/gulp-tasks/lint/esconfig.json
new file mode 100644
index 0000000..7ce1a78
--- /dev/null
+++ b/tools/gui/gulp-tasks/lint/esconfig.json
@@ -0,0 +1,27 @@
+{
+ "extends": "google",
+ "globals": {
+ "angular": true,
+ "d3": true,
+ "_": true
+ },
+ "rules": {
+ "prefer-spread": 0,
+ "prefer-rest-params": 0,
+ "no-var": 0,
+ "comma-dangle": 1,
+ "brace-style": 0,
+ "no-void": 0,
+ "require-jsdoc": 0,
+ "padded-blocks": 0,
+ "quote-props": 0,
+ "no-warning-comments": 0,
+ "object-curly-spacing": ["error", "always"],
+ "indent": 0,
+ "one-var": 0,
+ "block-spacing": ["error", "always"],
+ "space-before-function-paren": ["error", { "anonymous": "always", "named": "never" }],
+ "max-len": ["error", 120],
+ "no-invalid-this": 0
+ }
+}
diff --git a/tools/gui/gulp-tasks/lint/index.js b/tools/gui/gulp-tasks/lint/index.js
new file mode 100644
index 0000000..8dabc49
--- /dev/null
+++ b/tools/gui/gulp-tasks/lint/index.js
@@ -0,0 +1,33 @@
+import gulp from 'gulp';
+import eslint from 'gulp-eslint';
+import gulpIf from 'gulp-if';
+import path from 'path';
+
+const files = [
+ '../../web/gui/src/main/webapp/app/**/*.js'
+];
+
+function isFixed(file) {
+ // Has ESLint fixed the file contents?
+ return file.eslint != null && file.eslint.fixed;
+}
+
+const lint = () => {
+ return gulp.src(files)
+ .pipe(eslint({
+ configFile: path.join(__dirname, 'esconfig.json'),
+ useEslintrc: false,
+ // Automatically fix trivial issues
+ fix: true,
+ }))
+ .pipe(eslint.format())
+ .pipe(gulpIf(isFixed,
+ gulp.dest('../../web/gui/src/main/webapp/app')
+ ));
+};
+
+const tasks = () => {
+ gulp.task('lint', () => lint());
+};
+
+export default tasks();
\ No newline at end of file