Skip to content

Commit

Permalink
Change more suitable examples in unit-no-unknown doc
Browse files Browse the repository at this point in the history
The `unit-no-unknown` rule handles the `image-set()` function and the `x` unit.
So, specifying `image-set` to the `ignoreFunctions` option doesn't make sense.

Additionally, this change removes duplication in the test for `unit-no-unknown`.

See also the demo:
https://stylelint.io/demo/#N4Igxg9gJgpiBcICGACYAdAdilAjJYA1gOYBOEArplALQCWAtksTPCo8zDQM4wAuACiw4cAcgD0HFt3HcIDLlK4BGAB4A6AFYAHYqJRqANMJESlMuQvpMWNAEwadelA+PZTkmzAvzFXmgDMjrr6QSYAlADcWAC+IIYgAGZ0ADYwAHJICgggMKpZ2mnqYNzc8eAQmMnEORju6CCkFGncDWx1IigNVHR8NJgQNFSEAwDumG0ofE0wJjGx5ZBVdMQAYhCkTHw5mnKY5bDaZYgdXSDcfACeaSl0mHyTDSlIfN4P8SYNF9cwt-c0S2qPD4SGoSFIUEeIGerwuDQWMSAA
  • Loading branch information
ybiquitous committed May 19, 2023
1 parent fd78ef7 commit 0079b71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 53 deletions.
20 changes: 4 additions & 16 deletions lib/rules/unit-no-unknown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,28 @@ a {
Given:

```json
["image-set", "/^my-/", "/^YOUR-/i"]
["foo", "/^my-/", "/^YOUR-/i"]
```

The following patterns are _not_ considered problems:

<!-- prettier-ignore -->
```css
a {
background-image: image-set(
'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
width: foo(1x);
}
```

<!-- prettier-ignore -->
```css
a {
background-image: my-image-set(
'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
width: my-func(1x);
}
```

<!-- prettier-ignore -->
```css
a {
background-image: YoUr-image-set(
'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
width: YoUr-func(1x);
}
```
41 changes: 4 additions & 37 deletions lib/rules/unit-no-unknown/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,50 +597,17 @@ testRule({

testRule({
ruleName,
config: [true, { ignoreFunctions: ['image-set', '/^my-/', '/^YOUR-/i'] }],
config: [true, { ignoreFunctions: ['foo', '/^my-/', '/^YOUR-/i'] }],

accept: [
{
code: "a { background-image: image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }",
code: 'a { width: foo(1x); }',
},
{
code: "a { background-image: my-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }",
code: 'a { width: my-func(1x); }',
},
{
code: "a { background-image: YoUr-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }",
},
],

reject: [
{
code: 'a { margin: calc(10pixels + 1pixels); }',
warnings: [
{
message: messages.rejected('pixels'),
line: 1,
column: 20,
endLine: 1,
endColumn: 26,
},
{
message: messages.rejected('pixels'),
line: 1,
column: 30,
endLine: 1,
endColumn: 36,
},
],
},
],
});

testRule({
ruleName,
config: [true, { ignoreFunctions: [/^my-/] }],

accept: [
{
code: "a { background-image: my-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }",
code: 'a { width: YoUr-func(1x); }',
},
],

Expand Down

0 comments on commit 0079b71

Please sign in to comment.