Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ignoreSelectors: [] to selector-no-vendor-prefix #3748

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/rules/selector-no-vendor-prefix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ input::placeholder {}
```css
:full-screen a {}
```

## Optional secondary options

### `ignoreProperties: ["/regex/", "non-regex"]`
Bilie marked this conversation as resolved.
Show resolved Hide resolved

Ignore vendor prefixes for selectors.

Given:

```js
["::-webkit-input-placeholder", "/-moz-.*/"]
```

The following patterns are not considered violations:

```css
input::-webkit-input-placeholder {
color: pink;
}

input::-moz-placeholder {
color: pink;
}
```
24 changes: 24 additions & 0 deletions lib/rules/selector-no-vendor-prefix/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,27 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: [
true,
{ ignoreProperties: ["::-webkit-input-placeholder", "/-moz-.*/"] }
Bilie marked this conversation as resolved.
Show resolved Hide resolved
],

accept: [
{
code: "input::-webkit-input-placeholder { color: pink; }"
},
{
code: "input::-moz-placeholder { color: pink; }"
}
],

reject: [
{
code: "input:-ms-input-placeholder { color: pink; }",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might need to a pseudo-element to appease appveyor: input::-ms-input-placeholder.

message: messages.rejected(":-ms-input-placeholder")
}
]
});
21 changes: 19 additions & 2 deletions lib/rules/selector-no-vendor-prefix/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use strict";

const _ = require("lodash");
const isAutoprefixable = require("../../utils/isAutoprefixable");
const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule");
const isStandardSyntaxSelector = require("../../utils/isStandardSyntaxSelector");
const optionsMatches = require("../../utils/optionsMatches");
const parseSelector = require("../../utils/parseSelector");
const report = require("../../utils/report");
const ruleMessages = require("../../utils/ruleMessages");
Expand All @@ -14,9 +16,20 @@ const messages = ruleMessages(ruleName, {
rejected: selector => `Unexpected vendor-prefix "${selector}"`
});

const rule = function(actual) {
const rule = function(actual, options) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual });
const validOptions = validateOptions(
result,
ruleName,
{ actual },
{
actual: options,
possible: {
ignoreProperties: [_.isString]
Bilie marked this conversation as resolved.
Show resolved Hide resolved
},
optional: true
}
);

if (!validOptions) {
return;
Expand All @@ -36,6 +49,10 @@ const rule = function(actual) {
parseSelector(selector, result, rule, selectorTree => {
selectorTree.walkPseudos(pseudoNode => {
if (isAutoprefixable.selector(pseudoNode.value)) {
if (optionsMatches(options, "ignoreProperties", pseudoNode.value)) {
Bilie marked this conversation as resolved.
Show resolved Hide resolved
return;
}

report({
result,
ruleName,
Expand Down