Clean up eslint failures

This commit is contained in:
Calen Pennington
2018-04-27 12:20:18 -04:00
parent 61855b2b30
commit 667dbf1687
19 changed files with 621 additions and 217 deletions

View File

@@ -29,11 +29,9 @@
*/
toggleExpandCollapse = function(target, collapsedClass) {
// Support the old 'collapsed' option until fully switched over to is-collapsed
if (!collapsedClass) {
collapsedClass = 'collapsed';
}
var collapsed = collapsedClass || 'collapsed';
target.closest('.expand-collapse').toggleClass('expand collapse');
target.closest('.is-collapsible, .window').toggleClass(collapsedClass);
target.closest('.is-collapsible, .window').toggleClass(collapsed);
target.closest('.is-collapsible').children('article').slideToggle();
};
@@ -239,20 +237,20 @@
};
// Ensure that sum length of key field values <= ${MAX_SUM_KEY_LENGTH} chars.
validateTotalKeyLength = function(key_field_selectors) {
validateTotalKeyLength = function(keyFieldSelectors) {
var totalLength = _.reduce(
key_field_selectors,
keyFieldSelectors,
function(sum, ele) { return sum + $(ele).val().length; },
0
);
return totalLength <= MAX_SUM_KEY_LENGTH;
};
checkTotalKeyLengthViolations = function(selectors, classes, key_field_selectors, message_tpl) {
if (!validateTotalKeyLength(key_field_selectors)) {
checkTotalKeyLengthViolations = function(selectors, classes, keyFieldSelectors, messageTpl) {
if (!validateTotalKeyLength(keyFieldSelectors)) {
$(selectors.errorWrapper).addClass(classes.shown).removeClass(classes.hiding);
$(selectors.errorMessage).html(
'<p>' + _.template(message_tpl)({limit: MAX_SUM_KEY_LENGTH}) + '</p>'
'<p>' + _.template(messageTpl)({limit: MAX_SUM_KEY_LENGTH}) + '</p>'
);
$(selectors.save).addClass(classes.disabled);
} else {

View File

@@ -45,8 +45,6 @@ var webdriver = require('selenium-webdriver');
var firefox = require('selenium-webdriver/firefox');
var webpackConfig = require(path.join(appRoot, 'webpack.dev.config.js'));
delete webpackConfig.entry;
// The following crazy bit is to work around the webpack.optimize.CommonsChunkPlugin
// plugin. The problem is that it it factors out the code that defines webpackJsonp
// and puts in in the commons JS, which Karma doesn't know to load first. This is a
@@ -56,33 +54,36 @@ delete webpackConfig.entry;
// https://github.com/webpack-contrib/karma-webpack/issues/24#issuecomment-257613167
//
// This should be fixed in v3 of karma-webpack
const commonsChunkPluginIndex = webpackConfig.plugins.findIndex(plugin => plugin.chunkNames);
webpackConfig.plugins.splice(commonsChunkPluginIndex, 1);
var commonsChunkPluginIndex = webpackConfig.plugins.findIndex(function(plugin) { return plugin.chunkNames; });
// Files which are needed by all lms/cms suites.
var commonFiles = {
libraryFiles: [
{ pattern: 'common/js/vendor/**/*.js' },
{ pattern: 'edx-pattern-library/js/**/*.js' },
{ pattern: 'edx-ui-toolkit/js/**/*.js' },
{ pattern: 'xmodule_js/common_static/common/js/**/!(*spec).js' },
{ pattern: 'xmodule_js/common_static/js/**/!(*spec).js' },
{ pattern: 'xmodule_js/src/**/*.js' }
{pattern: 'common/js/vendor/**/*.js'},
{pattern: 'edx-pattern-library/js/**/*.js'},
{pattern: 'edx-ui-toolkit/js/**/*.js'},
{pattern: 'xmodule_js/common_static/common/js/**/!(*spec).js'},
{pattern: 'xmodule_js/common_static/js/**/!(*spec).js'},
{pattern: 'xmodule_js/src/**/*.js'}
],
sourceFiles: [
{ pattern: 'common/js/!(spec_helpers)/**/!(*spec).js' }
{pattern: 'common/js/!(spec_helpers)/**/!(*spec).js'}
],
specFiles: [
{ pattern: 'common/js/spec_helpers/**/*.js' }
{pattern: 'common/js/spec_helpers/**/*.js'}
],
fixtureFiles: [
{ pattern: 'common/templates/**/*.underscore' }
{pattern: 'common/templates/**/*.underscore'}
]
};
webpackConfig.plugins.splice(commonsChunkPluginIndex, 1);
delete webpackConfig.entry;
/**
* Customize the name attribute in xml testcase element
* @param {Object} browser
@@ -124,6 +125,8 @@ function reporters(config) {
* @return {Object}
*/
function getBasepathAndFilename(filepath) {
var file, dir;
if (!filepath) {
// these will configure the reporters to create report files relative to this karma config file
return {
@@ -131,9 +134,8 @@ function getBasepathAndFilename(filepath) {
file: undefined
};
}
var file = filepath.replace(/^.*[\\\/]/, ''),
dir = filepath.replace(file, '');
file = filepath.replace(/^.*[\\/]/, '');
dir = filepath.replace(file, '');
return {
dir: dir,
@@ -148,14 +150,14 @@ function getBasepathAndFilename(filepath) {
* @return {Object}
*/
function coverageSettings(config) {
var path = getBasepathAndFilename(config.coveragereportpath);
var pth = getBasepathAndFilename(config.coveragereportpath);
return {
dir: path.dir,
dir: pth.dir,
subdir: '.',
includeAllSources: true,
reporters: [
{ type: 'cobertura', file: path.file },
{ type: 'text-summary' }
{type: 'cobertura', file: pth.file},
{type: 'text-summary'}
]
};
}
@@ -167,10 +169,10 @@ function coverageSettings(config) {
* @return {Object}
*/
function junitSettings(config) {
var path = getBasepathAndFilename(config.junitreportpath);
var pth = getBasepathAndFilename(config.junitreportpath);
return {
outputDir: path.dir,
outputFile: path.file,
outputDir: pth.dir,
outputFile: pth.file,
suite: 'javascript',
useBrowserName: false,
nameFormatter: junitNameFormatter,
@@ -185,14 +187,15 @@ function junitSettings(config) {
* @return {String}
*/
// I'd like to fix the no-shadow violation on the next line, but it would break this shared conf's API.
function defaultNormalizeFunc(appRoot, pattern) { // eslint-disable-line no-shadow
if (pattern.match(/^common\/js/)) {
pattern = path.join(appRoot, '/common/static/' + pattern);
} else if (pattern.match(/^xmodule_js\/common_static/)) {
pattern = path.join(appRoot, '/common/static/' +
pattern.replace(/^xmodule_js\/common_static\//, ''));
function defaultNormalizeFunc(appRoot, pattern) { // eslint-disable-line no-shadow
var pat = pattern;
if (pat.match(/^common\/js/)) {
pat = path.join(appRoot, '/common/static/' + pat);
} else if (pat.match(/^xmodule_js\/common_static/)) {
pat = path.join(appRoot, '/common/static/' +
pat.replace(/^xmodule_js\/common_static\//, ''));
}
return pattern;
return pat;
}
function normalizePathsForCoverage(files, normalizeFunc, preprocessors) {
@@ -200,7 +203,7 @@ function normalizePathsForCoverage(files, normalizeFunc, preprocessors) {
normalizedFile,
filesForCoverage = {};
files.forEach(function (file) {
files.forEach(function(file) {
if (!file.ignoreCoverage) {
normalizedFile = normalizeFn(appRoot, file.pattern);
if (preprocessors && preprocessors.hasOwnProperty(normalizedFile)) {
@@ -222,17 +225,17 @@ function normalizePathsForCoverage(files, normalizeFunc, preprocessors) {
* @return {Object}
*/
function setDefaults(files) {
return files.map(function (f) {
var file = _.isObject(f) ? f : { pattern: f };
return files.map(function(f) {
var file = _.isObject(f) ? f : {pattern: f};
if (!file.included && !file.webpack) {
f.included = false;
file.included = false;
}
return file;
});
}
function getBaseConfig(config, useRequireJs) {
var getFrameworkFiles = function () {
var getFrameworkFiles = function() {
var files = [
'common/static/common/js/vendor/jquery.js',
'node_modules/jasmine-core/lib/jasmine-core/jasmine.js',
@@ -244,7 +247,7 @@ function getBaseConfig(config, useRequireJs) {
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/underscore/underscore.js',
'node_modules/backbone/backbone.js',
'common/static/js/test/i18n.js',
'common/static/js/test/i18n.js'
];
if (useRequireJs) {
@@ -263,8 +266,8 @@ function getBaseConfig(config, useRequireJs) {
// which isn't a karma plugin. Though a karma framework for jasmine-jquery is available
// but it's not actively maintained. In future we also wanna add jQuery at the top when
// we upgrade to jQuery 2
var initFrameworks = function (files) {
getFrameworkFiles().reverse().forEach(function (f) {
var initFrameworks = function(files) {
getFrameworkFiles().reverse().forEach(function(f) {
files.unshift({
pattern: path.join(appRoot, f),
included: true,
@@ -276,22 +279,21 @@ function getBaseConfig(config, useRequireJs) {
var hostname = 'localhost';
var port = 9876;
var customPlugin = {
'framework:custom': ['factory', initFrameworks]
};
if (process.env.hasOwnProperty('BOK_CHOY_HOSTNAME')) {
hostname = process.env.BOK_CHOY_HOSTNAME;
if (hostname === 'edx.devstack.lms') {
port = 19876;
}
else {
} else {
port = 19877;
}
}
initFrameworks.$inject = ['config.files'];
var customPlugin = {
'framework:custom': ['factory', initFrameworks]
};
return {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
@@ -370,7 +372,7 @@ function getBaseConfig(config, useRequireJs) {
ChromeDocker: {
base: 'SeleniumWebdriver',
browserName: 'chrome',
getDriver: function () {
getDriver: function() {
return new webdriver.Builder()
.forBrowser('chrome')
.usingServer('http://edx.devstack.chrome:4444/wd/hub')
@@ -380,7 +382,7 @@ function getBaseConfig(config, useRequireJs) {
FirefoxDocker: {
base: 'SeleniumWebdriver',
browserName: 'firefox',
getDriver: function () {
getDriver: function() {
var options = new firefox.Options(),
profile = new firefox.Profile();
profile.setPreference('focusmanager.testmode', true);
@@ -419,44 +421,45 @@ function getBaseConfig(config, useRequireJs) {
}
function configure(config, options) {
var useRequireJs = options.useRequireJs === undefined ? true : useRequireJs,
baseConfig = getBaseConfig(config, useRequireJs);
var useRequireJs = options.useRequireJs === undefined ? true : options.useRequireJs,
baseConfig = getBaseConfig(config, useRequireJs),
files, filesForCoverage, preprocessors;
if (options.includeCommonFiles) {
_.forEach(['libraryFiles', 'sourceFiles', 'specFiles', 'fixtureFiles'], function (collectionName) {
_.forEach(['libraryFiles', 'sourceFiles', 'specFiles', 'fixtureFiles'], function(collectionName) {
options[collectionName] = _.flatten([commonFiles[collectionName], options[collectionName]]);
});
}
var files = _.flatten(
files = _.flatten(
_.map(
['libraryFilesToInclude', 'libraryFiles', 'sourceFiles', 'specFiles', 'fixtureFiles', 'runFiles'],
function (collectionName) { return options[collectionName] || []; }
function(collectionName) { return options[collectionName] || []; }
)
);
files.unshift(
{ pattern: path.join(appRoot, 'common/static/common/js/jasmine.common.conf.js'), included: true }
{pattern: path.join(appRoot, 'common/static/common/js/jasmine.common.conf.js'), included: true}
);
if (useRequireJs) {
files.unshift({ pattern: 'common/js/utils/require-serial.js', included: true });
files.unshift({pattern: 'common/js/utils/require-serial.js', included: true});
}
// Karma sets included=true by default.
// We set it to false by default because RequireJS should be used instead.
files = setDefaults(files);
var filesForCoverage = _.flatten(
filesForCoverage = _.flatten(
_.map(
['sourceFiles', 'specFiles'],
function (collectionName) { return options[collectionName]; }
function(collectionName) { return options[collectionName]; }
)
);
// If we give symlink paths to Istanbul, coverage for each path gets tracked
// separately. So we pass absolute paths to the karma-coverage preprocessor.
var preprocessors = _.extend(
preprocessors = _.extend(
{},
options.preprocessors,
normalizePathsForCoverage(filesForCoverage, options.normalizePathsForCoverageFunc, options.preprocessors)

View File

@@ -1,9 +1,9 @@
/**
* Provides helper methods for invoking Studio modal windows in Jasmine tests.
*/
define(['jquery', 'common/js/components/views/feedback_notification', 'common/js/components/views/feedback_prompt',
define(['underscore', 'jquery', 'common/js/components/views/feedback_notification', 'common/js/components/views/feedback_prompt',
'edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers'],
function($, NotificationView, Prompt, AjaxHelpers) {
function(_, $, NotificationView, Prompt, AjaxHelpers) {
'use strict';
var installViewTemplates, createFeedbackSpy, verifyFeedbackShowing,
verifyFeedbackHidden, createNotificationSpy, verifyNotificationShowing,
@@ -41,11 +41,11 @@ define(['jquery', 'common/js/components/views/feedback_notification', 'common/js
return createFeedbackSpy(NotificationView, type || 'Mini');
};
verifyNotificationShowing = function(notificationSpy, text) {
verifyNotificationShowing = function() {
verifyFeedbackShowing.apply(this, arguments);
};
verifyNotificationHidden = function(notificationSpy) {
verifyNotificationHidden = function() {
verifyFeedbackHidden.apply(this, arguments);
};
@@ -62,11 +62,11 @@ define(['jquery', 'common/js/components/views/feedback_notification', 'common/js
}
};
verifyPromptShowing = function(promptSpy, text) {
verifyPromptShowing = function() {
verifyFeedbackShowing.apply(this, arguments);
};
verifyPromptHidden = function(promptSpy) {
verifyPromptHidden = function() {
verifyFeedbackHidden.apply(this, arguments);
};

View File

@@ -3,12 +3,12 @@
this.XBlock.Runtime.v1 = (function() {
function v1() {
var _this = this;
var block = this;
this.childMap = function() {
return v1.prototype.childMap.apply(_this, arguments);
return v1.prototype.childMap.apply(block, arguments);
};
this.children = function() {
return v1.prototype.children.apply(_this, arguments);
return v1.prototype.children.apply(block, arguments);
};
}
@@ -17,14 +17,15 @@
};
v1.prototype.childMap = function(block, childName) {
var child, _i, _len, _ref;
_ref = this.children(block);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
var child, idx, len, ref;
ref = this.children(block);
for (idx = 0, len = ref.length; idx < len; idx++) {
child = ref[idx];
if (child.name === childName) {
return child;
}
}
return null;
};
/**