@@ -16,10 +16,10 @@ describe('utils', () => {
16
16
'' ,
17
17
'module.exports;' ,
18
18
'module.exports = foo;' ,
19
- 'module.boop = function() { return {};};' ,
20
- 'exports = function() { return {};};' ,
21
- 'module.exports = function* () { return {}; };' ,
22
- 'module.exports = async function () { return {};};' ,
19
+ 'module.boop = function(context ) { return {};};' ,
20
+ 'exports = function(context ) { return {};};' ,
21
+ 'module.exports = function* (context ) { return {}; };' ,
22
+ 'module.exports = async function (context ) { return {};};' ,
23
23
'module.exports = {};' ,
24
24
'module.exports = { meta: {} }' ,
25
25
'module.exports = { create: {} }' ,
@@ -28,14 +28,18 @@ describe('utils', () => {
28
28
'module.exports = { create: async function foo() {} }' ,
29
29
30
30
// Function-style rule but missing object return.
31
- 'module.exports = () => { }' ,
32
- 'module.exports = () => { return; }' ,
33
- 'module.exports = () => { return 123; }' ,
34
- 'module.exports = () => { return FOO; }' ,
35
- 'module.exports = function foo() { }' ,
36
- 'module.exports = () => { }' ,
37
- 'exports.meta = {}; module.exports = () => { }' ,
38
- 'module.exports = () => { }; module.exports.meta = {};' ,
31
+ 'module.exports = (context) => { }' ,
32
+ 'module.exports = (context) => { return; }' ,
33
+ 'module.exports = (context) => { return 123; }' ,
34
+ 'module.exports = (context) => { return FOO; }' ,
35
+ 'module.exports = function foo(context) { }' ,
36
+ 'module.exports = (context) => { }' ,
37
+ 'exports.meta = {}; module.exports = (context) => { }' ,
38
+ 'module.exports = (context) => { }; module.exports.meta = {};' ,
39
+
40
+ // Function-style rule but missing context parameter.
41
+ 'module.exports = () => { return {}; }' ,
42
+ 'module.exports = (foo, bar) => { return {}; }' ,
39
43
40
44
// Correct TypeScript helper structure but we don't support CJS for TypeScript rules:
41
45
'module.exports = createESLintRule({ create() {}, meta: {} });' ,
@@ -57,13 +61,17 @@ describe('utils', () => {
57
61
'const foo = {}; export default foo' ,
58
62
59
63
// Exports function but not default export.
60
- 'export function foo () { return {}; }' ,
64
+ 'export function foo (context ) { return {}; }' ,
61
65
62
66
// Exports function but no object return inside function.
63
- 'export default function () { }' ,
64
- 'export default function () { return; }' ,
65
- 'export default function () { return 123; }' ,
66
- 'export default function () { return FOO; }' ,
67
+ 'export default function (context) { }' ,
68
+ 'export default function (context) { return; }' ,
69
+ 'export default function (context) { return 123; }' ,
70
+ 'export default function (context) { return FOO; }' ,
71
+
72
+ // Function-style rule but missing context parameter.
73
+ 'export default function () { return {}; }' ,
74
+ 'export default function (foo, bar) { return {}; }' ,
67
75
68
76
// Incorrect TypeScript helper structure:
69
77
'export default foo()({ create() {}, meta: {} });' ,
@@ -185,7 +193,7 @@ describe('utils', () => {
185
193
meta : { type : 'ObjectExpression' } ,
186
194
isNewStyle : true ,
187
195
} ,
188
- 'module.exports.create = function foo() {}; module.exports.meta = {}' : {
196
+ 'module.exports.create = function foo(context ) {}; module.exports.meta = {}' : {
189
197
create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
190
198
meta : { type : 'ObjectExpression' } ,
191
199
isNewStyle : true ,
@@ -220,32 +228,42 @@ describe('utils', () => {
220
228
meta : { type : 'ObjectExpression' } ,
221
229
isNewStyle : true ,
222
230
} ,
223
- 'module.exports = { create: () => { } }; exports.meta = {};' : {
231
+ 'module.exports = { create: (context ) => { } }; exports.meta = {};' : {
224
232
create : { type : 'ArrowFunctionExpression' } ,
225
233
meta : null ,
226
234
isNewStyle : true ,
227
235
} ,
228
- 'module.exports = function foo() { return {}; }' : {
236
+ 'module.exports = function foo(context) { return {}; }' : {
237
+ create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
238
+ meta : null ,
239
+ isNewStyle : false ,
240
+ } ,
241
+ 'module.exports = function foo(slightlyDifferentContextName) { return {}; }' : {
242
+ create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
243
+ meta : null ,
244
+ isNewStyle : false ,
245
+ } ,
246
+ 'module.exports = function foo({ report }) { return {}; }' : {
229
247
create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
230
248
meta : null ,
231
249
isNewStyle : false ,
232
250
} ,
233
- 'module.exports = () => { return {}; }' : {
251
+ 'module.exports = (context ) => { return {}; }' : {
234
252
create : { type : 'ArrowFunctionExpression' } ,
235
253
meta : null ,
236
254
isNewStyle : false ,
237
255
} ,
238
- 'module.exports = () => { if (foo) { return {}; } }' : {
256
+ 'module.exports = (context ) => { if (foo) { return {}; } }' : {
239
257
create : { type : 'ArrowFunctionExpression' } ,
240
258
meta : null ,
241
259
isNewStyle : false ,
242
260
} ,
243
- 'exports.meta = {}; module.exports = () => { return {}; }' : {
261
+ 'exports.meta = {}; module.exports = (context ) => { return {}; }' : {
244
262
create : { type : 'ArrowFunctionExpression' } ,
245
263
meta : null ,
246
264
isNewStyle : false ,
247
265
} ,
248
- 'module.exports = () => { return {}; }; module.exports.meta = {};' : {
266
+ 'module.exports = (context ) => { return {}; }; module.exports.meta = {};' : {
249
267
create : { type : 'ArrowFunctionExpression' } ,
250
268
meta : null ,
251
269
isNewStyle : false ,
@@ -279,17 +297,17 @@ describe('utils', () => {
279
297
} ,
280
298
281
299
// ESM (function style)
282
- 'export default function () { return {}; }' : {
300
+ 'export default function (context ) { return {}; }' : {
283
301
create : { type : 'FunctionDeclaration' } ,
284
302
meta : null ,
285
303
isNewStyle : false ,
286
304
} ,
287
- 'export default function () { if (foo) { return {}; } }' : {
305
+ 'export default function (context ) { if (foo) { return {}; } }' : {
288
306
create : { type : 'FunctionDeclaration' } ,
289
307
meta : null ,
290
308
isNewStyle : false ,
291
309
} ,
292
- 'export default () => { return {}; }' : {
310
+ 'export default (context ) => { return {}; }' : {
293
311
create : { type : 'ArrowFunctionExpression' } ,
294
312
meta : null ,
295
313
isNewStyle : false ,
@@ -315,7 +333,7 @@ describe('utils', () => {
315
333
{ ignoreEval : true , ecmaVersion : 6 , sourceType : 'module' } ,
316
334
] ) {
317
335
const ast = espree . parse ( `
318
- const create = () => {};
336
+ const create = (context ) => {};
319
337
const meta = {};
320
338
module.exports = { create, meta };
321
339
` , { ecmaVersion : 6 } ) ;
@@ -338,7 +356,7 @@ describe('utils', () => {
338
356
describe ( 'the file has newer syntax' , ( ) => {
339
357
const CASES = [
340
358
{
341
- source : 'module.exports = function() { class Foo { @someDecorator() someProp }; return {}; };' ,
359
+ source : 'module.exports = function(context ) { class Foo { @someDecorator() someProp }; return {}; };' ,
342
360
options : { sourceType : 'script' } ,
343
361
expected : {
344
362
create : { type : 'FunctionExpression' } ,
@@ -347,7 +365,7 @@ describe('utils', () => {
347
365
} ,
348
366
} ,
349
367
{
350
- source : 'export default function() { class Foo { @someDecorator() someProp }; return {}; };' ,
368
+ source : 'export default function(context ) { class Foo { @someDecorator() someProp }; return {}; };' ,
351
369
options : { sourceType : 'module' } ,
352
370
expected : {
353
371
create : { type : 'FunctionDeclaration' } ,
0 commit comments