2 * @fileoverview Disallow mixed spaces and tabs for indentation
4 * @copyright 2014 Nicholas C. Zakas. All rights reserved.
5 * @copyright 2014 Jary Niebur. All rights reserved.
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 module.exports = function(context) {
17 switch (context.options[0]) {
18 case true: // Support old syntax, maybe add deprecation warning here
26 var COMMENT_START = /^\s*\/\*/,
27 MAYBE_COMMENT = /^\s*\*/;
29 //--------------------------------------------------------------------------
31 //--------------------------------------------------------------------------
35 "Program": function(node) {
37 * At least one space followed by a tab
38 * or the reverse before non-tab/-space
41 var regex = /^(?=[\t ]*(\t | \t))/,
43 lines = context.getSourceLines();
47 * At least one space followed by a tab
48 * before non-tab/-space characters begin.
50 regex = /^(?=[\t ]* \t)/;
53 lines.forEach(function(line, i) {
54 match = regex.exec(line);
58 if (!MAYBE_COMMENT.test(line) && !COMMENT_START.test(lines[i - 1])) {
59 context.report(node, { line: i + 1, column: match.index + 1 }, "Mixed spaces and tabs.");