From ec02d4f4c695e990e5827a7e224bf9756dac9846 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:31:25 +0000 Subject: [PATCH] chore: enable eslint recommended config Enables the recommended lint rules from `eslint`. Also deletes `getEnumerableProperties.js` which is no longer referenced. --- eslint.config.js | 14 +++++++++ lib/chai/core/assertions.js | 20 ++++++------ lib/chai/interface/assert.js | 37 ++++++++++++----------- lib/chai/utils/getEnumerableProperties.js | 25 --------------- lib/chai/utils/proxify.js | 10 +++--- package-lock.json | 20 +++++++++--- package.json | 1 + 7 files changed, 66 insertions(+), 61 deletions(-) delete mode 100644 lib/chai/utils/getEnumerableProperties.js diff --git a/eslint.config.js b/eslint.config.js index c9017f6c..22339fce 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,12 +1,26 @@ import jsdoc from "eslint-plugin-jsdoc"; +import eslintjs from "@eslint/js"; + +const {configs: eslintConfigs} = eslintjs; export default [ jsdoc.configs["flat/recommended"], + eslintConfigs["recommended"], { + languageOptions: { + // if we ever use more globals than this, pull in the `globals` package + globals: { + console: false + } + }, rules: { "jsdoc/require-param-description": "off", "jsdoc/require-returns-description": "off", "jsdoc/tag-lines": ["error", "any", { startLines: 1 }], + "no-unused-vars": ["error", { + argsIgnorePattern: "^_", + caughtErrorsIgnorePattern: "^_" + }] }, }, ]; diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index e2971726..792eeff1 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -727,7 +727,7 @@ Assertion.addProperty('callable', function () { const negate = flag(this, 'negate'); const assertionMessage = negate ? - `${msg}expected ${_.inspect(val)} not to be a callable function` : + `${msg}expected ${_.inspect(val)} not to be a callable function` : `${msg}expected ${_.inspect(val)} to be a callable function`; const isCallable = ['Function', 'AsyncFunction', 'GeneratorFunction', 'AsyncGeneratorFunction'].includes(_.type(val)); @@ -1424,7 +1424,7 @@ function assertBelow (n, msg) { if (doLength && objType !== 'map' && objType !== 'set') { new Assertion(obj, flagMsg, ssfi, true).to.have.property('length'); } - + if (!doLength && (objType === 'date' && nType !== 'date')) { errorMessage = msgPrefix + 'the argument to below must be a date'; } else if (!_.isNumeric(n) && (doLength || _.isNumeric(obj))) { @@ -1744,7 +1744,7 @@ function assertInstanceOf (constructor, msg) { , 'expected #{this} to be an instance of ' + name , 'expected #{this} to not be an instance of ' + name ); -}; +} Assertion.addMethod('instanceof', assertInstanceOf); Assertion.addMethod('instanceOf', assertInstanceOf); @@ -1951,11 +1951,11 @@ Assertion.addMethod('property', assertProperty); /** * - * @param {unknown} name - * @param {unknown} value - * @param {string} msg + * @param {unknown} _name + * @param {unknown} _value + * @param {string} _msg */ -function assertOwnProperty (name, value, msg) { +function assertOwnProperty (_name, _value, _msg) { flag(this, 'own', true); assertProperty.apply(this, arguments); } @@ -2409,7 +2409,7 @@ function assertKeys (keys) { actual = []; // Map and Set '.keys' aren't supported in IE 11. Therefore, use .forEach. - obj.forEach(function (val, key) { actual.push(key) }); + obj.forEach(function (_val, key) { actual.push(key) }); if (keysType !== 'Array') { keys = Array.prototype.slice.call(arguments); @@ -2808,7 +2808,7 @@ function assertThrows (errorLike, errMsgMatcher, msg) { } flag(this, 'object', caughtErr); -}; +} Assertion.addMethod('throw', assertThrows); Assertion.addMethod('throws', assertThrows); @@ -3923,7 +3923,7 @@ Assertion.addProperty('frozen', function() { * @namespace BDD * @public */ -Assertion.addProperty('finite', function(msg) { +Assertion.addProperty('finite', function() { var obj = flag(this, 'object'); this.assert( diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 721ec2a3..80989212 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -713,7 +713,7 @@ assert.isNotNumber = function (val, msg) { * * var cups = 2; * assert.isNumeric(cups, 'how many cups'); - * + * * var cups = 10n; * assert.isNumeric(cups, 'how many cups'); * @@ -3031,21 +3031,22 @@ assert.isNotEmpty = function(val, msg) { * @param {unknown} as * @returns {unknown} */ -(function alias(name, as){ +const aliases = [ + ['isOk', 'ok'], + ['isNotOk', 'notOk'], + ['throws', 'throw'], + ['throws', 'Throw'], + ['isExtensible', 'extensible'], + ['isNotExtensible', 'notExtensible'], + ['isSealed', 'sealed'], + ['isNotSealed', 'notSealed'], + ['isFrozen', 'frozen'], + ['isNotFrozen', 'notFrozen'], + ['isEmpty', 'empty'], + ['isNotEmpty', 'notEmpty'], + ['isCallable', 'isFunction'], + ['isNotCallable', 'isNotFunction'] +]; +for (const [name, as] of aliases) { assert[as] = assert[name]; - return alias; -}) -('isOk', 'ok') -('isNotOk', 'notOk') -('throws', 'throw') -('throws', 'Throw') -('isExtensible', 'extensible') -('isNotExtensible', 'notExtensible') -('isSealed', 'sealed') -('isNotSealed', 'notSealed') -('isFrozen', 'frozen') -('isNotFrozen', 'notFrozen') -('isEmpty', 'empty') -('isNotEmpty', 'notEmpty') -('isCallable', 'isFunction') -('isNotCallable', 'isNotFunction') +} diff --git a/lib/chai/utils/getEnumerableProperties.js b/lib/chai/utils/getEnumerableProperties.js deleted file mode 100644 index 46960524..00000000 --- a/lib/chai/utils/getEnumerableProperties.js +++ /dev/null @@ -1,25 +0,0 @@ -/*! - * Chai - getEnumerableProperties utility - * Copyright(c) 2012-2014 Jake Luer - * MIT Licensed - */ - -/** - * ### .getEnumerableProperties(object) - * - * This allows the retrieval of enumerable property names of an object, - * inherited or not. - * - * @param {object} object - * @returns {Array} - * @namespace Utils - * @name getEnumerableProperties - * @public - */ -module.exports = function getEnumerableProperties(object) { - var result = []; - for (var name in object) { - result.push(name); - } - return result; -}; diff --git a/lib/chai/utils/proxify.js b/lib/chai/utils/proxify.js index 3789892f..d02d969d 100644 --- a/lib/chai/utils/proxify.js +++ b/lib/chai/utils/proxify.js @@ -56,6 +56,8 @@ export function proxify(obj ,nonChainableMethodName) { var suggestionDistance = 4; getProperties(target).forEach(function(prop) { if ( + // we actually mean to check `Object.prototype` here + // eslint-disable-next-line no-prototype-builtins !Object.prototype.hasOwnProperty(prop) && builtins.indexOf(prop) === -1 ) { @@ -119,17 +121,17 @@ function stringDistanceCapped(strA, strB, cap) { // `memo` is a two-dimensional array containing distances. // memo[i][j] is the distance between strA.slice(0, i) and // strB.slice(0, j). - for (var i = 0; i <= strA.length; i++) { + for (let i = 0; i <= strA.length; i++) { memo[i] = Array(strB.length + 1).fill(0); memo[i][0] = i; } - for (var j = 0; j < strB.length; j++) { + for (let j = 0; j < strB.length; j++) { memo[0][j] = j; } - for (var i = 1; i <= strA.length; i++) { + for (let i = 1; i <= strA.length; i++) { var ch = strA.charCodeAt(i - 1); - for (var j = 1; j <= strB.length; j++) { + for (let j = 1; j <= strB.length; j++) { if (Math.abs(i - j) >= cap) { memo[i][j] = cap; continue; diff --git a/package-lock.json b/package-lock.json index 66e90ee5..77ff41f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "pathval": "^2.0.0" }, "devDependencies": { + "@eslint/js": "^9.17.0", "@rollup/plugin-commonjs": "^25.0.7", "@web/dev-server-rollup": "^0.6.1", "@web/test-runner": "^0.18.0", @@ -548,12 +549,13 @@ } }, "node_modules/@eslint/js": { - "version": "8.56.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", - "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==", + "version": "9.17.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.17.0.tgz", + "integrity": "sha512-Sxc4hqcs1kTu0iID3kcZDW3JHq2a77HO9P8CP6YEA/FpH3Ll8UXE2r/86Rz9YJLKme39S9vU5OWNjC6Xl0Cr3w==", "dev": true, + "license": "MIT", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@humanwhocodes/config-array": { @@ -2998,6 +3000,16 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/@eslint/js": { + "version": "8.56.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.56.0.tgz", + "integrity": "sha512-gMsVel9D7f2HLkBma9VbtzZRehRogVRfbr++f06nL2vnCGCNlzOD+/MUov/F4p8myyAHspEhVobgjpX64q5m6A==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/eslint/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", diff --git a/package.json b/package.json index cc8fb27b..ff0a561d 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "pathval": "^2.0.0" }, "devDependencies": { + "@eslint/js": "^9.17.0", "@rollup/plugin-commonjs": "^25.0.7", "@web/dev-server-rollup": "^0.6.1", "@web/test-runner": "^0.18.0",