From 06c3363a30a165c95da14ee747d3bee4fd4cf8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 26 Mar 2024 00:10:10 +0100 Subject: [PATCH] Replace jshint by eslint Closes #13087 (grafted from b2a2c9483562f6ae5430df5cc957148003ac3520) --HG-- branch : 6.0 --- .gitlab-ci.yml | 15 +++++++++++++++ sao/Gruntfile.js | 26 ++++--------------------- sao/eslint.config.mjs | 44 +++++++++++++++++++++++++++++++++++++++++++ sao/package.json | 4 +++- sao/src/.jshintrc | 5 ----- sao/src/sao.js | 7 +++++-- sao/src/view/form.js | 2 -- sao/tests/.jshintrc | 8 -------- 8 files changed, 71 insertions(+), 40 deletions(-) create mode 100644 sao/eslint.config.mjs delete mode 100644 sao/src/.jshintrc delete mode 100644 sao/tests/.jshintrc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a591e3b31b..5eafe3e9e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -100,6 +100,21 @@ check-dist: script: - twine check packages/* +check-eslint: + extends: .check + image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node + variables: + NODE_CACHE_DIR: "$CI_PROJECT_DIR/.cache/npm" + cache: + paths: + - .cache/npm + before_script: + - sh .gitlab-scripts/bower_allow_root.sh + script: + - cd sao + - npm install --cache ${NODE_CACHE_DIR} --unsafe-perm --legacy-peer-deps + - npm run check + check-ci-modules: extends: .check script: diff --git a/sao/Gruntfile.js b/sao/Gruntfile.js index c33d334a8e..782243fe7d 100644 --- a/sao/Gruntfile.js +++ b/sao/Gruntfile.js @@ -74,23 +74,6 @@ module.exports = function(grunt) { dest: 'dist/<%= pkg.name %>.js' } }, - jshint: { - dist: { - options: { - jshintrc: 'src/.jshintrc' - }, - src: ['dist/<%= pkg.name %>.js'] - }, - grunt: { - src: ['Gruntfile.js'] - }, - tests: { - options: { - jshintrc: 'tests/.jshintrc' - }, - src: ['tests/*.js'] - } - }, uglify: { options: { banner: '/*! <%= pkg.name %>-<%= pkg.version %> | GPL-3\n' + @@ -126,7 +109,7 @@ module.exports = function(grunt) { watch: { scripts: { files: ['src/**/*.js'], - tasks: ['concat', 'jshint'] + tasks: ['concat'] }, styles: { files: ['src/*.less'], @@ -151,16 +134,15 @@ module.exports = function(grunt) { }); grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-po2json'); grunt.registerTask('default', 'Build for production.', function() { - grunt.task.run(['concat', 'jshint', 'uglify', 'less', 'po2json']); + grunt.task.run(['concat', 'uglify', 'less', 'po2json']); }); grunt.registerTask('dev', 'Build for development.', function() { - grunt.task.run(['concat', 'jshint', 'less:dev']); + grunt.task.run(['concat', 'less:dev']); }); grunt.registerTask('devwatch', 'Watch development', function() { grunt.loadNpmTasks('grunt-contrib-watch'); @@ -176,7 +158,7 @@ module.exports = function(grunt) { }); grunt.registerTask('test', 'Run tests', function() { grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.task.run(['concat', 'jshint', 'less:dev', 'qunit']); + grunt.task.run(['concat', 'less:dev', 'qunit']); }); }; diff --git a/sao/eslint.config.mjs b/sao/eslint.config.mjs new file mode 100644 index 0000000000..81ee681a6d --- /dev/null +++ b/sao/eslint.config.mjs @@ -0,0 +1,44 @@ +import js from "@eslint/js"; +import globals from "globals"; + +export default [ + js.configs.recommended, + { + languageOptions: { + ecmaVersion: 6, + sourceType: "script", + globals: { + Mousetrap: "readonly", + Papa: "readonly", + QUnit: "readonly", + Sao: "readonly", + Sortable: "readonly", + c3: "readonly", + i18n: "readonly", + jQuery: "readonly", + moment: "readonly", + ...globals.browser + }, + }, + rules: { + "getter-return": "off", + "no-constant-condition": "off", + "no-empty": "off", + "no-extra-boolean-cast": "off", + "no-prototype-builtins": "off", + "no-self-assign": "off", + "no-unexpected-multiline": "off", + "no-unused-vars": "off", + "no-useless-escape": "off", + "no-with": "off", + }, + }, { + files: ['tests/**/*.js'], + languageOptions: { + globals: { + Sao: "readonly", + eval_pyson: "readonly", + }, + }, + }, +]; diff --git a/sao/package.json b/sao/package.json index 54630d8f1c..29bd6663c5 100644 --- a/sao/package.json +++ b/sao/package.json @@ -33,9 +33,12 @@ ], "scripts": { "test": "npx grunt test", + "check": "npx eslint src tests", "postinstall": "npx bower install" }, "devDependencies": { + "eslint": "^8.57.0", + "globals": "^14.0.0", "grunt-contrib-nodeunit": "^2.0", "grunt-contrib-qunit": "^3.1", "grunt-contrib-watch": "^1.1", @@ -51,7 +54,6 @@ "grunt": "^1.0", "grunt-cli": "^1.3", "grunt-contrib-concat": "^1.0", - "grunt-contrib-jshint": "^2.1", "grunt-contrib-less": "^2.0", "grunt-contrib-uglify": "^4.0" } diff --git a/sao/src/.jshintrc b/sao/src/.jshintrc deleted file mode 100644 index 5956712c68..0000000000 --- a/sao/src/.jshintrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "browser": true, - "devel": true, - "jquery": true -} diff --git a/sao/src/sao.js b/sao/src/sao.js index 0eef4845b3..e8352ea951 100644 --- a/sao/src/sao.js +++ b/sao/src/sao.js @@ -1,6 +1,9 @@ /* This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. */ + +/* eslint-disable no-redeclare */ var Sao = {}; +/* eslint-enable no-redeclare */ (function() { 'use strict'; @@ -1105,7 +1108,7 @@ var Sao = {}; if (definition.id){ var current_tab = Sao.Tab.tabs.get_current(); if (current_tab) { - var focused = $(':focus'); + var focused = jQuery(':focus'); focused.blur(); current_tab.el.find('a[id="' + definition.id + '"]').click(); focused.focus(); @@ -1177,7 +1180,7 @@ var Sao = {}; .on('hidden.bs.modal', '.modal', function(event) { setModalsAndBackdropsOrder(); if (jQuery('.modal:visible').length) { - $(document.body).addClass('modal-open'); + jQuery(document.body).addClass('modal-open'); } }); diff --git a/sao/src/view/form.js b/sao/src/view/form.js index b6c7577dcb..0386c74288 100644 --- a/sao/src/view/form.js +++ b/sao/src/view/form.js @@ -1,7 +1,6 @@ /* This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. */ -/* jshint ignore:start */ // Must be defined in non strict context otherwise is invalid function eval_pyson(value){ with (Sao.PYSON.eval) { @@ -9,7 +8,6 @@ function eval_pyson(value){ return eval('(' + value + ')'); } } -/* jshint ignore:end */ (function() { 'use strict'; diff --git a/sao/tests/.jshintrc b/sao/tests/.jshintrc deleted file mode 100644 index 6ee8114281..0000000000 --- a/sao/tests/.jshintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "browser": true, - "jquery": true, - "predef": [ - "QUnit", - "Sao" - ] -}