@@ -75,7 +75,7 @@ exports.deepMerge = deepMerge;
7575 * @param {any[] } userOptions the user opts
7676 * @returns {TOptions } the options with defaults
7777 */
78- function applyDefault ( defaultOptions , userOptions ) {
78+ exports . applyDefault = ( defaultOptions , userOptions ) => {
7979 // clone defaults
8080 const options = JSON . parse ( JSON . stringify ( defaultOptions ) ) ;
8181
@@ -97,15 +97,32 @@ function applyDefault(defaultOptions, userOptions) {
9797 } ) ;
9898
9999 return options ;
100- }
101- exports . applyDefault = applyDefault ;
100+ } ;
102101
103102/**
104103 * Upper cases the first character or the string
105104 * @param {string } str a string
106105 * @returns {string } upper case first
107106 */
108- function upperCaseFirst ( str ) {
109- return str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ;
110- }
111- exports . upperCaseFirst = upperCaseFirst ;
107+ exports . upperCaseFirst = str => str [ 0 ] . toUpperCase ( ) + str . slice ( 1 ) ;
108+
109+ /**
110+ * Try to retrieve typescript parser service from context
111+ * @param {RuleContext } context Rule context
112+ * @returns {{esTreeNodeToTSNodeMap}|{program}|Object|* } parserServices
113+ */
114+ exports . getParserServices = context => {
115+ if (
116+ ! context . parserServices ||
117+ ! context . parserServices . program ||
118+ ! context . parserServices . esTreeNodeToTSNodeMap
119+ ) {
120+ // TODO - the message will require revisiting once the typescript-eslint-parser/typescript-estree finalises
121+ // their work around exposing the parser. They may require that there be a project config field in
122+ // the eslint config, in which case we should check and/or report that here appropriately.
123+ throw new Error (
124+ "This rule requires you to use `eslint-plugin-typescript/parser`."
125+ ) ;
126+ }
127+ return context . parserServices ;
128+ } ;
0 commit comments