Skip to content

Commit

Permalink
Add ignoreProperties option to value-keyword-case rule (#2937)
Browse files Browse the repository at this point in the history
  • Loading branch information
Biliana Valeva authored and jeddy3 committed Oct 5, 2017
1 parent fe071b6 commit 3457b84
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/rules/value-keyword-case/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,64 @@ a {
}
```

### `ignoreProperties: ["/regex/", "non-regex"]`

Ignore case of the values of the listed properties.

For example, with `"lower"`.

```js
["/^(b|B)ackground$/", "display"]
```

The following patterns are considered violations:

```css
a {
text-align: LEFT;
}
```

```css
a {
text-align: Left;
}
```

The following patterns are *not* considered violations:

```css
a {
display: bloCk;
}
```

```css
a {
display: BloCk;
}
```

```css
a {
display: BLOCK;
}
```

```css
a {
display: block;
}
```

```css
a {
background: Red;
}
```

```css
a {
Background: deepPink;
}
```
88 changes: 88 additions & 0 deletions lib/rules/value-keyword-case/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1938,3 +1938,91 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: ["lower", { ignoreProperties: ["display", "/^(b|B)ackground$/"] }],

accept: [
{
code: "a { display: bloCk; }"
},
{
code: "a { display: BloCk; }"
},
{
code: "a { display: BLOCK; }"
},
{
code: "a { display: block; }"
},
{
code: "a { background: Red; }"
},
{
code: "a { Background: deepPink; }"
}
],

reject: [
{
code: "a { text-align: LEFT; }",
message: messages.expected("LEFT", "left"),
description:
"Rejected because property doesn't match any property in ignoreProperties list"
},
{
code: "a { text-align: Left; }",
message: messages.expected("Left", "left"),
description:
"Rejected because property doesn't match any property in ignoreProperties list"
}
]
});

testRule(rule, {
ruleName,
config: ["upper", { ignoreProperties: ["display", "/^(b|B)ackground$/"] }],

accept: [
{
code: "a { display: bloCk; }"
},
{
code: "a { display: BloCk; }"
},
{
code: "a { display: BLOCK; }"
},
{
code: "a { display: block; }"
},
{
code: "a { background: Red; }"
},
{
code: "a { Background: deepPink; }"
}
],

reject: [
{
code: "a { text-align: left; }",
message: messages.expected("left", "LEFT"),
description:
"Rejected because property doesn't match any property in ignoreProperties list"
},
{
code: "a { text-align: LeFt; }",
message: messages.expected("LeFt", "LEFT"),
description:
"Rejected because property doesn't match any property in ignoreProperties list"
},
{
code: "a { text-align: Left; }",
message: messages.expected("Left", "LEFT"),
description:
"Rejected because property doesn't match any property in ignoreProperties list"
}
]
});
9 changes: 9 additions & 0 deletions lib/rules/value-keyword-case/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const rule = function(expectation, options) {
{
actual: options,
possible: {
ignoreProperties: [_.isString],
ignoreKeywords: [_.isString]
},
optional: true
Expand Down Expand Up @@ -156,6 +157,7 @@ const rule = function(expectation, options) {
}

const ignoreKeywords = (options && options.ignoreKeywords) || [];
const ignoreProperties = (options && options.ignoreProperties) || [];

if (
ignoreKeywords.length > 0 &&
Expand All @@ -164,6 +166,13 @@ const rule = function(expectation, options) {
return;
}

if (
ignoreProperties.length > 0 &&
matchesStringOrRegExp(prop, ignoreProperties)
) {
return;
}

const keywordLowerCase = keyword.toLocaleLowerCase();
let expectedKeyword = null;

Expand Down

0 comments on commit 3457b84

Please sign in to comment.