@@ -75,7 +75,7 @@ exports.deepMerge = deepMerge;
75
75
* @param {any[] } userOptions the user opts
76
76
* @returns {TOptions } the options with defaults
77
77
*/
78
- function applyDefault ( defaultOptions , userOptions ) {
78
+ exports . applyDefault = ( defaultOptions , userOptions ) => {
79
79
// clone defaults
80
80
const options = JSON . parse ( JSON . stringify ( defaultOptions ) ) ;
81
81
@@ -97,15 +97,29 @@ function applyDefault(defaultOptions, userOptions) {
97
97
} ) ;
98
98
99
99
return options ;
100
- }
101
- exports . applyDefault = applyDefault ;
100
+ } ;
102
101
103
102
/**
104
103
* Upper cases the first character or the string
105
104
* @param {string } str a string
106
105
* @returns {string } upper case first
107
106
*/
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
+ throw new Error (
121
+ "This rule requires you to use `typescript-eslint-parser`."
122
+ ) ;
123
+ }
124
+ return context . parserServices ;
125
+ } ;
0 commit comments