Build: Update ESLint to v9, migrate to flat config, lint dist files

Dist files linting is limited to checking if they're proper ES5.

Closes gh-2336
This commit is contained in:
Michał Gołębiowski-Owczarek
2025-03-03 20:15:14 +01:00
committed by GitHub
parent 302b488b92
commit 1da395de2e
16 changed files with 181 additions and 100 deletions

View File

@@ -1,4 +0,0 @@
dist/**/*
external/**/*
tests/lib/vendor/**/*
ui/vendor/**/*

View File

@@ -1,21 +0,0 @@
{
"root": true,
"extends": "jquery",
// Uncomment to find useless comment disable directives
// "reportUnusedDisableDirectives": true,
"parserOptions": {
"ecmaVersion": 2018
},
"env": {
"es6": true,
"node": true
},
"rules": {
"strict": [ "error", "global" ]
}
}

View File

@@ -49,12 +49,13 @@ jobs:
- name: Install npm dependencies
run: npm install
- name: Lint
run: npm run lint
- name: Build
run: npm run build
# Lint must happen after build as we lint generated files.
- name: Lint
run: npm run lint
- name: Test
run: |
npm run test:unit -- \

View File

@@ -204,9 +204,12 @@ grunt.initConfig( {
"ui/**/*.js",
"!ui/vendor/**/*.js",
"Gruntfile.js",
"dist/jquery-ui.js",
"dist/jquery-ui.min.js",
"build/**/*.js",
"tests/unit/**/*.js",
"tests/lib/**/*.js",
"!tests/lib/vendor/**/*.js",
"demos/**/*.js"
]
},
@@ -401,7 +404,7 @@ grunt.registerTask( "lint", [
"htmllint"
] );
grunt.registerTask( "build", [ "requirejs", "concat", "minify:main" ] );
grunt.registerTask( "default", [ "lint", "build" ] );
grunt.registerTask( "default", [ "build", "lint" ] );
grunt.registerTask( "sizer", [ "requirejs:js", "minify:main", "compare_size:all" ] );
grunt.registerTask( "sizer_all", [ "requirejs:js", "minify", "compare_size" ] );

View File

@@ -1,9 +0,0 @@
{
"root": true,
"extends": "../ui/.eslintrc.json",
"globals": {
"require": true
}
}

162
eslint.config.mjs Normal file
View File

@@ -0,0 +1,162 @@
import jqueryConfig from "eslint-config-jquery";
import globals from "globals";
export default [
{
ignores: [
"dist/**/*",
"!dist/jquery-ui.js",
"!dist/jquery-ui.min.js",
"external/**/*",
"tests/lib/vendor/**/*",
"ui/vendor/**/*"
]
},
{
ignores: [ "dist/**/*" ],
rules: {
...jqueryConfig.rules,
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_"
}
]
}
},
{
files: [ "Gruntfile.js" ],
languageOptions: {
ecmaVersion: "latest",
sourceType: "commonjs",
globals: {
...globals.node
}
},
rules: {
strict: [ "error", "global" ]
}
},
{
files: [ "eslint.config.mjs" ],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: {
...globals.node
}
},
rules: {
strict: [ "error", "global" ]
}
},
// Source, demos
{
files: [ "ui/**/*.js", "demos/**/*.js" ],
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
globals: {
...globals.browser,
...globals.jquery,
define: false,
Globalize: false
}
},
rules: {
strict: [ "error", "function" ],
// The following rule is relaxed due to too many violations:
"no-unused-vars": [
"error",
{
args: "after-used",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_"
}
],
// Too many violations:
camelcase: "off",
"no-nested-ternary": "off"
}
},
{
files: [ "ui/i18n/**/*.js" ],
rules: {
// We want to keep all the strings in separate single lines
"max-len": "off"
}
},
// Dist files
// For dist files, we don't include any jQuery rules on purpose.
// We just want to make sure the files are correct ES5.
{
files: [ "dist/jquery-ui.js", "dist/jquery-ui.min.js" ],
languageOptions: {
ecmaVersion: 5,
sourceType: "script"
},
linterOptions: {
reportUnusedDisableDirectives: "off"
}
},
// Build
{
files: [ "build/**/*.js" ],
languageOptions: {
ecmaVersion: "latest",
sourceType: "commonjs",
globals: {
...globals.node
}
},
rules: {
"no-implicit-globals": "error",
strict: [ "error", "global" ]
}
},
// Demos
{
files: [ "demos/**/*.js" ],
languageOptions: {
globals: {
require: true
}
}
},
// Tests
{
files: [ "tests/**/*.js" ],
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
globals: {
...globals.browser,
...globals.jquery,
define: false,
Globalize: false,
QUnit: false,
require: true,
requirejs: true
}
},
"rules": {
// Too many violations:
"max-len": "off",
"no-unused-vars": "off",
strict: "off" // ideally, `[ "error", "function" ]`
}
}
];

View File

@@ -58,13 +58,14 @@
"@swc/core": "1.11.5",
"commitplease": "3.2.0",
"eslint-config-jquery": "3.0.2",
"globals": "16.0.0",
"grunt": "1.6.1",
"grunt-bowercopy": "1.2.5",
"grunt-compare-size": "0.4.2",
"grunt-contrib-concat": "2.1.0",
"grunt-contrib-csslint": "2.0.0",
"grunt-contrib-requirejs": "1.0.0",
"grunt-eslint": "24.0.1",
"grunt-eslint": "25.0.0",
"grunt-git-authors": "3.2.0",
"grunt-html": "17.1.0",
"jquery-test-runner": "0.2.5",

View File

@@ -1,42 +0,0 @@
{
"root": true,
"extends": "jquery",
"parserOptions": {
"ecmaVersion": 5
},
"env": {
"browser": true,
"jquery": true,
"node": false
},
"rules": {
"strict": [ "error", "function" ],
// The following rule is relaxed due to too many violations:
"no-unused-vars": [ "error", { "vars": "all", "args": "after-used" } ],
// Too many violations:
"camelcase": "off",
"no-nested-ternary": "off"
},
"globals": {
"define": false,
"Globalize": false
},
"overrides": [
{
"files": [ "i18n/**/*.js" ],
"rules": {
// We want to keep all the strings in separate single lines
"max-len": "off"
}
}
]
}

View File

@@ -9,9 +9,7 @@
//>>label: Effects Core
//>>group: Effects
/* eslint-disable max-len */
//>>description: Extends the internal jQuery effects. Includes morphing and easing. Required by all other effects.
/* eslint-enable max-len */
//>>docs: https://api.jqueryui.com/category/effects-core/
//>>demos: https://jqueryui.com/effect/
@@ -320,7 +318,7 @@ if ( $.uiBackCompat === true ) {
try {
// eslint-disable-next-line no-unused-expressions
active.id;
} catch ( e ) {
} catch ( _e ) {
active = document.body;
}

View File

@@ -9,9 +9,7 @@
//>>label: Explode Effect
//>>group: Effects
/* eslint-disable max-len */
//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
/* eslint-enable max-len */
//>>docs: https://api.jqueryui.com/explode-effect/
//>>demos: https://jqueryui.com/effect/

View File

@@ -9,9 +9,7 @@
//>>label: Accordion
//>>group: Widgets
/* eslint-disable max-len */
//>>description: Displays collapsible content panels for presenting information in a limited amount of space.
/* eslint-enable max-len */
//>>docs: https://api.jqueryui.com/accordion/
//>>demos: https://jqueryui.com/accordion/
//>>css.structure: ../../themes/base/core.css

View File

@@ -1,4 +1,4 @@
/* eslint-disable max-len, camelcase */
/* eslint-disable max-len */
/*!
* jQuery UI Datepicker @VERSION
* https://jqueryui.com
@@ -535,7 +535,7 @@ $.extend( Datepicker.prototype, {
_getInst: function( target ) {
try {
return $.data( target, "datepicker" );
} catch ( err ) {
} catch ( _err ) {
throw "Missing instance data for this datepicker";
}
},
@@ -768,7 +768,7 @@ $.extend( Datepicker.prototype, {
$.datepicker._updateAlternate( inst );
$.datepicker._updateDatepicker( inst );
}
} catch ( err ) {
} catch ( _err ) {
}
}
return true;
@@ -1540,7 +1540,7 @@ $.extend( Datepicker.prototype, {
try {
date = this.parseDate( dateFormat, dates, settings ) || defaultDate;
} catch ( event ) {
} catch ( _err ) {
dates = ( noDefault ? "" : dates );
}
inst.selectedDay = date.getDate();
@@ -1569,7 +1569,7 @@ $.extend( Datepicker.prototype, {
try {
return $.datepicker.parseDate( $.datepicker._get( inst, "dateFormat" ),
offset, $.datepicker._getFormatConfig( inst ) );
} catch ( e ) {
} catch ( _e ) {
// Ignore
}

View File

@@ -9,9 +9,7 @@
//>>label: Progressbar
//>>group: Widgets
/* eslint-disable max-len */
//>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
/* eslint-enable max-len */
//>>docs: https://api.jqueryui.com/progressbar/
//>>demos: https://jqueryui.com/progressbar/
//>>css.structure: ../../themes/base/core.css

View File

@@ -104,7 +104,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
el[ scroll ] = 1;
has = ( el[ scroll ] > 0 );
el[ scroll ] = 0;
} catch ( e ) {
} catch ( _e ) {
// `el` might be a string, then setting `scroll` will throw
// an error in strict mode; ignore it.

View File

@@ -9,9 +9,7 @@
//>>label: Selectmenu
//>>group: Widgets
/* eslint-disable max-len */
//>>description: Duplicates and extends the functionality of a native HTML select element, allowing it to be customizable in behavior and appearance far beyond the limitations of a native select.
/* eslint-enable max-len */
//>>docs: https://api.jqueryui.com/selectmenu/
//>>demos: https://jqueryui.com/selectmenu/
//>>css.structure: ../../themes/base/core.css

View File

@@ -73,10 +73,10 @@ $.widget( "ui.tabs", {
// Decoding may throw an error if the URL isn't UTF-8 (#9518)
try {
anchorUrl = decodeURIComponent( anchorUrl );
} catch ( error ) {}
} catch ( _error ) {}
try {
locationUrl = decodeURIComponent( locationUrl );
} catch ( error ) {}
} catch ( _error ) {}
return anchor.hash.length > 1 && anchorUrl === locationUrl;
};