diff --git a/.eslintrc.json b/.eslintrc.json index 48cb1d9f..3fbbf51d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,7 +7,7 @@ "setFixtures": true // added globally by jasmine-jquery (bad) }, "rules": { - "indent": ["error", 4], + "indent": "off", "func-names": "off", "import/no-extraneous-dependencies": "off", "object-shorthand": "off", @@ -19,6 +19,21 @@ "one-var-declaration-per-line": "off", "import/no-amd": "off", "no-param-reassign": "off", - "new-cap": "off" + "new-cap": "off", + "comma-dangle": "off", + "object-curly-spacing": "off", + "space-before-function-paren": "off", + "prefer-template": "off", + "operator-linebreak": "off", + "no-multi-spaces": "off", + "prefer-spread": "off", + "prefer-rest-params": "off", + "no-else-return": "off", + "no-multiple-empty-lines": "off", + "prefer-destructuring": "off", + "no-buffer-constructor": "off", + "import/order": "off", + "import/extensions": "off", + "import/no-dynamic-require": "off" } } diff --git a/doc/static/js/ui-toolkit-doc-factory.js b/doc/static/js/ui-toolkit-doc-factory.js index 264bfb92..13f62177 100644 --- a/doc/static/js/ui-toolkit-doc-factory.js +++ b/doc/static/js/ui-toolkit-doc-factory.js @@ -1,12 +1,11 @@ -// eslint-disable-next-line import/no-dynamic-require require( [ 'jquery', 'edx-pattern-library/js/modernizr-custom', 'edx-pattern-library/js/afontgarde', - 'edx-pattern-library/js/edx-icons', + 'edx-pattern-library/js/edx-icons' ], - function () { + function() { 'use strict'; - }, + } ); diff --git a/gulp/config.js b/gulp/config.js index 6a89aa7f..47d8f941 100644 --- a/gulp/config.js +++ b/gulp/config.js @@ -6,46 +6,46 @@ module.exports = { previewTargetDir: './_preview_site', testing: { sources: [ - './src/js/utils/spec-helpers/*.js', + './src/js/utils/spec-helpers/*.js' ], output: './doc/_testing', - viewClass: 'testing', + viewClass: 'testing' }, utilities: { sources: [ - './src/js/utils/*.js', + './src/js/utils/*.js' ], output: './doc/_utilities', - viewClass: 'utility', + viewClass: 'utility' }, views: { sources: [ - './src/js/!(utils)/*.js', + './src/js/!(utils)/*.js' ], output: './doc/_views', - viewClass: 'view', + viewClass: 'view' }, browserSync: { server: { - baseDir: './_site', + baseDir: './_site' }, ui: { port: 5000, weinre: { - port: 5002, - }, - }, + port: 5002 + } + } }, templates: [ './doc/*.md', './doc/_data/**/*', - './doc/_layouts/**/*', + './doc/_layouts/**/*' ], static: [ - './doc/static/**/*', + './doc/static/**/*' ], gitHubPages: { - files: './_site/**/*', - }, - }, + files: './_site/**/*' + } + } }; diff --git a/gulp/tasks/clean.js b/gulp/tasks/clean.js index ce656aa1..c8b25aff 100644 --- a/gulp/tasks/clean.js +++ b/gulp/tasks/clean.js @@ -1,10 +1,10 @@ 'use strict'; var gulp = require('gulp'), - del = require('del'), - config = require('../config'); + config = require('../config'), + del = require('del'); -gulp.task('clean', function () { +gulp.task('clean', function() { return del([ // Remove the Jekyll site config.documentation.targetDir, @@ -15,7 +15,7 @@ gulp.task('clean', function () { // Remove the JSDoc generated markdown config.documentation.testing.output, config.documentation.utilities.output, - config.documentation.views.output, + config.documentation.views.output ]); }); diff --git a/gulp/tasks/coverage.js b/gulp/tasks/coverage.js index 4ef7ef00..b18a4265 100644 --- a/gulp/tasks/coverage.js +++ b/gulp/tasks/coverage.js @@ -3,7 +3,7 @@ var gulp = require('gulp'), coveralls = require('gulp-coveralls'); -gulp.task('coverage', function () { +gulp.task('coverage', function() { return gulp.src('coverage/**/lcov.info') .pipe(coveralls()); }); diff --git a/gulp/tasks/default.js b/gulp/tasks/default.js index f46522de..56cbb3a0 100644 --- a/gulp/tasks/default.js +++ b/gulp/tasks/default.js @@ -8,5 +8,5 @@ var gulp = require('gulp'), exports.default = gulp.series( lint.lint, test.test, - doc.docBuild, + doc.docBuild ); diff --git a/gulp/tasks/doc.js b/gulp/tasks/doc.js index 4848e658..ab07eb60 100644 --- a/gulp/tasks/doc.js +++ b/gulp/tasks/doc.js @@ -12,55 +12,55 @@ var gulp = require('gulp'), childProcess = require('child_process'), browserSync = require('browser-sync'), runSequence = require('gulp4-run-sequence'), + config = require('../config').documentation, + generateDoc = require('../utils/generate-doc'), rename = require('gulp-rename'), webpack = require('webpack'), webpackStream = require('webpack-stream'), ghPages = require('gulp-gh-pages'), - config = require('../config').documentation, - generateDoc = require('../utils/generate-doc'), - webpackConfig = require('../../webpack.config.js'), // eslint-disable-line import/extensions + webpackConfig = require('../../webpack.config.js'), clean = require('./clean'), renameAsMarkdown, generateDocFor; -renameAsMarkdown = function (path) { +renameAsMarkdown = function(path) { var renamedPath = path; renamedPath.extname = '.md'; return renamedPath; }; -generateDocFor = function (options) { +generateDocFor = function(options) { var i, sources, sourceLength = options.sources.length; for (i = 0; i < sourceLength; i += 1) { sources = options.sources[i]; - console.log(`Generating documentation for ${sources}`); - gulp.src(sources, { buffer: false }) + console.log('Generating documentation for ' + sources); + gulp.src(sources, {buffer: false}) .pipe(generateDoc(options.viewClass)) .pipe(rename(renameAsMarkdown)) .pipe(gulp.dest(options.output)); } }; -gulp.task('doc', function (callback) { +gulp.task('doc', function(callback) { runSequence( 'doc-build', 'doc-serve', - callback, + callback ); }); -gulp.task('doc-build', function (callback) { +gulp.task('doc-build', function(callback) { runSequence( ['doc-testing', 'doc-utils', 'doc-views'], 'copy-pattern-library', 'webpack', 'jekyll-build', - callback, + callback ); }); -gulp.task('doc-serve', function (callback) { +gulp.task('doc-serve', function(callback) { // Run browserSync to serve the doc site browserSync(config.browserSync); @@ -77,53 +77,53 @@ gulp.task('doc-serve', function (callback) { callback(); }); -gulp.task('doc-testing', function (callback) { +gulp.task('doc-testing', function(callback) { generateDocFor(config.testing); callback(); }); -gulp.task('doc-utils', function (callback) { +gulp.task('doc-utils', function(callback) { generateDocFor(config.utilities); callback(); }); -gulp.task('doc-views', function (callback) { +gulp.task('doc-views', function(callback) { generateDocFor(config.views); callback(); }); -gulp.task('copy-pattern-library', function (callback) { +gulp.task('copy-pattern-library', function(callback) { gulp.src(['./node_modules/edx-pattern-library/pattern-library/**/*']) .pipe(gulp.dest('doc/public/edx-pattern-library')); callback(); }); -gulp.task('webpack', function () { - return gulp.src('.', { allowEmpty: true }) +gulp.task('webpack', function() { + return gulp.src('.', {allowEmpty: true}) .pipe(webpackStream(webpackConfig, webpack)) .pipe(gulp.dest(webpackConfig.output.path)) .pipe(browserSync.stream()); }); -gulp.task('webpack-rebuild', function (callback) { +gulp.task('webpack-rebuild', function(callback) { runSequence( 'webpack', 'jekyll-rebuild', - callback, + callback ); }); -gulp.task('jekyll-build', function (callback) { +gulp.task('jekyll-build', function(callback) { childProcess.execSync('jekyll build'); callback(); }); -gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function (callback) { +gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function(callback) { browserSync.reload(); callback(); })); -gulp.task('doc-publish', gulp.series(clean.clean, 'doc-build', function () { +gulp.task('doc-publish', gulp.series(clean.clean, 'doc-build', function() { return gulp.src(config.gitHubPages.files) .pipe(ghPages()); })); @@ -132,5 +132,5 @@ exports.docBuild = gulp.series( gulp.parallel('doc-testing', 'doc-utils', 'doc-views'), 'copy-pattern-library', 'webpack', - 'jekyll-build', + 'jekyll-build' ); diff --git a/gulp/tasks/preview.js b/gulp/tasks/preview.js index 0a79aae3..4c0f52df 100644 --- a/gulp/tasks/preview.js +++ b/gulp/tasks/preview.js @@ -20,11 +20,11 @@ var gulp = require('gulp'), webpackStream = require('webpack-stream'), gitUtils = require('../utils/git-utils'), config = require('../config').documentation, - webpackConfig = require('../../webpack.config.js'), // eslint-disable-line import/extensions + webpackConfig = require('../../webpack.config.js'), previewConfigFile = '_tmp_preview_config.yml', previewDomain = process.env.S3_PREVIEW_DOMAIN; -gulp.task('preview', function (callback) { +gulp.task('preview', function(callback) { runSequence( 'clean', 'doc-build', @@ -32,62 +32,62 @@ gulp.task('preview', function (callback) { 'preview-webpack', 'upload-preview', 'show-preview', - callback, + callback ); }); -gulp.task('jekyll-build-preview', function () { +gulp.task('jekyll-build-preview', function() { var branch = gitUtils.currentBranch(), - previewBaseUrl = `/${branch}/`; + previewBaseUrl = '/' + branch + '/'; // Create a temporary Jekyll configuration file which specifies the base URL for the preview site childProcess.execSync( - `echo 'baseurl: ${previewBaseUrl}' > ${previewConfigFile}`, + 'echo \'baseurl: ' + previewBaseUrl + '\' > ' + previewConfigFile ); // Generate the preview version of the site - console.log(`Generating preview for branch ${branch}`); + console.log('Generating preview for branch ' + branch); childProcess.execSync( - `jekyll build --config _config.yml,${previewConfigFile} --destination ${config.previewTargetDir}`, + 'jekyll build --config _config.yml,' + previewConfigFile + ' --destination ' + config.previewTargetDir ); // Remove the configuration file since it is no longer needed - childProcess.execSync(`rm ${previewConfigFile}`); + childProcess.execSync('rm ' + previewConfigFile); }); -gulp.task('preview-webpack', function () { - var outputPath = `${config.previewTargetDir}/public/`, +gulp.task('preview-webpack', function() { + var outputPath = config.previewTargetDir + '/public/', branch = gitUtils.currentBranch(); - process.env.SITE_ROOT = `/${branch}/`; + process.env.SITE_ROOT = '/' + branch + '/'; return gulp.src('') .pipe(webpackStream(webpackConfig, webpack)) .pipe(gulp.dest(outputPath)); }); -gulp.task('upload-preview', function () { +gulp.task('upload-preview', function() { var branch = gitUtils.currentBranch(); if (previewDomain) { childProcess.execSync( - `aws s3 sync ${config.previewTargetDir} s3://${previewDomain}/${branch}`, + 'aws s3 sync ' + config.previewTargetDir + ' s3://' + previewDomain + '/' + branch ); - console.log(`Preview site ready at http://${previewDomain}/${branch}`); + console.log('Preview site ready at http://' + previewDomain + '/' + branch); } else { console.log( - 'No preview domain specified. Please export environment variable S3_PREVIEW_DOMAIN and try again.', + 'No preview domain specified. Please export environment variable S3_PREVIEW_DOMAIN and try again.' ); } }); -gulp.task('remove-preview', function () { +gulp.task('remove-preview', function() { var branch = gitUtils.currentBranch(); childProcess.execSync( - `aws s3 rm --recursive s3://${previewDomain}/${branch}`, + 'aws s3 rm --recursive s3://' + previewDomain + '/' + branch ); - console.log(`Removed preview for branch ${branch}`); + console.log('Removed preview for branch ' + branch); }); -gulp.task('show-preview', function () { +gulp.task('show-preview', function() { var branch = gitUtils.currentBranch(); childProcess.execSync( - `open http://${previewDomain}/${branch}`, + 'open http://' + previewDomain + '/' + branch ); }); diff --git a/gulp/tasks/test-debug.js b/gulp/tasks/test-debug.js index 00339d06..a892094f 100644 --- a/gulp/tasks/test-debug.js +++ b/gulp/tasks/test-debug.js @@ -5,8 +5,8 @@ var gulp = require('gulp'), path = require('path'), configFile = 'test/karma.debug.conf.js'; -gulp.task('test-debug', function (callback) { +gulp.task('test-debug', function(callback) { new karma.Server({ - configFile: path.resolve(configFile), + configFile: path.resolve(configFile) }, callback).start(); }); diff --git a/gulp/tasks/test.js b/gulp/tasks/test.js index 906f3ac9..77f1573d 100644 --- a/gulp/tasks/test.js +++ b/gulp/tasks/test.js @@ -5,14 +5,15 @@ var gulp = require('gulp'), path = require('path'), configFile; -gulp.task('test', function (callback) { + +gulp.task('test', function(callback) { if (process.argv.indexOf('--ci') !== -1) { configFile = 'test/karma.ci.conf.js'; } else { configFile = 'test/karma.conf.js'; } new karma.Server({ - configFile: path.resolve(configFile), + configFile: path.resolve(configFile) }, callback).start(); }); diff --git a/gulp/utils/generate-doc.js b/gulp/utils/generate-doc.js index 26c80e6c..c680e6b8 100644 --- a/gulp/utils/generate-doc.js +++ b/gulp/utils/generate-doc.js @@ -6,15 +6,15 @@ var jsdox = require('jsdox'), GulpUtil = require('gulp-util'), jsdocParser = require('jsdoc3-parser'), PLUGIN_NAME = 'generate-doc', - { analyze } = jsdox, - { generateMD } = jsdox, + analyze = jsdox.analyze, + generateMD = jsdox.generateMD, jsdoxTemplatesDir = 'node_modules/jsdox/templates'; -module.exports = function (viewClass) { - return through.obj(function (file, enc, next) { +module.exports = function(viewClass) { + return through.obj(function(file, enc, next) { var self = this; if (file.isStream()) { - jsdocParser(file.history, function (err, result) { + jsdocParser(file.history, function(err, result) { var frontMatter, data, markdown, title, relativePath, requirePath, gitHubPath, fileToPush = file; if (err) { @@ -23,18 +23,22 @@ module.exports = function (viewClass) { } else { // Generate the front matter relativePath = path.relative(path.resolve('src'), file.path); - requirePath = `edx-ui-toolkit/${relativePath.slice(0, -3)}`; - gitHubPath = `blob/master/src/${relativePath}`; + requirePath = 'edx-ui-toolkit/' + relativePath.slice(0, -3); + gitHubPath = 'blob/master/src/' + relativePath; // title = path.relative(path.resolve('src/js'), file.path).slice(0, -3); title = path.basename(file.path, '.js'); - frontMatter = `---\ntitle: ${title}\nrequirePath: ${requirePath}\ngithubPath: ${gitHubPath}\nviewClass: ${viewClass}\n---\n\n`; + frontMatter = '---\n' + + 'title: ' + title + '\n' + + 'requirePath: ' + requirePath + '\n' + + 'githubPath: ' + gitHubPath + '\n' + + 'viewClass: ' + viewClass + '\n' + + '---\n\n'; // Generate the markdown data = analyze(result, {}); markdown = generateMD(data, jsdoxTemplatesDir); // set the result to the front matter followed by the markdown - // eslint-disable-next-line no-buffer-constructor fileToPush.contents = new Buffer(frontMatter + markdown); } self.push(fileToPush); diff --git a/gulp/utils/git-utils.js b/gulp/utils/git-utils.js index 9c0982aa..7d354293 100644 --- a/gulp/utils/git-utils.js +++ b/gulp/utils/git-utils.js @@ -7,8 +7,8 @@ module.exports = { /** * Returns the current Git branch for the current directory. */ - currentBranch: function () { + currentBranch: function() { var branch = childProcess.execSync(gitBranchCommand); return branch.toString().trim(); - }, + } }; diff --git a/src/js/breadcrumbs/breadcrumbs-model.js b/src/js/breadcrumbs/breadcrumbs-model.js index 96754e4c..963695e2 100644 --- a/src/js/breadcrumbs/breadcrumbs-model.js +++ b/src/js/breadcrumbs/breadcrumbs-model.js @@ -20,15 +20,15 @@ *~~~ * @module BreadcrumbsModel */ -(function (define) { +(function(define) { 'use strict'; - define(['backbone'], function (Backbone) { + define(['backbone'], function(Backbone) { var BreadcrumbsModel = Backbone.Model.extend({ defaults: { breadcrumbs: null, - label: '', - }, + label: '' + } }); return BreadcrumbsModel; @@ -36,5 +36,5 @@ }).call( this, // Use the default 'define' function if available, else use 'RequireJS.define' - typeof define === 'function' && define.amd ? define : RequireJS.define, + typeof define === 'function' && define.amd ? define : RequireJS.define ); diff --git a/src/js/breadcrumbs/breadcrumbs-view.js b/src/js/breadcrumbs/breadcrumbs-view.js index e2cfda0b..0c5e72ed 100644 --- a/src/js/breadcrumbs/breadcrumbs-view.js +++ b/src/js/breadcrumbs/breadcrumbs-view.js @@ -19,23 +19,23 @@ *~~~ * @module BreadcrumbsView */ -(function (define) { +(function(define) { 'use strict'; define(['backbone', 'edx-ui-toolkit/js/utils/html-utils', 'text!./breadcrumbs.underscore'], - function (Backbone, HtmlUtils, breadcrumbsTemplate) { + function(Backbone, HtmlUtils, breadcrumbsTemplate) { var BreadcrumbsView = Backbone.View.extend({ - initialize: function () { + initialize: function() { this.template = HtmlUtils.template(breadcrumbsTemplate); this.listenTo(this.model, 'change', this.render); this.render(); }, - render: function () { + render: function() { var json = this.model.attributes; HtmlUtils.setHtml(this.$el, this.template(json)); return this; - }, + } }); return BreadcrumbsView; @@ -43,5 +43,5 @@ }).call( this, // Use the default 'define' function if available, else use 'RequireJS.define' - typeof define === 'function' && define.amd ? define : RequireJS.define, + typeof define === 'function' && define.amd ? define : RequireJS.define ); diff --git a/src/js/breadcrumbs/specs/breadcrumbs-spec.js b/src/js/breadcrumbs/specs/breadcrumbs-spec.js index f80d9b45..4d107ee5 100644 --- a/src/js/breadcrumbs/specs/breadcrumbs-spec.js +++ b/src/js/breadcrumbs/specs/breadcrumbs-spec.js @@ -1,4 +1,4 @@ -(function (define) { +(function(define) { 'use strict'; define([ @@ -6,61 +6,61 @@ '../../utils/html-utils.js', '../../utils/spec-helpers/spec-helpers.js', '../breadcrumbs-view.js', - '../breadcrumbs-model.js', + '../breadcrumbs-model.js' ], - function ($, HtmlUtils, SpecHelpers, BreadcrumbsView, BreadcrumbsModel) { - describe('BreadcrumbsView', function () { - var model, view; + function($, HtmlUtils, SpecHelpers, BreadcrumbsView, BreadcrumbsModel) { + describe('BreadcrumbsView', function() { + var model, view; - beforeEach(function () { - model = new BreadcrumbsModel(); - view = new BreadcrumbsView({ - model: model, - }); - }); + beforeEach(function() { + model = new BreadcrumbsModel(); + view = new BreadcrumbsView({ + model: model + }); + }); - it('does not show breadcrumbs by default', function () { - expect(view.$el.html()).not.toContain('