@@ -27,7 +27,17 @@ describe('utils', () => {
27
27
'module.exports = { create: function* foo() {} }' ,
28
28
'module.exports = { create: async function foo() {} }' ,
29
29
30
- // Correct TypeScript helper structure but missing parameterized types (note: we don't support CJS for TypeScript rules):
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 = {};' ,
39
+
40
+ // Correct TypeScript helper structure but we don't support CJS for TypeScript rules:
31
41
'module.exports = createESLintRule({ create() {}, meta: {} });' ,
32
42
'module.exports = util.createRule({ create() {}, meta: {} });' ,
33
43
'module.exports = ESLintUtils.RuleCreator(docsUrl)({ create() {}, meta: {} });' ,
@@ -90,7 +100,7 @@ describe('utils', () => {
90
100
91
101
describe ( 'the file does not have a valid rule (TypeScript + TypeScript parser + CJS)' , ( ) => {
92
102
[
93
- // Correct TypeScript helper structure but missing parameterized types (note: we don't support CJS for TypeScript rules):
103
+ // Correct TypeScript helper structure but we don't support CJS for TypeScript rules):
94
104
'module.exports = createESLintRule<Options, MessageIds>({ create() {}, meta: {} });' ,
95
105
'module.exports = util.createRule<Options, MessageIds>({ create() {}, meta: {} });' ,
96
106
'module.exports = ESLintUtils.RuleCreator(docsUrl)<Options, MessageIds>({ create() {}, meta: {} });' ,
@@ -215,22 +225,22 @@ describe('utils', () => {
215
225
meta : null ,
216
226
isNewStyle : true ,
217
227
} ,
218
- 'module.exports = function foo() {}' : {
228
+ 'module.exports = function foo() { return {}; }' : {
219
229
create : { type : 'FunctionExpression' , id : { name : 'foo' } } ,
220
230
meta : null ,
221
231
isNewStyle : false ,
222
232
} ,
223
- 'module.exports = () => {}' : {
233
+ 'module.exports = () => { return {}; }' : {
224
234
create : { type : 'ArrowFunctionExpression' } ,
225
235
meta : null ,
226
236
isNewStyle : false ,
227
237
} ,
228
- 'exports.meta = {}; module.exports = () => {}' : {
238
+ 'exports.meta = {}; module.exports = () => { return {}; }' : {
229
239
create : { type : 'ArrowFunctionExpression' } ,
230
240
meta : null ,
231
241
isNewStyle : false ,
232
242
} ,
233
- 'module.exports = () => {}; module.exports.meta = {};' : {
243
+ 'module.exports = () => { return {}; }; module.exports.meta = {};' : {
234
244
create : { type : 'ArrowFunctionExpression' } ,
235
245
meta : null ,
236
246
isNewStyle : false ,
@@ -533,9 +543,9 @@ describe('utils', () => {
533
543
534
544
describe ( 'getSourceCodeIdentifiers' , ( ) => {
535
545
const CASES = {
536
- 'module.exports = context => { const sourceCode = context.getSourceCode(); sourceCode; foo; }' : 2 ,
537
- 'module.exports = context => { const x = 1, sc = context.getSourceCode(); sc; sc; sc; sourceCode; }' : 4 ,
538
- 'module.exports = context => { const sourceCode = context.getNotSourceCode(); }' : 0 ,
546
+ 'module.exports = context => { const sourceCode = context.getSourceCode(); sourceCode; foo; return {}; }' : 2 ,
547
+ 'module.exports = context => { const x = 1, sc = context.getSourceCode(); sc; sc; sc; sourceCode; return {}; }' : 4 ,
548
+ 'module.exports = context => { const sourceCode = context.getNotSourceCode(); return {}; }' : 0 ,
539
549
} ;
540
550
541
551
Object . keys ( CASES ) . forEach ( testSource => {
0 commit comments