From be4b3cc6c7cf10645c899e9795f1428d19d19e5e Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Sat, 14 May 2016 11:10:13 +0100 Subject: [PATCH] MDL-52127 js: switch to a more YUI tolerant eslint config Instead of having the stricter configuration for all files, use the less strict default config and switch to the stricter config for building AMD modules. This means that the eslint commandline/editor inspections will work better for all files and not generate false positives when using editor integrations. But since grunt is required to build AMD modules we still get the stricter checking for those files on build. --- .eslintrc | 8 ++++---- Gruntfile.js | 14 ++++++++------ ...moodle-core-notification-ajaxexception-debug.js | 1 - .../moodle-core-notification-ajaxexception.js | 1 - .../moodle-core-notification-alert-debug.js | 1 - .../moodle-core-notification-alert.js | 1 - .../moodle-core-notification-confirm-debug.js | 1 - .../moodle-core-notification-confirm.js | 1 - .../moodle-core-notification-dialogue-debug.js | 1 - .../moodle-core-notification-dialogue.js | 1 - .../moodle-core-notification-exception-debug.js | 1 - .../moodle-core-notification-exception.js | 1 - lib/yui/src/notification/js/shared.js | 1 - 13 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.eslintrc b/.eslintrc index 05a6283b468..31bd8ab307e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,7 +21,7 @@ 'no-dupe-args': 'error', 'no-dupe-keys': 'error', 'no-duplicate-case': 'error', - 'no-empty': 'error', + // Disabled for YUI rollups, enabled by grunt for AMD: 'no-empty': 'error', 'no-empty-character-class': 'error', 'no-ex-assign': 'error', 'no-extra-boolean-cast': 'error', @@ -76,7 +76,7 @@ 'no-self-assign': 'error', 'no-self-compare': 'error', 'no-unmodified-loop-condition': 'error', - 'no-unused-expressions': '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-escape': 'warn', @@ -85,9 +85,9 @@ // === Variables === 'no-delete-var': 'error', - 'no-undef': 'error', + // Disabled for YUI rollups, enabled by grunt for AMD: 'no-undef': 'off', //DEFINE POLICY: 'no-undef-init': 'error', - 'no-unused-vars': 'error', + // Disabled for YUI rollups, enabled by grunt for AMD: 'no-unused-vars': 'error', // === Stylistic Issues === 'array-bracket-spacing': 'warn', diff --git a/Gruntfile.js b/Gruntfile.js index f152d3e1d1f..2ec167eaa64 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -75,13 +75,15 @@ module.exports = function(grunt) { // * It will complain about ignored files (https://github.com/sindresorhus/grunt-eslint/issues/119) // * It's better experience to use editor integrations or eslint natively options: { quiet: !grunt.option('show-lint-warnings') }, - // Check AMD files with standard config - amd: { src: amdSrc }, - // Some rules disabled for YUI config, because we don't do rollup magic, so its able to be accurate - // about undefined items. + // 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'} } + }, + // Check YUI module source files. yui: { - src: ['**/yui/src/**/*.js'], - options: {globals: ['Y', 'YUI'], rules: {'no-undef': 'off', 'no-unused-vars': 'off', 'no-empty': 'off'} } + src: ['**/yui/src/**/*.js'] } }, uglify: { diff --git a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js index ecd1ea534c1..bebacc1d174 100644 --- a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js +++ b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception-debug.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-ajaxexception', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js index ecd1ea534c1..bebacc1d174 100644 --- a/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js +++ b/lib/yui/build/moodle-core-notification-ajaxexception/moodle-core-notification-ajaxexception.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-ajaxexception', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js index b0115ec8476..1fa77324b20 100644 --- a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert-debug.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-alert', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js index b0115ec8476..1fa77324b20 100644 --- a/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js +++ b/lib/yui/build/moodle-core-notification-alert/moodle-core-notification-alert.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-alert', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js index b98dfe19fa7..459e5951b67 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm-debug.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-confirm', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js index b98dfe19fa7..459e5951b67 100644 --- a/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js +++ b/lib/yui/build/moodle-core-notification-confirm/moodle-core-notification-confirm.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-confirm', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js index f2f2ddd2910..86f372cba1c 100644 --- a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue-debug.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-dialogue', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js index 92c164348d2..26caaf2a363 100644 --- a/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js +++ b/lib/yui/build/moodle-core-notification-dialogue/moodle-core-notification-dialogue.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-dialogue', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js index 219d336b5e5..6f439323eb1 100644 --- a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception-debug.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-exception', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js index 219d336b5e5..6f439323eb1 100644 --- a/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js +++ b/lib/yui/build/moodle-core-notification-exception/moodle-core-notification-exception.js @@ -1,6 +1,5 @@ YUI.add('moodle-core-notification-exception', function (Y, NAME) { -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES, diff --git a/lib/yui/src/notification/js/shared.js b/lib/yui/src/notification/js/shared.js index b80eb437a46..362bd766c9b 100644 --- a/lib/yui/src/notification/js/shared.js +++ b/lib/yui/src/notification/js/shared.js @@ -1,4 +1,3 @@ -/* eslint-disable */ var DIALOGUE_PREFIX, BASE, CONFIRMYES,