From 6345a6ff63a8b8af86ee9a025e29984a410c9764 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 5 May 2024 21:03:16 +0200 Subject: [PATCH] Migrated to ESLint 9+. --- .eslintignore | 7 --- .eslintrc | 37 ----------- .pre-commit-config.yaml | 2 +- .../admin/static/admin/js/SelectFilter2.js | 2 +- .../contrib/admin/static/admin/js/actions.js | 2 +- .../admin/static/admin/js/popup_response.js | 1 - .../contrib/gis/static/gis/js/OLMapWidget.js | 2 +- eslint.config.mjs | 63 +++++++++++++++++++ js_tests/admin/actions.test.js | 2 +- js_tests/admin/navigation.test.js | 2 +- package.json | 3 +- 11 files changed, 71 insertions(+), 52 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 6e4edbd66d..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -**/*.min.js -**/vendor/**/*.js -django/contrib/gis/templates/**/*.js -django/views/templates/*.js -docs/_build/**/*.js -node_modules/**.js -tests/**/*.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 332755a844..0000000000 --- a/.eslintrc +++ /dev/null @@ -1,37 +0,0 @@ -{ - "rules": { - "camelcase": ["off", {"properties": "always"}], - "comma-spacing": ["error", {"before": false, "after": true}], - "curly": ["error", "all"], - "dot-notation": ["error", {"allowKeywords": true}], - "eqeqeq": ["error"], - "indent": ["error", 4], - "key-spacing": ["error", {"beforeColon": false, "afterColon": true}], - "linebreak-style": ["error", "unix"], - "new-cap": ["off", {"newIsCap": true, "capIsNew": true}], - "no-alert": ["off"], - "no-eval": ["error"], - "no-extend-native": ["error", {"exceptions": ["Date", "String"]}], - "no-multi-spaces": ["error"], - "no-octal-escape": ["error"], - "no-script-url": ["error"], - "no-shadow": ["error", {"hoist": "functions"}], - "no-underscore-dangle": ["error"], - "no-unused-vars": ["error", {"vars": "local", "args": "none"}], - "no-var": ["error"], - "prefer-const": ["error"], - "quotes": ["off", "single"], - "semi": ["error", "always"], - "space-before-blocks": ["error", "always"], - "space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}], - "space-infix-ops": ["error", {"int32Hint": false}], - "strict": ["error", "global"] - }, - "env": { - "browser": true, - "es6": true - }, - "globals": { - "django": false - } -} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a030ca7cc2..9deb1d0cc6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,6 @@ repos: hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.56.0 + rev: v9.2.0 hooks: - id: eslint diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js index fc59eba7c4..6957412462 100644 --- a/django/contrib/admin/static/admin/js/SelectFilter2.js +++ b/django/contrib/admin/static/admin/js/SelectFilter2.js @@ -1,4 +1,4 @@ -/*global SelectBox, gettext, interpolate, quickElement, SelectFilter*/ +/*global SelectBox, gettext, ngettext, interpolate, quickElement, SelectFilter*/ /* SelectFilter2 - Turns a multiple-select box into a filter interface. diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js index 6a2ae91a19..04b25e9684 100644 --- a/django/contrib/admin/static/admin/js/actions.js +++ b/django/contrib/admin/static/admin/js/actions.js @@ -1,4 +1,4 @@ -/*global gettext, interpolate, ngettext*/ +/*global gettext, interpolate, ngettext, Actions*/ 'use strict'; { function show(selector) { diff --git a/django/contrib/admin/static/admin/js/popup_response.js b/django/contrib/admin/static/admin/js/popup_response.js index 2b1d3dd31d..fecf0f4798 100644 --- a/django/contrib/admin/static/admin/js/popup_response.js +++ b/django/contrib/admin/static/admin/js/popup_response.js @@ -1,4 +1,3 @@ -/*global opener */ 'use strict'; { const initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse); diff --git a/django/contrib/gis/static/gis/js/OLMapWidget.js b/django/contrib/gis/static/gis/js/OLMapWidget.js index f3025f24ac..a545036c9f 100644 --- a/django/contrib/gis/static/gis/js/OLMapWidget.js +++ b/django/contrib/gis/static/gis/js/OLMapWidget.js @@ -54,7 +54,7 @@ class MapWidget { // Altering using user-provided options for (const property in options) { - if (options.hasOwnProperty(property)) { + if (Object.hasOwn(options, property)) { this.options[property] = options[property]; } } diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000000..306adb3aa5 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,63 @@ +import globals from "globals"; +import js from "@eslint/js"; + +export default [ + js.configs.recommended, + { + files: ["**/*.js"], + rules: { + "camelcase": ["off", {"properties": "always"}], + "comma-spacing": ["error", {"before": false, "after": true}], + "curly": ["error", "all"], + "dot-notation": ["error", {"allowKeywords": true}], + "eqeqeq": ["error"], + "indent": ["error", 4], + "key-spacing": ["error", {"beforeColon": false, "afterColon": true}], + "linebreak-style": ["error", "unix"], + "new-cap": ["off", {"newIsCap": true, "capIsNew": true}], + "no-alert": ["off"], + "no-eval": ["error"], + "no-extend-native": ["error", {"exceptions": ["Date", "String"]}], + "no-multi-spaces": ["error"], + "no-octal-escape": ["error"], + "no-script-url": ["error"], + "no-shadow": ["error", {"hoist": "functions"}], + "no-underscore-dangle": ["error"], + "no-unused-vars": ["error", {"vars": "local", "args": "none"}], + "no-var": ["error"], + "prefer-const": ["error"], + "quotes": ["off", "single"], + "semi": ["error", "always"], + "space-before-blocks": ["error", "always"], + "space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}], + "space-infix-ops": ["error", {"int32Hint": false}], + "strict": ["error", "global"] + }, + languageOptions: { + ecmaVersion: 6, + sourceType: "script", + globals: { + ...globals.browser, + ...globals.commonjs, + "django": false + } + } + }, + { + files: ["**/*.mjs"], + languageOptions: { + sourceType: "module" + } + }, + { + ignores: [ + "**/*.min.js", + "**/vendor/**/*.js", + "django/contrib/gis/templates/**/*.js", + "django/views/templates/*.js", + "docs/_build/**/*.js", + "node_modules/**.js", + "tests/**/*.js", + ] + } +]; diff --git a/js_tests/admin/actions.test.js b/js_tests/admin/actions.test.js index 0077dd6ff3..bcc10debaa 100644 --- a/js_tests/admin/actions.test.js +++ b/js_tests/admin/actions.test.js @@ -1,4 +1,4 @@ -/* global QUnit */ +/* global QUnit, Actions */ 'use strict'; QUnit.module('admin.actions', { diff --git a/js_tests/admin/navigation.test.js b/js_tests/admin/navigation.test.js index 262f08c9ae..0da50e757c 100644 --- a/js_tests/admin/navigation.test.js +++ b/js_tests/admin/navigation.test.js @@ -1,4 +1,4 @@ -/* global QUnit */ +/* global QUnit, initSidebarQuickFilter */ 'use strict'; QUnit.module('admin.sidebar: filter', { diff --git a/package.json b/package.json index 51836701e5..88d154cd28 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,9 @@ "npm": ">=1.3.0" }, "devDependencies": { - "eslint": "^8.56.0", + "eslint": "^9.2.0", "puppeteer": "^22.2.0", + "globals": "^15.1.0", "grunt": "^1.6.1", "grunt-cli": "^1.4.3", "grunt-contrib-qunit": "^8.0.1",