Skip to content

Commit

Permalink
MDL-54944 eslint: Add rules from Policy decision
Browse files Browse the repository at this point in the history
Also bump eslint to v2.13.1 and make the version explicit in
package.json
  • Loading branch information
danpoltawski committed Jul 7, 2016
1 parent 5a1728d commit 037de71
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 59 deletions.
54 changes: 31 additions & 23 deletions .eslintrc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
}, },
'rules': { 'rules': {
// See http://eslint.org/docs/rules/ for all rules and explanations of all // See http://eslint.org/docs/rules/ for all rules and explanations of all
// rules. Commented out rules with 'DEFINE POLICY' are rules Dan P has flagged // rules.
// for discussion and possible enable soon.
// === Possible Errors === // === Possible Errors ===
// DEFINE POLICY: 'comma-dangle': ['off', 'always'], 'comma-dangle': 'off',
'no-cond-assign': 'error', 'no-cond-assign': 'error',
'no-console': 'error', 'no-console': 'error',
'no-constant-condition': 'error', 'no-constant-condition': 'error',
Expand All @@ -21,7 +21,7 @@
'no-dupe-args': 'error', 'no-dupe-args': 'error',
'no-dupe-keys': 'error', 'no-dupe-keys': 'error',
'no-duplicate-case': 'error', 'no-duplicate-case': 'error',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-empty': 'error', 'no-empty': 'warn',
'no-empty-character-class': 'error', 'no-empty-character-class': 'error',
'no-ex-assign': 'error', 'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error', 'no-extra-boolean-cast': 'error',
Expand All @@ -45,18 +45,25 @@


// === Best Practices === // === Best Practices ===
// (these mostly match our jshint config) // (these mostly match our jshint config)
'array-callback-return': 'warn',
'block-scoped-var': 'warn',
'complexity': 'warn',
'consistent-return': 'warn',
'curly': 'error', 'curly': 'error',
'dot-notation': 'warn', 'dot-notation': 'warn',
'no-alert': 'warn', 'no-alert': 'warn',
'no-caller': 'error', 'no-caller': 'error',
'no-case-declarations': 'error', 'no-case-declarations': 'error',
'no-div-regex': 'error',
'no-empty-pattern': 'error', 'no-empty-pattern': 'error',
'no-empty-function': 'warn', 'no-empty-function': 'warn',
//DEFINE POLICY: 'no-eq-null': 'warn', 'no-eq-null': 'error',
'no-eval': 'error', 'no-eval': 'error',
//DEFINE POLICY: 'no-extra-bind': 'warn', 'no-extend-native': 'error',
'no-extra-bind': 'warn',
'no-fallthrough': 'error', 'no-fallthrough': 'error',
//DEFINE POLICY: 'no-implicit-globals': 'warn', 'no-floating-decimal': 'warn',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-implicit-globals': 'warn',
'no-implied-eval': 'error', 'no-implied-eval': 'error',
'no-invalid-this': 'error', 'no-invalid-this': 'error',
'no-iterator': 'error', 'no-iterator': 'error',
Expand All @@ -67,26 +74,28 @@
'no-native-reassign': 'warn', 'no-native-reassign': 'warn',
'no-new-func': 'error', 'no-new-func': 'error',
'no-new-wrappers': 'error', 'no-new-wrappers': 'error',
// DEFINE POLICY: no-octal: "error" 'no-octal': 'error',
// DEFINE POLICY: no-octal-escape: "error" 'no-octal-escape': 'error',
'no-proto': 'error', 'no-proto': 'error',
'no-redeclare': 'warn', 'no-redeclare': 'warn',
'no-return-assign': 'error', 'no-return-assign': 'error',
'no-script-url': 'error', 'no-script-url': 'error',
'no-self-assign': 'error', 'no-self-assign': 'error',
'no-self-compare': 'error', 'no-self-compare': 'error',
'no-sequences': 'warn',
'no-throw-literal': 'warn',
'no-unmodified-loop-condition': 'error', 'no-unmodified-loop-condition': 'error',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-expressions': 'error', // Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-expressions': 'error',
'no-unused-labels': 'error', 'no-unused-labels': 'error',
//DEFINE POLICY: 'no-useless-call': 'error', 'no-useless-call': 'warn',
'no-useless-escape': 'warn', 'no-useless-escape': 'warn',
//DEFINE POLICY: 'no-with': 'error', 'no-with': 'error',
'wrap-iife': ['error', 'any'], 'wrap-iife': ['error', 'any'],


// === Variables === // === Variables ===
'no-delete-var': 'error', 'no-delete-var': 'error',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-undef': 'off', // Disabled for YUI rollups, enabled by grunt for AMD: 'no-undef': 'off',
//DEFINE POLICY: 'no-undef-init': 'error', 'no-undef-init': 'error',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-vars': 'error', // Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-vars': 'error',


// === Stylistic Issues === // === Stylistic Issues ===
Expand All @@ -109,17 +118,16 @@
'lines-around-comment': 'off', 'lines-around-comment': 'off',
'max-len': ['error', 132], 'max-len': ['error', 132],
'max-lines': 'off', 'max-lines': 'off',
// DEFINE POLICY: turn on some of these max values? 'max-depth': 'warn',
'max-depth': 'off', 'max-nested-callbacks': ['warn', 5],
'max-nested-callbacks': 'off',
'max-params': 'off', 'max-params': 'off',
'max-statements': 'off', 'max-statements': 'off',
'max-statements-per-line': 'off', 'max-statements-per-line': ['warn', { max: 2 }],
'new-cap': ['warn', { 'properties': false }], 'new-cap': ['warn', { 'properties': false }],
'new-parens': 'warn', 'new-parens': 'warn',
'newline-after-var': 'off', 'newline-after-var': 'off',
'newline-before-return': 'off', 'newline-before-return': 'off',
// REVIST POLICY: 'newline-per-chained-call': 'warn', 'newline-per-chained-call': 'off',
'no-array-constructor': 'off', 'no-array-constructor': 'off',
'no-bitwise': 'error', 'no-bitwise': 'error',
'no-continue': 'off', 'no-continue': 'off',
Expand All @@ -136,17 +144,17 @@
'no-ternary': 'off', 'no-ternary': 'off',
'no-trailing-spaces': 'error', 'no-trailing-spaces': 'error',
'no-underscore-dangle': 'off', 'no-underscore-dangle': 'off',
// DEFINE POLICY: 'no-unneeded-ternary': 'off', 'no-unneeded-ternary': 'off',
'no-whitespace-before-property': 'warn', 'no-whitespace-before-property': 'warn',
// DEFINE POLICY: 'object-curly-newline': 'off, 'object-curly-newline': 'off',
// DEFINE POLICY: 'object-curly-spacing': 'off', 'object-curly-spacing': 'warn',
// DEFINE POLICY: 'object-property-newline': 'off', 'object-property-newline': 'off',
'one-var': 'off', 'one-var': 'off',
// DEFINE POLICY: 'one-var-declaration-per-line': 'off', 'one-var-declaration-per-line': ['warn', 'initializations'],
'operator-assignment': 'off', 'operator-assignment': 'off',
'operator-linebreak': 'off', 'operator-linebreak': 'off',
'padded-blocks': 'off', 'padded-blocks': 'off',
// DEFINE POLICY: 'quote-props': 'off', 'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
'quotes': 'off', 'quotes': 'off',
'require-jsdoc': 'warn', 'require-jsdoc': 'warn',
'semi': 'error', 'semi': 'error',
Expand Down
9 changes: 7 additions & 2 deletions Gruntfile.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ module.exports = function(grunt) {
eslint: { eslint: {
// Even though warnings dont stop the build we don't display warnings by default because // Even though warnings dont stop the build we don't display warnings by default because
// at this moment we've got too many core warnings. // at this moment we've got too many core warnings.
options: { quiet: !grunt.option('show-lint-warnings') }, options: {quiet: !grunt.option('show-lint-warnings')},
// Check AMD files. We add some stricter rules which we can't apply to the default configuration due // Check AMD files. We add some stricter rules which we can't apply to the default configuration due
// to YUI rollups. // to YUI rollups.
amd: { amd: {
src: amdSrc, src: amdSrc,
options: { options: {
rules: {'no-undef': 'error', 'no-unused-vars': 'error', 'no-empty': 'error', 'no-unused-expressions': 'error'} rules: {
'no-undef': 'error',
'no-unused-vars': 'error',
'no-unused-expressions': 'error',
'no-implicit-globals': 'error'
}
} }
}, },
// Check YUI module source files. // Check YUI module source files.
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/lp/amd/src/tree.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ define(['jquery', 'core/url', 'core/log'], function($, url, log) {
* @param {Event} e The event. * @param {Event} e The event.
* @return {Boolean} * @return {Boolean}
*/ */
// This function should be simplified. In the meantime..
// eslint-disable-next-line complexity
Tree.prototype.handleKeyDown = function(item, e) { Tree.prototype.handleKeyDown = function(item, e) {
var currentIndex = this.visibleItems.index(item); var currentIndex = this.visibleItems.index(item);
var newItem = null; var newItem = null;
Expand Down
2 changes: 2 additions & 0 deletions lib/amd/src/tree.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ define(['jquery'], function($) {
* @param {Event} e The event. * @param {Event} e The event.
* @return {Boolean} * @return {Boolean}
*/ */
// This function should be simplified. In the meantime..
// eslint-disable-next-line complexity
Tree.prototype.handleKeyDown = function(item, e) { Tree.prototype.handleKeyDown = function(item, e) {
var currentIndex = this.getVisibleItems().index(item); var currentIndex = this.getVisibleItems().index(item);


Expand Down
73 changes: 39 additions & 34 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Moodle", "description": "Moodle",
"devDependencies": { "devDependencies": {
"async": "^1.5.2", "async": "^1.5.2",
"eslint": "^2.13.1",
"grunt": "0.4.5", "grunt": "0.4.5",
"grunt-contrib-less": "1.1.0", "grunt-contrib-less": "1.1.0",
"grunt-contrib-uglify": "0.11.0", "grunt-contrib-uglify": "0.11.0",
Expand Down

0 comments on commit 037de71

Please sign in to comment.