From a2260ae850b992e049719e571c9310e111df122b Mon Sep 17 00:00:00 2001 From: firefoxic Date: Fri, 17 May 2024 22:49:08 +0300 Subject: [PATCH] Disallow unknown custom media queries --- CHANGELOG.md | 4 +++ stylelint.config.js | 1 + test/no-unknown-custom-media.js | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 test/no-unknown-custom-media.js diff --git a/CHANGELOG.md b/CHANGELOG.md index a0300c2..d4cd434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and  ## [Unreleased] +### Changed + +- The custom media queries should now be defined within the same source. + ### Fixed - Zero length value no longer requires no units in all cases. diff --git a/stylelint.config.js b/stylelint.config.js index e0e8011..940841e 100644 --- a/stylelint.config.js +++ b/stylelint.config.js @@ -71,6 +71,7 @@ export default { "no-invalid-double-slash-comments": true, "no-invalid-position-at-import-rule": true, "no-irregular-whitespace": true, + "no-unknown-custom-media": true, "number-max-precision": [ 3, { diff --git a/test/no-unknown-custom-media.js b/test/no-unknown-custom-media.js new file mode 100644 index 0000000..12689f7 --- /dev/null +++ b/test/no-unknown-custom-media.js @@ -0,0 +1,43 @@ +import { testRule } from "../utils/testRule.js" + +let rule = `no-unknown-custom-media` + +let code = ` +@custom-media --any-valid (width >= 40rem); + +@media (--any-valid), (height < 40rem) {} + +@media (--another-valid) {} + +@custom-media --another-valid (width >= 60rem); + +@media (--invalid) {} + +@media (--invalid), (height < 40rem) {} +` + +testRule({ + description: `Custom media queries should be known`, + rule, + code, + expectedWarnings: [ + { + line: 10, + column: 9, + endLine: 10, + endColumn: 18, + rule, + severity: `error`, + text: `Unexpected unknown custom media "--invalid" (${rule})`, + }, + { + line: 12, + column: 9, + endLine: 12, + endColumn: 18, + rule, + severity: `error`, + text: `Unexpected unknown custom media "--invalid" (${rule})`, + }, + ], +})