From 1a3bc437159acef39a61d0c135b93fb2cf0d5743 Mon Sep 17 00:00:00 2001 From: Situphen Date: Fri, 25 Mar 2022 19:47:09 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20des=20d=C3=A9pendances?= =?UTF-8?q?=20front=20(#6261)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mise à jour des dépendances front * Modifications cosmétiques des fichiers JS * Correction manuelle des erreurs ESLint --- .eslintignore | 1 + Gulpfile.js | 27 +- assets/js/ajax-actions.js | 86 +- assets/js/autocompletion.js | 62 +- assets/js/charts.js | 54 +- assets/js/content-publication-readiness.js | 12 +- assets/js/dropdown-menu.js | 24 +- assets/js/editor-new.js | 82 +- assets/js/featured-request-ignore.js | 12 +- assets/js/featured-resource-preview.js | 4 +- assets/js/form-email-username.js | 12 +- assets/js/gallery.js | 8 +- assets/js/jquery-tabbable.js | 10 +- assets/js/karma.js | 28 +- assets/js/keyboard-navigation.js | 10 +- assets/js/markdown-help.js | 12 +- assets/js/mobile-menu.js | 64 +- assets/js/snow.js | 12 +- assets/js/spoiler.js | 10 +- assets/js/submit-dbclick.js | 4 +- assets/js/tab-modalize.js | 10 +- assets/js/topic-suggest.js | 26 +- assets/js/tribune-pick.js | 20 +- assets/js/userprofile-bio.js | 10 +- assets/js/zen-mode.js | 8 +- package.json | 21 +- yarn.lock | 1346 +++++++++----------- 27 files changed, 921 insertions(+), 1054 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000..5da9ae26ad --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +assets/js/editor-old.js diff --git a/Gulpfile.js b/Gulpfile.js index 13e01d3a12..e25f9d605b 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -2,7 +2,7 @@ const autoprefixer = require('autoprefixer') const concat = require('gulp-concat') const cssnano = require('cssnano') const del = require('del') -const eslint = require('gulp-eslint') +const { ESLint } = require('eslint') const gulp = require('gulp') const gulpif = require('gulp-if') const imagemin = require('gulp-imagemin') @@ -94,7 +94,7 @@ function errors() { /* JS tasks */ // ESLint options -var eslintOptions = {} +let eslintOptions = {} const fix = options.has('fix') if (fix) { eslintOptions = { fix: true } @@ -102,12 +102,19 @@ if (fix) { // Lints the JS source files -function jsLint() { - return gulp.src(['assets/js/*.js', 'Gulpfile.js', '!assets/js/editor-old.js'], { base: '.' }) - .pipe(eslint(eslintOptions)) - .pipe(eslint.format()) - .pipe(gulp.dest('.')) - .pipe(eslint.failAfterError()) +async function jsLint() { + const eslint = new ESLint(eslintOptions) + + const results = await eslint.lintFiles(['assets/js/*.js', 'Gulpfile.js']) + + if (fix) { + await ESLint.outputFixes(results) + } + + const formatter = await eslint.loadFormatter('stylish') + const resultText = formatter.format(results) + + console.log(resultText) } // Get JS minified files from packages @@ -148,7 +155,7 @@ function js() { // Optimizes the images function images() { - var plugins = [ + const plugins = [ imagemin.gifsicle(), imagemin.mozjpeg(), imagemin.optipng(), @@ -202,7 +209,7 @@ function watch() { } // Build the front -var build = gulp.parallel(prepareZmd, prepareEasyMde, jsPackages, js, images, gulp.series(spriteCss, gulp.parallel(css, spriteImages))) +const build = gulp.parallel(prepareZmd, prepareEasyMde, jsPackages, js, images, gulp.series(spriteCss, gulp.parallel(css, spriteImages))) exports.build = build exports.watch = gulp.series(build, watch) diff --git a/assets/js/ajax-actions.js b/assets/js/ajax-actions.js index 7efa08322d..44e700353a 100644 --- a/assets/js/ajax-actions.js +++ b/assets/js/ajax-actions.js @@ -11,15 +11,15 @@ * @param {string} dataAttribute */ $.fn.toggleText = function(dataAttribute) { - var textContainer = this.find('.a11y') + let textContainer = this.find('.a11y') if (textContainer.length === 0) { textContainer = this } else { textContainer = $(textContainer[0]) } - var text = textContainer.text() - var textToPut = this.data(dataAttribute) + const text = textContainer.text() + const textToPut = this.data(dataAttribute) textContainer.text(textToPut) this.data(dataAttribute, text) @@ -27,7 +27,7 @@ function synchText() { $('#mobile-menu [data-ajax-input]').each(function() { - var dataAjaxInput = $(this).data('ajax-input') + const dataAjaxInput = $(this).data('ajax-input') $(this).text($('.sidebar').find("button[data-ajax-input='" + dataAjaxInput + "']").text()) }) } @@ -36,13 +36,13 @@ * Follow a topic */ $('.sidebar, .flexpage-title-tool .actions').on('click', "[data-ajax-input='follow-topic']", function(e) { - var $act = $(this) - var $form = $(this).parents('form:first') - var $email = $(this).parents('li:first').next().find("[data-ajax-input='follow-topic-by-email']") - var $followText = $act.find('span#follow_text') - var $count = $form.find('span#subscriber_count') - var $plural = $act.find('span#subscriber_plural') - var $otherSubscriberCount = $($act.attr('data-raw-subscriber-count')) + const $act = $(this) + const $form = $(this).parents('form:first') + let $email = $(this).parents('li:first').next().find("[data-ajax-input='follow-topic-by-email']") + const $followText = $act.find('span#follow_text') + const $count = $form.find('span#subscriber_count') + const $plural = $act.find('span#subscriber_plural') + const $otherSubscriberCount = $($act.attr('data-raw-subscriber-count')) if ($email.length === 0) { $email = $(this).parents('.buttons-combined').find("[data-ajax-input='follow-topic-by-email']") @@ -50,10 +50,10 @@ $email.prop('disabled', true) - var csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - var topic = $form.find('input[name=topic]').val() - var follow = $form.find('input[name=follow]').val() - var page = $form.find('input[name=page]').val() + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + const topic = $form.find('input[name=topic]').val() + const follow = $form.find('input[name=follow]').val() + const page = $form.find('input[name=page]').val() $.ajax({ url: $form.attr('action'), @@ -105,9 +105,9 @@ * Be notified by email */ $('.sidebar, .flexpage-title-tool .actions').on('click', "[data-ajax-input='follow-topic-by-email']", function(e) { - var $act = $(this) - var $follow = $(this).parents('li:first').prev().find("[data-ajax-input='follow-topic']") - var $form = $(this).parents('form:first') + const $act = $(this) + let $follow = $(this).parents('li:first').prev().find("[data-ajax-input='follow-topic']") + const $form = $(this).parents('form:first') if ($follow.length === 0) { $follow = $(this).parents('.buttons-combined').find("[data-ajax-input='follow-topic']") @@ -115,10 +115,10 @@ $follow.prop('disabled', true) - var csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - var topic = $form.find('input[name=topic]').val() - var email = $form.find('input[name=email]').val() - var page = $form.find('input[name=page]').val() + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + const topic = $form.find('input[name=topic]').val() + const email = $form.find('input[name=email]').val() + const page = $form.find('input[name=page]').val() $.ajax({ url: $form.attr('action'), @@ -163,14 +163,14 @@ * Featured request */ $('.sidebar').on('click', "[data-ajax-input='request-featured']", function(e) { - var $act = $(this) - var $form = $(this).parents('form:first') - var $requestText = $act.find('#request_text') - var $count = $form.find('#featured_request_count') - var $plural = $act.find('#featured_request_plural') + const $act = $(this) + const $form = $(this).parents('form:first') + const $requestText = $act.find('#request_text') + const $count = $form.find('#featured_request_count') + const $plural = $act.find('#featured_request_plural') - var csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - var requestFeatured = $form.find('input[name=request_featured]').val() + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + const requestFeatured = $form.find('input[name=request_featured]').val() $.ajax({ url: $form.attr('action'), @@ -198,13 +198,13 @@ * Mark a topic solved */ $('.sidebar').on('click', "[data-ajax-input='solve-topic']", function(e) { - var $act = $(this) - var $form = $(this).parents('form:first') + const $act = $(this) + const $form = $(this).parents('form:first') - var csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - var topic = $form.find('input[name=topic]').val() - var solved = $form.find('input[name=solved]').val() - var page = $form.find('input[name=page]').val() + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + const topic = $form.find('input[name=topic]').val() + const solved = $form.find('input[name=solved]').val() + const page = $form.find('input[name=page]').val() $.ajax({ url: $form.attr('action'), @@ -239,8 +239,8 @@ * Mobile action */ $('#mobile-menu').on('click', '[data-ajax-input]', function(e) { - var dataAjaxInput = $(this).data('ajax-input') - var $button = $('.sidebar').find("button[data-ajax-input='" + dataAjaxInput + "']") + const dataAjaxInput = $(this).data('ajax-input') + const $button = $('.sidebar').find("button[data-ajax-input='" + dataAjaxInput + "']") if ($button[0]) { $(this).toggleText('content-on-click') @@ -252,8 +252,8 @@ }) function getLineAt(string, index) { - var before = string.slice(0, index).split('\n').slice(-1)[0] || '' - var after = string.slice(index).split('\n')[0] || '' + const before = string.slice(0, index).split('\n').slice(-1)[0] || '' + const after = string.slice(index).split('\n')[0] || '' return before + after } @@ -268,8 +268,8 @@ return } - var before = editor.value.slice(0, editor.selectionStart) - var after = editor.value.slice(editor.selectionEnd) + const before = editor.value.slice(0, editor.selectionStart) + const after = editor.value.slice(editor.selectionEnd) editor.value = before + '\n' + citation + '\n' + after } @@ -297,8 +297,8 @@ e.stopPropagation() e.preventDefault() - var $act = $(this) - var editor = document.querySelector('.md-editor') + const $act = $(this) + const editor = document.querySelector('.md-editor') $.ajax({ url: $act.attr('href'), diff --git a/assets/js/autocompletion.js b/assets/js/autocompletion.js index 6d99d8a13b..0a79b10272 100644 --- a/assets/js/autocompletion.js +++ b/assets/js/autocompletion.js @@ -42,7 +42,7 @@ cache: {}, handleKeydown: function(e) { - var $tmp + let $tmp switch (e.which) { case 38: // Up e.preventDefault() @@ -82,14 +82,14 @@ e.stopPropagation() } - var input = this.$input.val() + const input = this.$input.val() if (this._lastInput === input) { return } this._lastInput = input - var search = this.parseInput(input) - var self = this + const search = this.parseInput(input) + const self = this if (!search || search === this._lastAutocomplete) { this.hideDropdown() @@ -116,7 +116,7 @@ }, handleSubmit: function() { - var content = this.$input.val() + const content = this.$input.val() if (content.slice(-2) === ', ') { this.$input.val(content.slice(0, -2)) } @@ -139,15 +139,15 @@ enter: function(selected) { selected = selected || this.selected - var input = this.$input.val() - var lastChar = input.substr(-1) + let input = this.$input.val() + const lastChar = input.substr(-1) if ((lastChar === ',' || selected === -1) && this.options.type === 'multiple') { return false } - var completion = this.getFromCache(selected) + const completion = this.getFromCache(selected) if (!completion) { return false } if (this.options.type === 'multiple') { - var lastComma = input.lastIndexOf(',') + const lastComma = input.lastIndexOf(',') if (lastComma !== -1) { input = input.substr(0, lastComma) + ', ' + completion[this.options.fieldname] + ', ' this.$input.val(input) @@ -172,13 +172,13 @@ }, updateCache: function(data) { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { this.cache[data[i][this.options.fieldname]] = data[i] } }, extractWords: function(input) { - var words = $.grep( + const words = $.grep( $.map(input.split(','), $.trim), // Remove empty function(e) { return e === '' || e === undefined @@ -193,7 +193,7 @@ if (this.options.type === 'multiple') { if (input.substr(-1) === ',' || input.substr(-2) === ', ') { return false } - var words = this.extractWords(input) + const words = this.extractWords(input) if (words.length === 0) return false return words[words.length - 1] // last word in list @@ -203,7 +203,7 @@ }, searchCache: function(input) { - var regexp = new RegExp(input, 'ig') + const regexp = new RegExp(input, 'ig') return $.grep( this.cache, function(e) { @@ -213,22 +213,22 @@ }, getFromCache: function(id) { - for (var i in this.cache) { + for (const i in this.cache) { if (parseInt(this.cache[i].id) === parseInt(id)) { return this.cache[i] } } return false }, filterData: function(data, exclude) { - var fieldname = this.options.fieldname + const fieldname = this.options.fieldname return data.filter(function(e) { return exclude.indexOf(e[fieldname]) === -1 }) }, updateDropdown: function(list) { - var self = this - var onClick = function(e) { + const self = this + const onClick = function(e) { e.preventDefault() e.stopPropagation() self.enter($(this).attr('data-autocomplete-id')) @@ -240,9 +240,9 @@ if (list.length > this.options.limit) list = list.slice(0, this.options.limit) - var $list = $('