mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.0 KiB
74 lines
2.0 KiB
/**
|
|
* @fileoverview Disallow mixed spaces and tabs for indentation
|
|
* @author Jary Niebur
|
|
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
|
* @copyright 2014 Jary Niebur. All rights reserved.
|
|
*/
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
module.exports = function(context) {
|
|
|
|
var smartTabs;
|
|
|
|
switch (context.options[0]) {
|
|
case true: // Support old syntax, maybe add deprecation warning here
|
|
case "smart-tabs":
|
|
smartTabs = true;
|
|
break;
|
|
default:
|
|
smartTabs = false;
|
|
}
|
|
|
|
var COMMENT_START = /^\s*\/\*/,
|
|
MAYBE_COMMENT = /^\s*\*/;
|
|
|
|
//--------------------------------------------------------------------------
|
|
// Public
|
|
//--------------------------------------------------------------------------
|
|
|
|
return {
|
|
|
|
"Program": function(node) {
|
|
/*
|
|
* At least one space followed by a tab
|
|
* or the reverse before non-tab/-space
|
|
* characters begin.
|
|
*/
|
|
var regex = /^(?=[\t ]*(\t | \t))/,
|
|
match,
|
|
lines = context.getSourceLines();
|
|
|
|
if (smartTabs) {
|
|
/*
|
|
* At least one space followed by a tab
|
|
* before non-tab/-space characters begin.
|
|
*/
|
|
regex = /^(?=[\t ]* \t)/;
|
|
}
|
|
|
|
lines.forEach(function(line, i) {
|
|
match = regex.exec(line);
|
|
|
|
if (match) {
|
|
|
|
if (!MAYBE_COMMENT.test(line) && !COMMENT_START.test(lines[i - 1])) {
|
|
context.report(node, { line: i + 1, column: match.index + 1 }, "Mixed spaces and tabs.");
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
module.exports.schema = [
|
|
{
|
|
"enum": ["smart-tabs", true, false]
|
|
}
|
|
];
|
|
|