From 79e9febf02c125aaaa8f18e0ab9ffbc023c6fa00 Mon Sep 17 00:00:00 2001 From: Masafumi Koba <473530+ybiquitous@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:36:26 +0900 Subject: [PATCH] Fix `max-nesting-depth` error for at-rules in Sass syntax --- .changeset/cyan-dingos-own.md | 5 +++++ lib/rules/max-nesting-depth/__tests__/index.js | 17 +++++++++++++++++ lib/rules/max-nesting-depth/index.js | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/cyan-dingos-own.md diff --git a/.changeset/cyan-dingos-own.md b/.changeset/cyan-dingos-own.md new file mode 100644 index 0000000000..f4e04ab8e7 --- /dev/null +++ b/.changeset/cyan-dingos-own.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `max-nesting-depth` error for at-rules in Sass syntax diff --git a/lib/rules/max-nesting-depth/__tests__/index.js b/lib/rules/max-nesting-depth/__tests__/index.js index 70ac1f909c..30a7629d74 100644 --- a/lib/rules/max-nesting-depth/__tests__/index.js +++ b/lib/rules/max-nesting-depth/__tests__/index.js @@ -1,5 +1,7 @@ 'use strict'; +const { stripIndent } = require('common-tags'); + const { messages, ruleName } = require('..'); testRule({ @@ -281,3 +283,18 @@ testRule({ }, ], }); + +testRule({ + ruleName, + config: [1], + customSyntax: 'postcss-sass', + + accept: [ + { + code: stripIndent` + @media print + color: white + `, + }, + ], +}); diff --git a/lib/rules/max-nesting-depth/index.js b/lib/rules/max-nesting-depth/index.js index d33df14b07..a1211c94f9 100644 --- a/lib/rules/max-nesting-depth/index.js +++ b/lib/rules/max-nesting-depth/index.js @@ -90,8 +90,8 @@ const rule = (primary, secondaryOptions) => { function nestingDepth(node, level) { const parent = node.parent; - if (parent == null) { - throw new Error('The parent node must exist'); + if (!parent) { + return 0; } if (isIgnoreAtRule(parent)) {