@o3r/eslint-plugin
Version:
The module provides in-house eslint plugins to use in your own eslint configuration.
42 lines (41 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isYamlParserServices = isYamlParserServices;
exports.getYamlParserServices = getYamlParserServices;
exports.ensureJsoncParser = ensureJsoncParser;
/**
* Determine if yaml-eslint-parser is used
* @param parserServices Parser services object
*/
function isYamlParserServices(parserServices) {
return !!parserServices && parserServices.isYAML;
}
/**
* Retrieve the yaml parser services object or throw if the invalid parser is used
* @param context Rule context
*/
function getYamlParserServices(context) {
const parserService = context.sourceCode.parserServices;
if (!isYamlParserServices(parserService)) {
/*
* The user needs to have configured "parser" in their eslint config and set it
* to yaml-eslint-parser
*/
throw new Error('You have used a rule which requires \'yaml-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 yaml-eslint-parser
* If yaml-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 yaml-eslint-parser
*/
throw new Error('You have used a rule which requires \'yaml-eslint-parser\' to be used as the \'parser\' in your ESLint config.');
}
}