From fd1ac773400e55b47d609415e48a810ca52896c9 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Tue, 19 Nov 2024 15:24:31 +0000 Subject: [PATCH] use fewer negative lookahead assertions in regular expressions (#4209) --- src/negative_test/stylelintrc/objectRule.json | 15 ++++++ src/schemas/json/package.json | 2 +- src/schemas/json/stylelintrc.json | 46 +++++++------------ src/test/stylelintrc/objectRule.json | 15 ++++++ 4 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 src/negative_test/stylelintrc/objectRule.json create mode 100644 src/test/stylelintrc/objectRule.json diff --git a/src/negative_test/stylelintrc/objectRule.json b/src/negative_test/stylelintrc/objectRule.json new file mode 100644 index 000000000000..128624ea31f5 --- /dev/null +++ b/src/negative_test/stylelintrc/objectRule.json @@ -0,0 +1,15 @@ +{ + "rules": { + "declaration-property-unit-whitelist": [ + { + "message": [] + }, + { + "/^animation/": "s", + "font-size": "em", + "line-height": [], + "message": [] + } + ] + } +} diff --git a/src/schemas/json/package.json b/src/schemas/json/package.json index 1c419ca427f6..79d2457276e0 100644 --- a/src/schemas/json/package.json +++ b/src/schemas/json/package.json @@ -139,7 +139,7 @@ } }, "patternProperties": { - "^(?![\\.0-9]).": { + "^[^.0-9]+$": { "$ref": "#/definitions/packageExportsEntryOrFallback", "description": "The module path that is resolved when this environment matches the property name." } diff --git a/src/schemas/json/stylelintrc.json b/src/schemas/json/stylelintrc.json index b2aa1a1a1c41..abbabbafd6c9 100644 --- a/src/schemas/json/stylelintrc.json +++ b/src/schemas/json/stylelintrc.json @@ -193,8 +193,7 @@ "type": "null" }, { - "type": "boolean", - "enum": [true, []] + "type": "boolean" }, { "type": "array", @@ -205,8 +204,7 @@ "type": ["boolean", "object"], "anyOf": [ { - "type": "boolean", - "enum": [true, {}] + "type": "boolean" }, { "$ref": "#/definitions/coreRule" @@ -217,6 +215,7 @@ ] }, "coreRule": { + "type": "object", "properties": { "disableFix": { "type": "boolean" @@ -427,48 +426,36 @@ ] }, "objectRule": { - "type": ["null", "object", "array"], "oneOf": [ { "type": "null" }, { "type": "object", - "patternProperties": { - ".*": { - "$ref": "#/definitions/simpleArrayStringRule" - } + "additionalProperties": { + "$ref": "#/definitions/simpleStringOrArrayStringRule" } }, { "type": "array", "minItems": 2, "maxItems": 2, - "uniqueItems": true, - "items": { - "type": ["object"], - "anyOf": [ - { - "type": "object", - "allOf": [ - { - "$ref": "#/definitions/coreRule" - } - ], - "patternProperties": { - "^((?!message|severity).)*$": { - "$ref": "#/definitions/simpleArrayStringRule" - } - } + "items": [ + { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/simpleStringOrArrayStringRule" } - ] - } + }, + { + "$ref": "#/definitions/coreRule" + } + ] } ] }, "simpleArrayStringRule": { "type": "array", - "minItems": 1, "uniqueItems": true, "items": { "type": "string" @@ -572,8 +559,7 @@ "type": ["string", "object"], "anyOf": [ { - "type": "string", - "enum": [{}] + "type": "string" }, { "$ref": "#/definitions/coreRule" diff --git a/src/test/stylelintrc/objectRule.json b/src/test/stylelintrc/objectRule.json new file mode 100644 index 000000000000..b9ba39aa9fdd --- /dev/null +++ b/src/test/stylelintrc/objectRule.json @@ -0,0 +1,15 @@ +{ + "rules": { + "declaration-property-unit-whitelist": [ + { + "/^animation/": "s", + "/message/": "blah", + "font-size": "em", + "line-height": [] + }, + { + "message": "it failed!" + } + ] + } +}