Skip to content

Commit

Permalink
hide nesting warnings in root or @layer nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Jan 3, 2023
1 parent 3a8e95d commit 0b24530
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/detectNesting.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
function isRoot(node) {
return node.type === 'root'
}

function isAtLayer(node) {
return node.type === 'atrule' && node.name === 'layer'
}

export default function (_context) {
return (root, result) => {
let found = false

root.walkAtRules('tailwind', (node) => {
if (found) return false

if (node.parent && node.parent.type !== 'root') {
if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
found = true
node.warn(
result,
Expand Down
25 changes: 25 additions & 0 deletions tests/detect-nesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ it('should warn when we detect nested css', () => {
})
})

it('should not warn when we detect nested css inside css @layer rules', () => {
let config = {
content: [{ raw: html`<div class="underline"></div>` }],
}

let input = css`
@layer tw-base, tw-components, tw-utilities;
@layer tw-utilities {
@tailwind utilities;
}
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@layer tw-base, tw-components, tw-utilities;
@layer tw-utilities {
.underline {
text-decoration-line: underline;
}
}
`)
expect(result.messages).toHaveLength(0)
})
})

it('should warn when we detect namespaced @tailwind at rules', () => {
let config = {
content: [{ raw: html`<div class="text-center"></div>` }],
Expand Down

0 comments on commit 0b24530

Please sign in to comment.