From 7dcfcfcb3a70aab789af86ee35fabf512cd3d5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 11 Mar 2024 23:33:12 +0100 Subject: [PATCH] Replace jshint by eslint Closes #13087 --- .gitlab-ci.yml | 15 +++++++++++++++ sao/Gruntfile.js | 26 ++++--------------------- sao/eslint.config.mjs | 44 +++++++++++++++++++++++++++++++++++++++++++ sao/package.json | 4 +++- sao/src/.jshintrc | 6 ------ sao/src/sao.js | 7 +++++-- sao/src/view/form.js | 2 -- sao/tests/.jshintrc | 9 --------- 8 files changed, 71 insertions(+), 42 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 2f7957aca8..8e75023fb5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -127,6 +127,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 0ec1a429ce..da85d7ca9f 100644 --- a/sao/Gruntfile.js +++ b/sao/Gruntfile.js @@ -75,23 +75,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' + @@ -127,7 +110,7 @@ module.exports = function(grunt) { watch: { scripts: { files: ['src/**/*.js'], - tasks: ['concat', 'jshint'] + tasks: ['concat'] }, styles: { files: ['src/*.less'], @@ -152,17 +135,16 @@ 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.loadNpmTasks('grunt-qunit-junit'); 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'); @@ -178,7 +160,7 @@ module.exports = function(grunt) { }); grunt.registerTask('test', 'Run tests', function() { grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.task.run(['concat', 'jshint', 'less:dev', 'qunit_junit', 'qunit']); + grunt.task.run(['concat', 'less:dev', 'qunit_junit', '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 3ea62856a8..16fe7c9a94 100644 --- a/sao/package.json +++ b/sao/package.json @@ -34,9 +34,12 @@ ], "scripts": { "test": "npx grunt test -v", + "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", @@ -52,7 +55,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": "^5.0" } diff --git a/sao/src/.jshintrc b/sao/src/.jshintrc deleted file mode 100644 index e95d2a3226..0000000000 --- a/sao/src/.jshintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "browser": true, - "devel": true, - "esversion": 6, - "jquery": true -} diff --git a/sao/src/sao.js b/sao/src/sao.js index 635c4cc895..cb1a51264d 100644 --- a/sao/src/sao.js +++ b/sao/src/sao.js @@ -1,8 +1,11 @@ /* 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 = { __version__: '7.1.0', }; +/* eslint-enable no-redeclare */ (function() { 'use strict'; @@ -1201,7 +1204,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(); @@ -1293,7 +1296,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 6d31cae878..4cde01d8d8 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 833a0df37b..0000000000 --- a/sao/tests/.jshintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "browser": true, - "esversion": 6, - "jquery": true, - "predef": [ - "QUnit", - "Sao" - ] -}