-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/fix-shorthand-values
- Loading branch information
Showing
9 changed files
with
242 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# No Url Domains | ||
|
||
Rule `no-url-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'); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'), | ||
url = require('url'); | ||
|
||
module.exports = { | ||
'name': 'no-url-domains', | ||
'defaults': {}, | ||
'detect': function (ast, parser) { | ||
var result = []; | ||
|
||
ast.traverseByType('uri', function (uri) { | ||
uri.traverse(function (item) { | ||
if (item.is('string')) { | ||
var stripped = helpers.stripQuotes(item.content), | ||
parsedUrl = url.parse(stripped, false, true); | ||
|
||
if (parsedUrl.host && parsedUrl.protocol !== 'data:') { | ||
result = helpers.addUnique(result, { | ||
'ruleId': parser.rule.name, | ||
'severity': parser.severity, | ||
'line': item.end.line, | ||
'column': item.end.column, | ||
'message': 'Domains in URLs are disallowed' | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return result; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var lint = require('./_lint'); | ||
|
||
////////////////////////////// | ||
// SCSS syntax tests | ||
////////////////////////////// | ||
describe('no url domains - scss', function () { | ||
var file = lint.file('no-url-domains.scss'); | ||
|
||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'no-url-domains': 1 | ||
}, function (data) { | ||
lint.assert.equal(3, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
////////////////////////////// | ||
// Sass syntax tests | ||
////////////////////////////// | ||
describe('no url domains - sass', function () { | ||
var file = lint.file('no-url-domains.sass'); | ||
|
||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'no-url-domains': 1 | ||
}, function (data) { | ||
lint.assert.equal(3, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.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') | ||
|
||
|
||
.foo | ||
background-image: url('/img/bar.png') | ||
|
||
|
||
.foo | ||
background-image: url('img/bar.png') | ||
|
||
|
||
.foo | ||
background-image: url('bar.png') | ||
|
||
.foo | ||
background-image: url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.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'); | ||
} | ||
|
||
.foo { | ||
background-image: url('/img/bar.png'); | ||
} | ||
|
||
.foo { | ||
background-image: url('img/bar.png'); | ||
} | ||
|
||
.foo { | ||
background-image: url('bar.png'); | ||
} | ||
|
||
.foo { | ||
background-image: url('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); | ||
} |