postcss-modules-local-by-default
Advanced tools
Comparing version 4.1.0 to 4.2.0
{ | ||
"name": "postcss-modules-local-by-default", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A CSS Modules transform to make local scope the default", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -62,3 +62,3 @@ [![Build Status][ci-img]][ci] [![codecov][codecov-img]][codecov] [![npm][npm-img]][npm] | ||
To ignore this rule for a specific selector, add the following comment in front | ||
To ignore this rule for a specific selector, add the a `/* cssmodules-pure-ignore */` comment in front | ||
of the selector: | ||
@@ -73,2 +73,16 @@ | ||
or by adding a `/* cssmodules-pure-no-check */` comment at the top of a file to disable this check for the whole file: | ||
```css | ||
/* cssmodules-pure-no-check */ | ||
:global(#modal-backdrop) { | ||
...; | ||
} | ||
:global(#my-id) { | ||
...; | ||
} | ||
``` | ||
## Building | ||
@@ -104,4 +118,4 @@ | ||
[ci-img]: https://img.shields.io/travis/css-modules/postcss-modules-local-by-default/master.svg?style=flat-square | ||
[ci]: https://travis-ci.org/css-modules/postcss-modules-local-by-default | ||
[ci-img]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml/badge.svg | ||
[ci]: https://github.com/css-modules/postcss-modules-local-by-default/actions/workflows/nodejs.yml | ||
[npm-img]: https://img.shields.io/npm/v/postcss-modules-local-by-default.svg?style=flat-square | ||
@@ -108,0 +122,0 @@ [npm]: https://www.npmjs.com/package/postcss-modules-local-by-default |
@@ -7,6 +7,19 @@ "use strict"; | ||
const IGNORE_MARKER = "cssmodules-pure-ignore"; | ||
const IGNORE_FILE_MARKER = "cssmodules-pure-no-check"; | ||
const IGNORE_NEXT_LINE_MARKER = "cssmodules-pure-ignore"; | ||
const isSpacing = (node) => node.type === "combinator" && node.value === " "; | ||
const isPureCheckDisabled = (root) => { | ||
for (const node of root.nodes) { | ||
if (node.type !== "comment") { | ||
return false; | ||
} | ||
if (node.text.trim().startsWith(IGNORE_FILE_MARKER)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
function getIgnoreComment(node) { | ||
@@ -16,9 +29,7 @@ if (!node.parent) { | ||
} | ||
const indexInParent = node.parent.index(node); | ||
for (let i = indexInParent - 1; i >= 0; i--) { | ||
const prevNode = node.parent.nodes[i]; | ||
if (prevNode.type === "comment") { | ||
if (prevNode.text.trimStart().startsWith(IGNORE_MARKER)) { | ||
if (prevNode.text.trimStart().startsWith(IGNORE_NEXT_LINE_MARKER)) { | ||
return prevNode; | ||
@@ -557,2 +568,3 @@ } | ||
const { icssImports } = extractICSS(root, false); | ||
const enforcePureMode = pureMode && !isPureCheckDisabled(root); | ||
@@ -577,5 +589,4 @@ Object.keys(icssImports).forEach((key) => { | ||
if (globalMatch) { | ||
if (pureMode) { | ||
if (enforcePureMode) { | ||
const ignoreComment = getIgnoreComment(atRule); | ||
if (!ignoreComment) { | ||
@@ -589,3 +600,2 @@ throw atRule.error( | ||
} | ||
atRule.params = globalMatch[1]; | ||
@@ -634,3 +644,7 @@ globalKeyframes = true; | ||
if (pureMode && context.hasPureGlobals && !ignoreComment) { | ||
if ( | ||
enforcePureMode && | ||
context.hasPureGlobals && | ||
!ignoreComment | ||
) { | ||
throw atRule.error( | ||
@@ -686,4 +700,6 @@ 'Selector in at-rule"' + | ||
const ignoreComment = pureMode ? getIgnoreComment(rule) : undefined; | ||
const isNotPure = pureMode && !isPureSelector(context, rule); | ||
const ignoreComment = enforcePureMode | ||
? getIgnoreComment(rule) | ||
: undefined; | ||
const isNotPure = enforcePureMode && !isPureSelector(context, rule); | ||
@@ -690,0 +706,0 @@ if ( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26331
620
124