Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-tabs.js
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 //------------------------------------------------------------------------------
11
12 const tabRegex = /\t+/gu;
13 const anyNonWhitespaceRegex = /\S/u;
14
15 //------------------------------------------------------------------------------
16 // Public Interface
17 //------------------------------------------------------------------------------
18
19 module.exports = {
20     meta: {
21         type: "layout",
22
23         docs: {
24             description: "disallow all tabs",
25             category: "Stylistic Issues",
26             recommended: false,
27             url: "https://eslint.org/docs/rules/no-tabs"
28         },
29         schema: [{
30             type: "object",
31             properties: {
32                 allowIndentationTabs: {
33                     type: "boolean",
34                     default: false
35                 }
36             },
37             additionalProperties: false
38         }]
39     },
40
41     create(context) {
42         const sourceCode = context.getSourceCode();
43         const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;
44
45         return {
46             Program(node) {
47                 sourceCode.getLines().forEach((line, index) => {
48                     let match;
49
50                     while ((match = tabRegex.exec(line)) !== null) {
51                         if (allowIndentationTabs && !anyNonWhitespaceRegex.test(line.slice(0, match.index))) {
52                             continue;
53                         }
54
55                         context.report({
56                             node,
57                             loc: {
58                                 start: {
59                                     line: index + 1,
60                                     column: match.index
61                                 },
62                                 end: {
63                                     line: index + 1,
64                                     column: match.index + match[0].length
65                                 }
66                             },
67                             message: "Unexpected tab character."
68                         });
69                     }
70                 });
71             }
72         };
73     }
74 };