-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: detect duplicate test cases (#17955)
* feat!: detect duplicate test cases Part of: https://github.com/eslint/rfcs/tree/main/designs/2021-stricter-rule-test-validation#disallow-identical-test-cases * remove some duplicate test cases * add more tests * better detection of duplicate test cases * fix more rule tests * Update tests/lib/rules/no-misleading-character-class.js * add function to check if an object is serializable * tweak name * add to migration guide * tweak wording * add test cases * remove lodash.isplainobject * rename obj to val * add obj check
- Loading branch information
Showing
12 changed files
with
398 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @fileoverview Serialization utils. | ||
* @author Bryan Mishkin | ||
*/ | ||
|
||
"use strict"; | ||
|
||
/** | ||
* Check if a value is a primitive or plain object created by the Object constructor. | ||
* @param {any} val the value to check | ||
* @returns {boolean} true if so | ||
* @private | ||
*/ | ||
function isSerializablePrimitiveOrPlainObject(val) { | ||
return ( | ||
val === null || | ||
typeof val === "string" || | ||
typeof val === "boolean" || | ||
typeof val === "number" || | ||
(typeof val === "object" && val.constructor === Object) || | ||
Array.isArray(val) | ||
); | ||
} | ||
|
||
/** | ||
* Check if a value is serializable. | ||
* Functions or objects like RegExp cannot be serialized by JSON.stringify(). | ||
* Inspired by: https://stackoverflow.com/questions/30579940/reliable-way-to-check-if-objects-is-serializable-in-javascript | ||
* @param {any} val the value | ||
* @returns {boolean} true if the value is serializable | ||
*/ | ||
function isSerializable(val) { | ||
if (!isSerializablePrimitiveOrPlainObject(val)) { | ||
return false; | ||
} | ||
if (typeof val === "object") { | ||
for (const property in val) { | ||
if (Object.hasOwn(val, property)) { | ||
if (!isSerializablePrimitiveOrPlainObject(val[property])) { | ||
return false; | ||
} | ||
if (typeof val[property] === "object") { | ||
if (!isSerializable(val[property])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
module.exports = { | ||
isSerializable | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.