1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | const utils_1 = require("@typescript-eslint/utils");
|
23 | const util = __importStar(require("../util"));
|
24 |
|
25 |
|
26 | const ENABLE_DISABLE_REGEX = /^\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/;
|
27 | const toText = (text, type) => type === utils_1.AST_TOKEN_TYPES.Line
|
28 | ? ['//', text.trim()].join(' ')
|
29 | : ['/*', text.trim(), '*/'].join(' ');
|
30 | exports.default = util.createRule({
|
31 | name: 'ban-tslint-comment',
|
32 | meta: {
|
33 | type: 'suggestion',
|
34 | docs: {
|
35 | description: 'Bans `// tslint:<rule-flag>` comments from being used',
|
36 | recommended: false,
|
37 | },
|
38 | messages: {
|
39 | commentDetected: 'tslint comment detected: "{{ text }}"',
|
40 | },
|
41 | schema: [],
|
42 | fixable: 'code',
|
43 | },
|
44 | defaultOptions: [],
|
45 | create: context => {
|
46 | const sourceCode = context.getSourceCode();
|
47 | return {
|
48 | Program() {
|
49 | const comments = sourceCode.getAllComments();
|
50 | comments.forEach(c => {
|
51 | if (ENABLE_DISABLE_REGEX.test(c.value)) {
|
52 | context.report({
|
53 | data: { text: toText(c.value, c.type) },
|
54 | node: c,
|
55 | messageId: 'commentDetected',
|
56 | fix(fixer) {
|
57 | const rangeStart = sourceCode.getIndexFromLoc({
|
58 | column: c.loc.start.column > 0 ? c.loc.start.column - 1 : 0,
|
59 | line: c.loc.start.line,
|
60 | });
|
61 | const rangeEnd = sourceCode.getIndexFromLoc({
|
62 | column: c.loc.end.column,
|
63 | line: c.loc.end.line,
|
64 | });
|
65 | return fixer.removeRange([rangeStart, rangeEnd + 1]);
|
66 | },
|
67 | });
|
68 | }
|
69 | });
|
70 | },
|
71 | };
|
72 | },
|
73 | });
|
74 |
|
\ | No newline at end of file |