Skip to content

Commit

Permalink
issue-813 -- Updates documentation for new and updated rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
danwaz committed Aug 25, 2016
1 parent 75ac1f0 commit 45074f7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
37 changes: 37 additions & 0 deletions docs/rules/no-domains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# No Domains

Rule `no-domains` will enforce that domains are not used within urls.

## Examples

When enabled, the following are allowed:

```scss
.foo {
background-image: url('/img/bar.png');
}

.foo {
background-image: url('img/bar.png');
}

.foo {
background-image: url('bar.png');
}
```

When enabled, the following are disallowed:

```scss
.foo {
background-image: url('https://foo.com/img/bar.png');
}

.foo {
background-image: url('http://foo.com/img/bar.png');
}

.foo {
background-image: url('//foo.com/img/bar.png');
}
```
42 changes: 40 additions & 2 deletions docs/rules/no-url-protocols.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

Rule `no-url-protocols` will enforce that protocols and domains are not used within urls.

## Options

* `protocol-relative-urls`: `true`/`false` (defaults to `false`)

## Examples

When enabled, the following are allowed:
### `protocol-relative-urls`

When `protocol-relative-urls: false`, the following are allowed:

```scss
.foo {
Expand All @@ -20,7 +26,7 @@ When enabled, the following are allowed:
}
```

When enabled, the following are disallowed:
When `protocol-relative-urls: false`, the following are disallowed:

```scss
.foo {
Expand All @@ -35,3 +41,35 @@ When enabled, the following are disallowed:
background-image: url('//foo.com/img/bar.png');
}
```

When `protocol-relative-urls: true`, the following are allowed:

```scss
.foo {
background-image: url('//foo.com/img/bar.png');
}

.foo {
background-image: url('/img/bar.png');
}

.foo {
background-image: url('img/bar.png');
}

.foo {
background-image: url('bar.png');
}
```

When `protocol-relative-urls: true`, the following are disallowed:

```scss
.foo {
background-image: url('https://foo.com/img/bar.png');
}

.foo {
background-image: url('http://foo.com/img/bar.png');
}
```
10 changes: 5 additions & 5 deletions lib/rules/no-url-protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
var helpers = require('../helpers');

var isUrlRegex = /^(https?:)?\/\//,
noProtocolRegex = /^(https?:)\/\//;
protocolRelativeRegex = /^(https?:)\/\//;

module.exports = {
'name': 'no-url-protocols',
'defaults': {
'enforce-domains': true
'protocol-relative-urls': false
},
'detect': function (ast, parser) {
var result = [];
Expand All @@ -17,9 +17,9 @@ module.exports = {
uri.traverse(function (item) {
if (item.is('string')) {
var stripped = helpers.stripQuotes(item.content),
regexSelector = parser.options['enforce-domains'] ?
isUrlRegex : noProtocolRegex,
message = parser.options['enforce-domains'] ?
regexSelector = !parser.options['protocol-relative-urls'] ?
isUrlRegex : protocolRelativeRegex,
message = !parser.options['protocol-relative-urls'] ?
'Protocols and domains in URLs are disallowed' :
'Protocols in URLS are disallowed';

Expand Down
8 changes: 4 additions & 4 deletions tests/rules/no-url-protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe('no url protocols - scss', function () {
});
});

it('allow protocol-relative urls [enforce-domains: false]', function (done) {
it('allow protocol-relative-urls urls [protocol-relative-urls: true]', function (done) {
lint.test(file, {
'no-url-protocols': [
1,
{
'enforce-domains': false
'protocol-relative-urls': true
}
]
}, function (data) {
Expand All @@ -48,12 +48,12 @@ describe('no url protocols - sass', function () {
});
});

it('allow protocol-relative urls [enforce-domains: false]', function (done) {
it('allow protocol-relative-urls urls [protocol-relative-urls: true]', function (done) {
lint.test(file, {
'no-url-protocols': [
1,
{
'enforce-domains': false
'protocol-relative-urls': true
}
]
}, function (data) {
Expand Down

0 comments on commit 45074f7

Please sign in to comment.