node/tools/node_modules/eslint/lib/rules/no-tabs.js
cjihrig d72d43f9bf tools: update ESLint to 5.9.0
Update ESLint to 5.9.0.

PR-URL: https://github.com/nodejs/node/pull/24280
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-11-12 14:14:31 -08:00

68 lines
2.0 KiB
JavaScript

/**
* @fileoverview Rule to check for tabs inside a file
* @author Gyandeep Singh
*/
"use strict";
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const tabRegex = /\t+/g;
const anyNonWhitespaceRegex = /\S/;
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "layout",
docs: {
description: "disallow all tabs",
category: "Stylistic Issues",
recommended: false,
url: "https://eslint.org/docs/rules/no-tabs"
},
schema: [{
type: "object",
properties: {
allowIndentationTabs: {
type: "boolean"
}
},
additionalProperties: false
}]
},
create(context) {
const sourceCode = context.getSourceCode();
const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;
return {
Program(node) {
sourceCode.getLines().forEach((line, index) => {
let match;
while ((match = tabRegex.exec(line)) !== null) {
if (allowIndentationTabs && !anyNonWhitespaceRegex.test(line.slice(0, match.index))) {
continue;
}
context.report({
node,
loc: {
line: index + 1,
column: match.index
},
message: "Unexpected tab character."
});
}
});
}
};
}
};