main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
2.4 KB
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Rule to check for tabs inside a file
|
---|
| 3 | * @author Gyandeep Singh
|
---|
| 4 | * @deprecated in ESLint v8.53.0
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | "use strict";
|
---|
| 8 |
|
---|
| 9 | //------------------------------------------------------------------------------
|
---|
| 10 | // Helpers
|
---|
| 11 | //------------------------------------------------------------------------------
|
---|
| 12 |
|
---|
| 13 | const tabRegex = /\t+/gu;
|
---|
| 14 | const anyNonWhitespaceRegex = /\S/u;
|
---|
| 15 |
|
---|
| 16 | //------------------------------------------------------------------------------
|
---|
| 17 | // Public Interface
|
---|
| 18 | //------------------------------------------------------------------------------
|
---|
| 19 |
|
---|
| 20 | /** @type {import('../shared/types').Rule} */
|
---|
| 21 | module.exports = {
|
---|
| 22 | meta: {
|
---|
| 23 | deprecated: true,
|
---|
| 24 | replacedBy: [],
|
---|
| 25 | type: "layout",
|
---|
| 26 |
|
---|
| 27 | docs: {
|
---|
| 28 | description: "Disallow all tabs",
|
---|
| 29 | recommended: false,
|
---|
| 30 | url: "https://eslint.org/docs/latest/rules/no-tabs"
|
---|
| 31 | },
|
---|
| 32 | schema: [{
|
---|
| 33 | type: "object",
|
---|
| 34 | properties: {
|
---|
| 35 | allowIndentationTabs: {
|
---|
| 36 | type: "boolean",
|
---|
| 37 | default: false
|
---|
| 38 | }
|
---|
| 39 | },
|
---|
| 40 | additionalProperties: false
|
---|
| 41 | }],
|
---|
| 42 |
|
---|
| 43 | messages: {
|
---|
| 44 | unexpectedTab: "Unexpected tab character."
|
---|
| 45 | }
|
---|
| 46 | },
|
---|
| 47 |
|
---|
| 48 | create(context) {
|
---|
| 49 | const sourceCode = context.sourceCode;
|
---|
| 50 | const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs;
|
---|
| 51 |
|
---|
| 52 | return {
|
---|
| 53 | Program(node) {
|
---|
| 54 | sourceCode.getLines().forEach((line, index) => {
|
---|
| 55 | let match;
|
---|
| 56 |
|
---|
| 57 | while ((match = tabRegex.exec(line)) !== null) {
|
---|
| 58 | if (allowIndentationTabs && !anyNonWhitespaceRegex.test(line.slice(0, match.index))) {
|
---|
| 59 | continue;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | context.report({
|
---|
| 63 | node,
|
---|
| 64 | loc: {
|
---|
| 65 | start: {
|
---|
| 66 | line: index + 1,
|
---|
| 67 | column: match.index
|
---|
| 68 | },
|
---|
| 69 | end: {
|
---|
| 70 | line: index + 1,
|
---|
| 71 | column: match.index + match[0].length
|
---|
| 72 | }
|
---|
| 73 | },
|
---|
| 74 | messageId: "unexpectedTab"
|
---|
| 75 | });
|
---|
| 76 | }
|
---|
| 77 | });
|
---|
| 78 | }
|
---|
| 79 | };
|
---|
| 80 | }
|
---|
| 81 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.