Skip to content

Commit

Permalink
issue-813 -- Adds no-domains rule
Browse files Browse the repository at this point in the history
  • Loading branch information
danwaz committed Aug 25, 2016
1 parent a120002 commit cf9472a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/config/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rules:
no-css-comments: 1
no-debug: 1
no-disallowed-properties: 0
no-domains: 1
no-duplicate-properties: 1
no-empty-rulesets: 1
no-extends: 0
Expand Down
37 changes: 37 additions & 0 deletions lib/rules/no-domains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

var helpers = require('../helpers');
var url = require('url');

var stripQuotes = function (str) {
return str.substring(1, str.length - 1);
};

module.exports = {
'name': 'no-domains',
'defaults': {},
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('uri', function (uri) {
uri.traverse(function (item) {
if (item.is('string')) {
var stripped = stripQuotes(item.content),
parsedUrl = url.parse(stripped, false, true);

if (parsedUrl.host) {
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;
}
};

0 comments on commit cf9472a

Please sign in to comment.