Skip to content

Commit

Permalink
Add ignoreValues: [] to value-no-vendor-prefix (#3015)
Browse files Browse the repository at this point in the history
* Add ignoreValues to value-no-vendor-prefix

* remove space

* edited ignoreValues to target properties

* added rejection tests

* switched to optionsMatches
  • Loading branch information
Bebersohl authored and CAYdenberg committed Nov 12, 2017
1 parent 12d1698 commit 6abc9ce
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
20 changes: 20 additions & 0 deletions lib/rules/value-no-vendor-prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ a { max-width: max-content; }
```css
a { background: linear-gradient(bottom, #000, #fff); }
```

## Optional secondary options

### `ignoreValues: ["string"]`

Given:

```js
["grab", "max-content"]
```

The following patterns are *not* considered violations:

```css
cursor: -webkit-grab;
```

```css
.foo { max-width: -moz-max-content; }
```
37 changes: 37 additions & 0 deletions lib/rules/value-no-vendor-prefix/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,40 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: [true, { ignoreValues: ["grab", "max-content", "/^linear-/"] }],

accept: [
{
code: "cursor: -webkit-grab;"
},
{
code: ".foo { max-width: -moz-max-content; }"
},
{
code: ".foo { background: -webkit-linear-gradient(bottom, #000, #fff); }"
}
],
reject: [
{
code: ".foo { display: -webkit-flex; }",
message: messages.rejected("-webkit-flex"),
line: 1,
column: 17
},
{
code: ".foo { display: -wEbKiT-fLeX; }",
message: messages.rejected("-wEbKiT-fLeX"),
line: 1,
column: 17
},
{
code: ".foo { display: -WEBKIT-FLEX; }",
message: messages.rejected("-WEBKIT-FLEX"),
line: 1,
column: 17
}
]
});
27 changes: 24 additions & 3 deletions lib/rules/value-no-vendor-prefix/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use strict";

const _ = require("lodash");
const isAutoprefixable = require("../../utils/isAutoprefixable");
const isStandardSyntaxDeclaration = require("../../utils/isStandardSyntaxDeclaration");
const isStandardSyntaxProperty = require("../../utils/isStandardSyntaxProperty");
const optionsMatches = require("../../utils/optionsMatches");
const postcss = require("postcss");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
const styleSearch = require("style-search");
Expand All @@ -16,9 +19,21 @@ const messages = ruleMessages(ruleName, {

const valuePrefixes = ["-webkit-", "-moz-", "-ms-", "-o-"];

const rule = function(actual) {
const rule = function(actual, options) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual });
const validOptions = validateOptions(
result,
ruleName,
{ actual },
{
optional: true,
actual: options,
possible: {
ignoreValues: [_.isString]
}
}
);

if (!validOptions) {
return;
}
Expand All @@ -33,7 +48,13 @@ const rule = function(actual) {
}

const prop = decl.prop,
value = decl.value;
value = decl.value,
unprefixedValue = postcss.vendor.unprefixed(value);

//return early if value is to be ignored
if (optionsMatches(options, "ignoreValues", unprefixedValue)) {
return;
}

// Search the full declaration in order to get an accurate index

Expand Down

0 comments on commit 6abc9ce

Please sign in to comment.