UNPKG

tslint-to-eslint-config

Version:

Converts your TSLint configuration to the closest reasonable ESLint equivalent.

100 lines (99 loc) 3.44 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? function (o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function () { return m[k]; }, }; } Object.defineProperty(o, k2, desc); } : function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); } : function (o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseFileComments = void 0; const utils = __importStar(require("tsutils")); const typescript_1 = __importDefault(require("typescript")); /** * @see https://github.com/Microsoft/TypeScript/issues/21049 */ const parseFileComments = (filePath, content) => { const sourceFile = typescript_1.default.createSourceFile( filePath, content, typescript_1.default.ScriptTarget.Latest, /*setParentNodes */ true, ); const directives = []; utils.forEachComment(sourceFile, (fullText, comment) => { const parsedComment = parseFileComment(fullText, comment); if (parsedComment !== undefined) { directives.push(parsedComment); } }); return directives; }; exports.parseFileComments = parseFileComments; /** * @see https://github.com/palantir/tslint/blob/master/src/enableDisableRules.ts */ const tslintRegex = new RegExp(/tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/g); const parseFileComment = (fullText, comment) => { const commentText = ( comment.kind === typescript_1.default.SyntaxKind.SingleLineCommentTrivia ? fullText.substring(comment.pos + 2, comment.end) : fullText.substring(comment.pos + 2, comment.end - 2) ).trim(); const match = commentText.match(tslintRegex); if (match === null) { return undefined; } return { commentKind: comment.kind, directive: match[0].replace("e:", "e"), end: comment.end, pos: comment.pos, ruleNames: commentText.slice(match[0].length).split(/\s+/).map(trimColons).filter(Boolean), }; }; const trimColons = (text) => text .replace(/^(:|\s)*/, "") .replace(/(:|\s)*$/, "") .trim(); //# sourceMappingURL=parseFileComments.js.map