UNPKG

@o3r/eslint-plugin

Version:

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

42 lines (41 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isJsoncParserServices = isJsoncParserServices; exports.getJsoncParserServices = getJsoncParserServices; exports.ensureJsoncParser = ensureJsoncParser; /** * Determine if jsonc-eslint-parser is used * @param parserServices Parser services object */ function isJsoncParserServices(parserServices) { return !!parserServices && typeof parserServices.isJSON !== 'undefined'; } /** * Retrieve the json parser services object or throw if the invalid parser is used * @param context Rule context */ function getJsoncParserServices(context) { const parserService = context.sourceCode.parserServices; if (!isJsoncParserServices(parserService)) { /* * The user needs to have configured "parser" in their eslint config and set it * to jsonc-eslint-parser */ throw new Error('You have used a rule which requires \'jsonc-eslint-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 jsonc-eslint-parser * If jsonc-eslint-parser is not the configured parser when the function is invoked it will throw * @param context */ function ensureJsoncParser(context) { if (!(context.sourceCode.parserServices)) { /* * The user needs to have configured "parser" in their eslint config and set it * to jsonc-eslint-parser */ throw new Error('You have used a rule which requires \'jsonc-eslint-parser\' to be used as the \'parser\' in your ESLint config.'); } }