File tree Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Expand file tree Collapse file tree 4 files changed +68
-3
lines changed Original file line number Diff line number Diff line change @@ -684,7 +684,18 @@ function quux () {}
684
684
// Message: @example error (semi): Missing semicolon.
685
685
686
686
/**
687
- * @example quux2 ()
687
+ * @example const i = 5 ;
688
+ * quux2 ()
689
+ */
690
+ function quux2 () {
691
+
692
+ }
693
+ // Settings: {"jsdoc":{"matchingFileName":"test/jsdocUtils.js"}}
694
+ // Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
695
+
696
+ /**
697
+ * @example const i = 5 ;
698
+ * quux2 ()
688
699
*/
689
700
function quux2 () {
690
701
Original file line number Diff line number Diff line change @@ -149,16 +149,42 @@ export default iterateJsdoc(({
149
149
150
150
if ( filename ) {
151
151
const config = cli . getConfigForFile ( filename ) ;
152
+
153
+ // We need a new instance to ensure that the rules that may only
154
+ // be available to `filename` (if it has its own `.eslintrc`),
155
+ // will be defined.
156
+ const cliFile = new CLIEngine ( {
157
+ allowInlineConfig,
158
+ baseConfig : config ,
159
+ configFile,
160
+ reportUnusedDisableDirectives,
161
+ rulePaths,
162
+ rules,
163
+ useEslintrc : eslintrcForExamples
164
+ } ) ;
165
+
152
166
const linter = new Linter ( ) ;
153
167
154
- const linterRules = [ ...cli . getRules ( ) . entries ( ) ] . reduce ( ( obj , [ key , val ] ) => {
168
+ // Force external rules to become available on `cli`
169
+ try {
170
+ cliFile . executeOnText ( '' ) ;
171
+ } catch ( error ) {
172
+ // Ignore
173
+ }
174
+
175
+ const linterRules = [ ...cliFile . getRules ( ) . entries ( ) ] . reduce ( ( obj , [ key , val ] ) => {
155
176
obj [ key ] = val ;
156
177
157
178
return obj ;
158
179
} , { } ) ;
159
180
160
181
linter . defineRules ( linterRules ) ;
161
182
183
+ if ( config . parser ) {
184
+ // eslint-disable-next-line global-require, import/no-dynamic-require
185
+ linter . defineParser ( config . parser , require ( config . parser ) ) ;
186
+ }
187
+
162
188
// Could also support `disableFixes` and `allowInlineConfig`
163
189
messages = linter . verify ( source , config , {
164
190
filename,
Original file line number Diff line number Diff line change @@ -301,7 +301,32 @@ export default {
301
301
{
302
302
code : `
303
303
/**
304
- * @example quux2()
304
+ * @example const i = 5;
305
+ * quux2()
306
+ */
307
+ function quux2 () {
308
+
309
+ }
310
+ ` ,
311
+ errors : [
312
+ {
313
+ message : '@example warning (id-length): Identifier name \'i\' is too short (< 2).'
314
+ } ,
315
+ {
316
+ message : '@example error (semi): Missing semicolon.'
317
+ }
318
+ ] ,
319
+ settings : {
320
+ jsdoc : {
321
+ matchingFileName : 'test/jsdocUtils.js'
322
+ }
323
+ }
324
+ } ,
325
+ {
326
+ code : `
327
+ /**
328
+ * @example const i = 5;
329
+ * quux2()
305
330
*/
306
331
function quux2 () {
307
332
Original file line number Diff line number Diff line change 1
1
{
2
2
"root" : true ,
3
+ "parserOptions" : {
4
+ "ecmaVersion" : 8
5
+ },
3
6
"rules" : {
4
7
"semi" : [" error" , " always" ]
5
8
}
You can’t perform that action at this time.
0 commit comments