Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
[FEAT] Add getParserServices function from #245
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed Dec 28, 2018
1 parent 4d85404 commit b08576e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ exports.deepMerge = deepMerge;
* @param {any[]} userOptions the user opts
* @returns {TOptions} the options with defaults
*/
function applyDefault(defaultOptions, userOptions) {
exports.applyDefault = (defaultOptions, userOptions) => {
// clone defaults
const options = JSON.parse(JSON.stringify(defaultOptions));

Expand All @@ -97,15 +97,29 @@ function applyDefault(defaultOptions, userOptions) {
});

return options;
}
exports.applyDefault = applyDefault;
};

/**
* Upper cases the first character or the string
* @param {string} str a string
* @returns {string} upper case first
*/
function upperCaseFirst(str) {
return str[0].toUpperCase() + str.slice(1);
}
exports.upperCaseFirst = upperCaseFirst;
exports.upperCaseFirst = str => str[0].toUpperCase() + str.slice(1);

/**
* Try to retrieve typescript parser service from context
* @param {RuleContext} context Rule context
* @returns {{esTreeNodeToTSNodeMap}|{program}|Object|*} parserServices
*/
exports.getParserServices = context => {
if (
!context.parserServices ||
!context.parserServices.program ||
!context.parserServices.esTreeNodeToTSNodeMap
) {
throw new Error(
"This rule requires you to use `typescript-eslint-parser`."
);
}
return context.parserServices;
};

0 comments on commit b08576e

Please sign in to comment.