Permalink
Browse files

Added: `warnings` option allows you to disable warnings.

1 parent 6ccf4a9 commit ae55769f675d20172d9727b62c098f21613306cf @MoOx MoOx committed Jul 21, 2015
Showing with 61 additions and 17 deletions.
  1. +5 −0 CHANGELOG.md
  2. +29 −9 README.md
  3. +9 −4 index.js
  4. +1 −1 package.json
  5. +17 −3 test/index.js
View
@@ -1,3 +1,8 @@
+# 4.2.0 - 2015-07-21
+
+- Added: `warnings` option allows you to disable warnings.
+([cssnext#186](https://github.com/cssnext/cssnext/issues/186))
+
# 4.1.0 - 2015-07-14
- Added: plugin now returns itself in order to expose a `setVariables` function
View
@@ -79,13 +79,17 @@ Checkout [tests](test) for more.
### Options
-#### `strict` (default: `true`)
+#### `strict`
+
+Default: `true`
Per specifications, all fallbacks should be added since we can't verify if a
computed value is valid or not.
This option allows you to avoid adding too many fallback values in your CSS.
-#### `preserve` (default: `false`)
+#### `preserve`
+
+Default: `false`
Allows you to preserve custom properties & var() usage in output.
@@ -96,27 +100,43 @@ var out = postcss()
.css
```
-You can also set `preserve: "computed"` to get computed resolved custom properties in the final output.
+You can also set `preserve: "computed"` to get computed resolved custom
+properties in the final output.
Handy to make them available to your JavaScript.
-#### `variables` (default: `{}`)
+#### `variables`
-Allows you to pass an object of variables for `:root`. These definitions will override any that exist in the CSS.
+Default: `{}`
+
+Allows you to pass an object of variables for `:root`. These definitions will
+override any that exist in the CSS.
The keys are automatically prefixed with the CSS `--` to make it easier to share
variables in your codebase.
-#### `appendVariables` (default: `false`)
+#### `appendVariables`
+
+Default: `false`
+
+If `preserve` is set to `true` (or `"computed"`), allows you to append your
+variables at the end of your CSS.
+
+#### `warnings`
+
+Default: `true`
+Type: `Boolean|Object`
-If `preserve` is set to `true` (or `"computed"`), allows you to append your variables at the end of your CSS.
+Allows you to enable/disable warnings. If true, will enable all warnings.
+For now, it only allow to disable messages about custom properties definition
+not scoped in a `:root` selector.
---
## Contributing
-Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
+Fork, work on a branch, install dependencies & run tests before submitting a PR.
```console
-$ git clone https://github.com/postcss/postcss-custom-properties.git
+$ git clone https://github.com/YOU/postcss-custom-properties.git
$ git checkout -b patch-1
$ npm install
$ npm test
View
@@ -156,6 +156,7 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
}
function plugin(style, result) {
+ var warnings = options.warnings === undefined ? true : options.warnings
var variables = prefixVariables(options.variables)
var strict = options.strict === undefined ? true : options.strict
var appendVariables = options.appendVariables
@@ -169,13 +170,17 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
// only variables declared for `:root` are supported for now
if (
- rule.selectors.length !== 1 ||
- rule.selectors[0] !== ":root" ||
- rule.parent.type !== "root"
+ rule.selectors.length !== 1 ||
+ rule.selectors[0] !== ":root" ||
+ rule.parent.type !== "root"
) {
rule.each(function(decl) {
var prop = decl.prop
- if (prop && prop.indexOf(VAR_PROP_IDENTIFIER) === 0) {
+ if (
+ warnings &&
+ prop &&
+ prop.indexOf(VAR_PROP_IDENTIFIER) === 0
+ ) {
result.warn(
"Custom property ignored: not scoped to the top-level :root " +
"element (" + rule.selectors + " { ... " + prop + ": ... })" +
View
@@ -1,6 +1,6 @@
{
"name": "postcss-custom-properties",
- "version": "4.1.0",
+ "version": "4.2.0",
"description": "PostCSS plugin to polyfill W3C CSS Custom Properties for cascading variables",
"keywords": [
"css",
View
@@ -63,7 +63,7 @@ test(
function(t) {
var result = compareFixtures(t, "substitution-undefined")
t.equal(
- result.warnings()[0].text,
+ result.messages[0].text,
"variable '--test' is undefined and used without a fallback",
"should add a warning for undefined variable"
)
@@ -74,12 +74,26 @@ test(
test("substitutes defined variables in `:root` only", function(t) {
var result = compareFixtures(t, "substitution-defined")
t.ok(
- result.warnings()[0].text.match(/^Custom property ignored/),
+ result.messages[0].text.match(/^Custom property ignored/),
"should add a warning for non root custom properties"
)
t.end()
})
+test("allow to hide warnings", function(t) {
+ var result = compareFixtures(
+ t,
+ "substitution-defined",
+ {warnings: false}
+ )
+ t.equal(
+ result.messages.length,
+ 0,
+ "should not add warnings if option set to false"
+ )
+ t.end()
+})
+
test(
"accepts variables defined from JavaScript, and overrides local definitions",
function(t) {
@@ -181,7 +195,7 @@ test("circular variable references", function(t) {
compareFixtures(t, "self-reference")
var result = compareFixtures(t, "circular-reference")
t.equal(
- result.warnings()[0].text,
+ result.messages[0].text,
"Circular variable reference: --color",
"should add a warning for circular reference"
)

0 comments on commit ae55769

Please sign in to comment.