Skip to content
Snippets Groups Projects
Commit d4f66eb3 authored by Paal Joergensen's avatar Paal Joergensen
Browse files

Add eslint config, and fix problems reported

parent ac56ab3f
No related branches found
No related tags found
No related merge requests found
.eslintrc 0 → 100644
{
"env": {
"browser": true,
"amd": true
},
"globals": {
"M": true,
"Y": true,
"H5PIntegration": true,
"H5PEditor": true,
"H5P": true
},
"rules": {
"comma-dangle": "off",
"no-compare-neg-zero": "error",
"no-cond-assign": "error",
"no-console": ["error", {"allow": ["warn", "error"]}],
"no-constant-condition": "error",
"no-control-regex": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "warn",
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-parens": "off",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": "error",
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-prototype-builtins": "off",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "warn",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"use-isnan": "error",
"valid-jsdoc": ["warn", { "requireReturn": false, "requireParamDescription": false, "requireReturnDescription": false }],
"valid-typeof": "error",
"array-callback-return": "warn",
"block-scoped-var": "warn",
"complexity": "warn",
"consistent-return": "warn",
"curly": "error",
"dot-notation": "warn",
"no-alert": "warn",
"no-caller": "error",
"no-case-declarations": "error",
"no-div-regex": "error",
"no-empty-pattern": "error",
"no-empty-function": "warn",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "warn",
"no-fallthrough": "error",
"no-floating-decimal": "warn",
"no-global-assign": "warn",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-labels": "error",
"no-loop-func": "error",
"no-multi-spaces": "warn",
"no-multi-str": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-octal": "error",
"no-octal-escape": "error",
"no-proto": "error",
"no-redeclare": "warn",
"no-return-assign": "error",
"no-script-url": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "warn",
"no-throw-literal": "warn",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "warn",
"no-useless-escape": "warn",
"no-with": "error",
"wrap-iife": ["error", "any"],
"no-delete-var": "error",
"no-undef": "error",
"no-undef-init": "error",
"no-unused-vars": ["error", { "caughtErrors": "none" }],
"array-bracket-spacing": "warn",
"block-spacing": "warn",
"brace-style": ["warn", "1tbs"],
"camelcase": "warn",
"capitalized-comments": ["warn", "always", { "ignoreConsecutiveComments": true }],
"comma-spacing": ["warn", { "before": false, "after": true }],
"comma-style": ["warn", "last"],
"computed-property-spacing": "error",
"consistent-this": "off",
"eol-last": "off",
"func-call-spacing": ["warn", "never"],
"func-names": "off",
"func-style": "off",
"indent": ["off", 4, { "SwitchCase": 1 }],
"key-spacing": ["warn", { "beforeColon": false, "afterColon": true, "mode": minimum }],
"keyword-spacing": "warn",
"linebreak-style": ["error", "unix"],
"lines-around-comment": "off",
"max-len": ["error", 132],
"max-lines": "off",
"max-depth": "warn",
"max-nested-callbacks": ["warn", 5],
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": ["warn", { max: 2 }],
"new-cap": ["warn", { "properties": false }],
"new-parens": "warn",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-array-constructor": "off",
"no-bitwise": "error",
"no-continue": "off",
"no-inline-comments": "off",
"no-lonely-if": "off",
"no-mixed-operators": "off",
"no-mixed-spaces-and-tabs": "error",
"no-multiple-empty-lines": "warn",
"no-negated-condition": "off",
"no-nested-ternary": "warn",
"no-new-object": "off",
"no-plusplus": "off",
"no-tabs": "error",
"no-ternary": "off",
"no-trailing-spaces": "error",
"no-underscore-dangle": "off",
"no-unneeded-ternary": "off",
"no-whitespace-before-property": "warn",
"object-curly-newline": "off",
"object-curly-spacing": "warn",
"object-property-newline": "off",
"one-var": "off",
"one-var-declaration-per-line": ["warn", "initializations"],
"operator-assignment": "off",
"operator-linebreak": "off",
"padded-blocks": "off",
"quote-props": ["warn", "as-needed", {"unnecessary": false, "keywords": true, "numbers": true}],
"quotes": "off",
"require-jsdoc": "warn",
"semi": "error",
"semi-spacing": ["warn", {"before": false, "after": true}],
"sort-vars": "off",
"space-before-blocks": "warn",
"space-before-function-paren": ["warn", "never"],
"space-in-parens": "warn",
"space-infix-ops": "warn",
"space-unary-ops": "warn",
"spaced-comment": "warn",
"unicode-bom": "error",
"wrap-regex": "off",
"no-restricted-properties": ["warn", {
"object": "M",
"property": "str",
"message": "Use AMD module 'core/str' or M.util.get_string()"
}],
},
overrides: [
{
files: ["**/yui/src/**/*.js"],
rules: {
"no-undef": "off",
"no-unused-vars": "off",
"no-unused-expressions": "off"
}
},
{
files: ["**/amd/src/*.js"],
rules: {
"no-unused-vars": "error",
"no-implicit-globals": "error"
}
}
]
}
/*global H5PDataView H5PIntegration H5P*/ /* global H5PDataView */
(function($) { (function($) {
/** /**
......
/*global H5PIntegration H5PEditor H5P*/
(function($) { (function($) {
/** /**
* Get closest row of element * Get closest row of element
* *
* @param $el * @param {jQuery} $el
* @returns jQuery * @returns {jQuery}
*/ */
function getRow($el) { function getRow($el) {
return $el.closest('.fitem'); return $el.closest('.fitem');
......
...@@ -129,8 +129,7 @@ document.onreadystatechange = function (){ ...@@ -129,8 +129,7 @@ document.onreadystatechange = function (){
clientHeight: iFrame.contentDocument.body.clientHeight clientHeight: iFrame.contentDocument.body.clientHeight
} }
); );
} } else {
else {
H5PEmbedCommunicator.send('hello'); H5PEmbedCommunicator.send('hello');
} }
}, 0); }, 0);
......
/*global HVPSettingsHideKey H5P*/ /* global HVPSettingsHideKey */
/** /**
* Prepares for hiding of the Site Key setting since you cannot modify attributes and such in Moodle. * Prepares for hiding of the Site Key setting since you cannot modify attributes and such in Moodle.
*/ */
......
/*global H5P*/
/** /**
* Collect results from xAPI events * Collect results from xAPI events
*/ */
...@@ -9,7 +8,7 @@ ...@@ -9,7 +8,7 @@
* *
* @param {Array} instances * @param {Array} instances
* @param {number} contentId * @param {number} contentId
* @returns {Object|null} Content instance * @returns {Object|undefined} Content instance
*/ */
function findInstanceInArray(instances, contentId) { function findInstanceInArray(instances, contentId) {
if (instances !== undefined && contentId !== undefined) { if (instances !== undefined && contentId !== undefined) {
...@@ -19,6 +18,7 @@ ...@@ -19,6 +18,7 @@
} }
} }
} }
return undefined;
} }
/** /**
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
// Assume first iframe. // Assume first iframe.
instance = iframes[0].contentWindow.H5P.instances[0]; instance = iframes[0].contentWindow.H5P.instances[0];
} }
} } else {
else {
// Try this documents instances. // Try this documents instances.
instance = findInstanceInArray(H5P.instances, contentId); instance = findInstanceInArray(H5P.instances, contentId);
if (!instance) { if (!instance) {
...@@ -72,8 +71,7 @@ ...@@ -72,8 +71,7 @@
// Use getXAPIData contract, needed to get children. // Use getXAPIData contract, needed to get children.
if (instance && instance.getXAPIData) { if (instance && instance.getXAPIData) {
xAPIData = instance.getXAPIData(); xAPIData = instance.getXAPIData();
} } else {
else {
// Fallback to event data. // Fallback to event data.
xAPIData = { xAPIData = {
statement: event.data.statement statement: event.data.statement
...@@ -86,7 +84,7 @@ ...@@ -86,7 +84,7 @@
xAPIResult: JSON.stringify(xAPIData) xAPIResult: JSON.stringify(xAPIData)
}).done(function(data) { }).done(function(data) {
if (data.error) { if (data.error) {
console.debug('Storing xAPI results failed with error message:', data); console.error('Storing xAPI results failed with error message:', data);
} }
}); });
} }
...@@ -94,13 +92,13 @@ ...@@ -94,13 +92,13 @@
$(document).ready(function() { $(document).ready(function() {
// No external dispatcher. // No external dispatcher.
if (!(window.H5P && H5P.externalDispatcher)) { if (!(window.H5P && H5P.externalDispatcher)) {
console.debug('External dispatcher not found'); console.error('External dispatcher not found');
return; return;
} }
// No ajax path. // No ajax path.
if (!(window.H5PIntegration && H5PIntegration.ajax && H5PIntegration.ajax.xAPIResult)) { if (!(window.H5PIntegration && H5PIntegration.ajax && H5PIntegration.ajax.xAPIResult)) {
console.debug('No ajax path found'); console.error('No ajax path found');
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment