google_forms/node_modules/eslint/lib/rules/no-tabs.js

82 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

2024-08-09 12:04:48 +00:00
/**
* @fileoverview Rule to check for tabs inside a file
* @author Gyandeep Singh
2024-08-21 06:34:30 +00:00
* @deprecated in ESLint v8.53.0
2024-08-09 12:04:48 +00:00
*/
"use strict";
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
const tabRegex = /\t+/gu;
const anyNonWhitespaceRegex = /\S/u;
//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
2024-08-21 06:34:30 +00:00
/** @type {import('../shared/types').Rule} */
2024-08-09 12:04:48 +00:00
module.exports = {
meta: {
2024-08-21 06:34:30 +00:00
deprecated: true,
replacedBy: [],
2024-08-09 12:04:48 +00:00
type: "layout",
docs: {
2024-08-21 06:34:30 +00:00
description: "Disallow all tabs",
2024-08-09 12:04:48 +00:00
recommended: false,
2024-08-21 06:34:30 +00:00
url: "https://eslint.org/docs/latest/rules/no-tabs"
2024-08-09 12:04:48 +00:00
},
schema: [{
type: "object",
properties: {
allowIndentationTabs: {
type: "boolean",
default: false
}
},
additionalProperties: false
}],
messages: {
unexpectedTab: "Unexpected tab character."
}
},
create(context) {
2024-08-21 06:34:30 +00:00
const sourceCode = context.sourceCode;
2024-08-09 12:04:48 +00:00
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: {
start: {
line: index + 1,
column: match.index
},
end: {
line: index + 1,
column: match.index + match[0].length
}
},
messageId: "unexpectedTab"
});
}
});
}
};
}
};