Skip to content

Commit e74cdad

Browse files
committed
Adding no-tabs rule
Don't allow TAB, only spaces.
1 parent f57c84c commit e74cdad

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/rules/no-tabs.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Rule: Don't use tabs, use space
3+
*
4+
*/
5+
6+
CSSLint.addRule({
7+
8+
// rule information
9+
id: "no-tabs",
10+
name: "Disallow tabs",
11+
desc: "Checks for tab",
12+
browsers: "All",
13+
14+
// initialization
15+
init: function(parser, reporter) {
16+
"use strict";
17+
var rule = this,
18+
sheet;
19+
20+
parser.addListener("startstylesheet", function() {
21+
sheet = this._tokenStream._reader._input.split(/\n/);
22+
});
23+
24+
parser.addListener("property", function(event) {
25+
if (/\t/.test(sheet[event.line - 1])) {
26+
reporter.report("The TAB character is not allowed.", event.line, event.col, rule);
27+
}
28+
});
29+
}
30+
31+
});

tests/rules/no-tabs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(function() {
2+
"use strict";
3+
var Assert = YUITest.Assert;
4+
5+
YUITest.TestRunner.add(new YUITest.TestCase({
6+
7+
name: "no-tabs rule errors",
8+
9+
"tabs in a stylesheet": function() {
10+
var result = CSSLint.verify(".foo{\ttext-indent: -100px;}", { "no-tabs": 1 });
11+
12+
Assert.areEqual(1, result.messages.length);
13+
Assert.areEqual("warning", result.messages[0].type);
14+
Assert.areEqual("The TAB character is not allowed.", result.messages[0].message);
15+
}
16+
17+
}));
18+
19+
})();

0 commit comments

Comments
 (0)