UNPKG

@o3r/eslint-plugin

Version:

The module provides in-house eslint plugins to use in your own eslint configuration.

43 lines (42 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isTemplateParserServices = isTemplateParserServices; exports.getTemplateParserServices = getTemplateParserServices; exports.ensureTemplateParser = ensureTemplateParser; /** * Determine if @angular-eslint/template-parser is used * @param parserServices Parser services object */ function isTemplateParserServices(parserServices) { return parserServices && (typeof parserServices.convertElementSourceSpanToLoc === 'function' || typeof parserServices.convertNodeSourceSpanToLoc === 'function'); } /** * Retrieve the template parser services object or throw if the invalid parser is used * @param context Rule context */ function getTemplateParserServices(context) { const parserService = context.sourceCode.parserServices; if (!isTemplateParserServices(parserService)) { /* * The user needs to have configured "parser" in their eslint config and set it * to @angular-eslint/template-parser */ throw new Error('You have used a rule which requires \'@angular-eslint/template-parser\' to be used as the \'parser\' in your ESLint config.'); } return parserService; } /** * Utility for rule authors to ensure that their rule is correctly being used with @angular-eslint/template-parser * If @angular-eslint/template-parser is not the configured parser when the function is invoked it will throw * @param context */ function ensureTemplateParser(context) { if (!isTemplateParserServices(context.parserServices)) { /* * The user needs to have configured "parser" in their eslint config and set it * to @angular-eslint/template-parser */ throw new Error('You have used a rule which requires \'@angular-eslint/template-parser\' to be used as the \'parser\' in your ESLint config.'); } }