@@ -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,32 @@ 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 {}; }' : {
229
237
create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
230
238
meta : null ,
231
239
isNewStyle : false ,
232
240
} ,
233
- 'module.exports = () => { return {}; }' : {
241
+ 'module.exports = (context ) => { return {}; }' : {
234
242
create : { type : 'ArrowFunctionExpression' } ,
235
243
meta : null ,
236
244
isNewStyle : false ,
237
245
} ,
238
- 'module.exports = () => { if (foo) { return {}; } }' : {
246
+ 'module.exports = (context ) => { if (foo) { return {}; } }' : {
239
247
create : { type : 'ArrowFunctionExpression' } ,
240
248
meta : null ,
241
249
isNewStyle : false ,
242
250
} ,
243
- 'exports.meta = {}; module.exports = () => { return {}; }' : {
251
+ 'exports.meta = {}; module.exports = (context ) => { return {}; }' : {
244
252
create : { type : 'ArrowFunctionExpression' } ,
245
253
meta : null ,
246
254
isNewStyle : false ,
247
255
} ,
248
- 'module.exports = () => { return {}; }; module.exports.meta = {};' : {
256
+ 'module.exports = (context ) => { return {}; }; module.exports.meta = {};' : {
249
257
create : { type : 'ArrowFunctionExpression' } ,
250
258
meta : null ,
251
259
isNewStyle : false ,
@@ -279,17 +287,17 @@ describe('utils', () => {
279
287
} ,
280
288
281
289
// ESM (function style)
282
- 'export default function () { return {}; }' : {
290
+ 'export default function (context ) { return {}; }' : {
283
291
create : { type : 'FunctionDeclaration' } ,
284
292
meta : null ,
285
293
isNewStyle : false ,
286
294
} ,
287
- 'export default function () { if (foo) { return {}; } }' : {
295
+ 'export default function (context ) { if (foo) { return {}; } }' : {
288
296
create : { type : 'FunctionDeclaration' } ,
289
297
meta : null ,
290
298
isNewStyle : false ,
291
299
} ,
292
- 'export default () => { return {}; }' : {
300
+ 'export default (context ) => { return {}; }' : {
293
301
create : { type : 'ArrowFunctionExpression' } ,
294
302
meta : null ,
295
303
isNewStyle : false ,
@@ -315,7 +323,7 @@ describe('utils', () => {
315
323
{ ignoreEval : true , ecmaVersion : 6 , sourceType : 'module' } ,
316
324
] ) {
317
325
const ast = espree . parse ( `
318
- const create = () => {};
326
+ const create = (context ) => {};
319
327
const meta = {};
320
328
module.exports = { create, meta };
321
329
` , { ecmaVersion : 6 } ) ;
@@ -338,7 +346,7 @@ describe('utils', () => {
338
346
describe ( 'the file has newer syntax' , ( ) => {
339
347
const CASES = [
340
348
{
341
- source : 'module.exports = function() { class Foo { @someDecorator() someProp }; return {}; };' ,
349
+ source : 'module.exports = function(context ) { class Foo { @someDecorator() someProp }; return {}; };' ,
342
350
options : { sourceType : 'script' } ,
343
351
expected : {
344
352
create : { type : 'FunctionExpression' } ,
@@ -347,7 +355,7 @@ describe('utils', () => {
347
355
} ,
348
356
} ,
349
357
{
350
- source : 'export default function() { class Foo { @someDecorator() someProp }; return {}; };' ,
358
+ source : 'export default function(context ) { class Foo { @someDecorator() someProp }; return {}; };' ,
351
359
options : { sourceType : 'module' } ,
352
360
expected : {
353
361
create : { type : 'FunctionDeclaration' } ,
0 commit comments