UNPKG

1.39 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to check for tabs inside a file
3 * @author Gyandeep Singh
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Helpers
10//------------------------------------------------------------------------------
11const regex = /\t/;
12
13//------------------------------------------------------------------------------
14// Public Interface
15//------------------------------------------------------------------------------
16
17module.exports = {
18 meta: {
19 docs: {
20 description: "disallow all tabs",
21 category: "Stylistic Issues",
22 recommended: false,
23 url: "https://eslint.org/docs/rules/no-tabs"
24 },
25 schema: []
26 },
27
28 create(context) {
29 return {
30 Program(node) {
31 context.getSourceCode().getLines().forEach((line, index) => {
32 const match = regex.exec(line);
33
34 if (match) {
35 context.report({
36 node,
37 loc: {
38 line: index + 1,
39 column: match.index + 1
40 },
41 message: "Unexpected tab character."
42 });
43 }
44 });
45 }
46 };
47 }
48};