Warn when nesting is detected (#5489)

* warn when nesting is detected

* add todo for improving warning messages
This commit is contained in:
Robin Malfait 2021-09-16 14:13:45 +02:00 • committed by GitHub
parent c64bc1f652
commit 14d49a9fd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 0 deletions

20
src/lib/detectNesting.js Normal file
View file

@ -0,0 +1,20 @@
export default function (_context) {
return (root, result) => {
let found = false
root.walkRules((rule) => {
if (found) return false
rule.walkRules((nestedRule) => {
found = true
nestedRule.warn(
result,
// TODO: Improve this warning message
'Nested CSS detected, checkout the docs on how to support nesting: https://tailwindcss.com/docs/using-with-preprocessors#nesting'
)
return false
})
})
}
}

View file

@ -5,6 +5,7 @@ import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
import substituteScreenAtRules from './lib/substituteScreenAtRules'
import resolveDefaultsAtRules from './lib/resolveDefaultsAtRules'
import collapseAdjacentRules from './lib/collapseAdjacentRules'
import detectNesting from './lib/detectNesting'
import { createContext } from './lib/setupContextUtils'
export default function processTailwindFeatures(setupContext) {
@ -31,6 +32,7 @@ export default function processTailwindFeatures(setupContext) {
)
}
detectNesting(context)(root, result)
expandTailwindAtRules(context)(root, result)
expandApplyAtRules(context)(root, result)
evaluateTailwindFunctions(context)(root, result)