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 Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
},
'rules': {
// 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
// for discussion and possible enable soon.
// rules.

// === Possible Errors ===
// DEFINE POLICY: 'comma-dangle': ['off', 'always'],
'comma-dangle': 'off',
'no-cond-assign': 'error',
'no-console': 'error',
'no-constant-condition': 'error',
Expand All @@ -21,7 +21,7 @@
'no-dupe-args': 'error',
'no-dupe-keys': '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-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
Expand All @@ -45,18 +45,25 @@

// === Best Practices ===
// (these mostly match our jshint config)
'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',
//DEFINE POLICY: 'no-eq-null': 'warn',
'no-eq-null': 'error',
'no-eval': 'error',
//DEFINE POLICY: 'no-extra-bind': 'warn',
'no-extend-native': 'error',
'no-extra-bind': 'warn',
'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-invalid-this': 'error',
'no-iterator': 'error',
Expand All @@ -67,26 +74,28 @@
'no-native-reassign': 'warn',
'no-new-func': 'error',
'no-new-wrappers': 'error',
// DEFINE POLICY: no-octal: "error"
// DEFINE POLICY: no-octal-escape: "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',
// Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-expressions': 'error',
'no-unused-labels': 'error',
//DEFINE POLICY: 'no-useless-call': 'error',
'no-useless-call': 'warn',
'no-useless-escape': 'warn',
//DEFINE POLICY: 'no-with': 'error',
'no-with': 'error',
'wrap-iife': ['error', 'any'],

// === Variables ===
'no-delete-var': 'error',
// 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',

// === Stylistic Issues ===
Expand All @@ -109,17 +118,16 @@
'lines-around-comment': 'off',
'max-len': ['error', 132],
'max-lines': 'off',
// DEFINE POLICY: turn on some of these max values?
'max-depth': 'off',
'max-nested-callbacks': 'off',
'max-depth': 'warn',
'max-nested-callbacks': ['warn', 5],
'max-params': 'off',
'max-statements': 'off',
'max-statements-per-line': 'off',
'max-statements-per-line': ['warn', { max: 2 }],
'new-cap': ['warn', { 'properties': false }],
'new-parens': 'warn',
'newline-after-var': 'off',
'newline-before-return': 'off',
// REVIST POLICY: 'newline-per-chained-call': 'warn',
'newline-per-chained-call': 'off',
'no-array-constructor': 'off',
'no-bitwise': 'error',
'no-continue': 'off',
Expand All @@ -136,17 +144,17 @@
'no-ternary': 'off',
'no-trailing-spaces': 'error',
'no-underscore-dangle': 'off',
// DEFINE POLICY: 'no-unneeded-ternary': 'off',
'no-unneeded-ternary': 'off',
'no-whitespace-before-property': 'warn',
// DEFINE POLICY: 'object-curly-newline': 'off,
// DEFINE POLICY: 'object-curly-spacing': 'off',
// DEFINE POLICY: 'object-property-newline': 'off',
'object-curly-newline': 'off',
'object-curly-spacing': 'warn',
'object-property-newline': 'off',
'one-var': 'off',
// DEFINE POLICY: 'one-var-declaration-per-line': 'off',
'one-var-declaration-per-line': ['warn', 'initializations'],
'operator-assignment': 'off',
'operator-linebreak': 'off',
'padded-blocks': 'off',
// DEFINE POLICY: 'quote-props': 'off',
'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
'quotes': 'off',
'require-jsdoc': 'warn',
'semi': 'error',
Expand Down
9 changes: 7 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ module.exports = function(grunt) {
eslint: {
// 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.
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
// to YUI rollups.
amd: {
src: amdSrc,
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.
Expand Down
2 changes: 2 additions & 0 deletions admin/tool/lp/amd/src/tree.js
Original file line number 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.
* @return {Boolean}
*/
// This function should be simplified. In the meantime..
// eslint-disable-next-line complexity
Tree.prototype.handleKeyDown = function(item, e) {
var currentIndex = this.visibleItems.index(item);
var newItem = null;
Expand Down
2 changes: 2 additions & 0 deletions lib/amd/src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ define(['jquery'], function($) {
* @param {Event} e The event.
* @return {Boolean}
*/
// This function should be simplified. In the meantime..
// eslint-disable-next-line complexity
Tree.prototype.handleKeyDown = function(item, e) {
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 Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Moodle",
"devDependencies": {
"async": "^1.5.2",
"eslint": "^2.13.1",
"grunt": "0.4.5",
"grunt-contrib-less": "1.1.0",
"grunt-contrib-uglify": "0.11.0",
Expand Down

0 comments on commit 037de71

Please sign in to comment.