@@ -50,6 +50,12 @@ describe('utils', () => {
50
50
'module.exports = createESLintRule({ create() {}, meta: {} });' ,
51
51
'module.exports = util.createRule({ create() {}, meta: {} });' ,
52
52
'module.exports = ESLintUtils.RuleCreator(docsUrl)({ create() {}, meta: {} });' ,
53
+
54
+ // Named export of a rule, only supported in ESM within this plugin
55
+ 'module.exports.rule = { create: function() {} };' ,
56
+ 'exports.rule = { create: function() {} };' ,
57
+ 'const rule = { create: function() {} }; module.exports.rule = rule;' ,
58
+ 'const rule = { create: function() {} }; exports.rule = rule;' ,
53
59
] . forEach ( ( noRuleCase ) => {
54
60
it ( `returns null for ${ noRuleCase } ` , ( ) => {
55
61
const ast = espree . parse ( noRuleCase , { ecmaVersion : 8 , range : true } ) ;
@@ -65,15 +71,11 @@ describe('utils', () => {
65
71
describe ( 'the file does not have a valid rule (ESM)' , ( ) => {
66
72
[
67
73
'' ,
68
- 'export const foo = { create() {} }' ,
69
74
'export default { foo: {} }' ,
70
75
'const foo = {}; export default foo' ,
71
76
'const foo = 123; export default foo' ,
72
77
'const foo = function(){}; export default foo' ,
73
78
74
- // Exports function but not default export.
75
- 'export function foo (context) { return {}; }' ,
76
-
77
79
// Exports function but no object return inside function.
78
80
'export default function (context) { }' ,
79
81
'export default function (context) { return; }' ,
@@ -209,13 +211,46 @@ describe('utils', () => {
209
211
meta : { type : 'ObjectExpression' } ,
210
212
isNewStyle : true ,
211
213
} ,
214
+ // No helper, exported variable.
215
+ 'export const rule = { create() {}, meta: {} };' : {
216
+ create : { type : 'FunctionExpression' } ,
217
+ meta : { type : 'ObjectExpression' } ,
218
+ isNewStyle : true ,
219
+ } ,
212
220
// no helper, variable with type.
213
221
'const rule: Rule.RuleModule = { create() {}, meta: {} }; export default rule;' :
214
222
{
215
223
create : { type : 'FunctionExpression' } ,
216
224
meta : { type : 'ObjectExpression' } ,
217
225
isNewStyle : true ,
218
226
} ,
227
+ // no helper, exported variable with type.
228
+ 'export const rule: Rule.RuleModule = { create() {}, meta: {} };' : {
229
+ create : { type : 'FunctionExpression' } ,
230
+ meta : { type : 'ObjectExpression' } ,
231
+ isNewStyle : true ,
232
+ } ,
233
+ // no helper, exported reference with type.
234
+ 'const rule: Rule.RuleModule = { create() {}, meta: {} }; export {rule};' :
235
+ {
236
+ create : { type : 'FunctionExpression' } ,
237
+ meta : { type : 'ObjectExpression' } ,
238
+ isNewStyle : true ,
239
+ } ,
240
+ // no helper, exported aliased reference with type.
241
+ 'const foo: Rule.RuleModule = { create() {}, meta: {} }; export {foo as rule};' :
242
+ {
243
+ create : { type : 'FunctionExpression' } ,
244
+ meta : { type : 'ObjectExpression' } ,
245
+ isNewStyle : true ,
246
+ } ,
247
+ // no helper, exported variable with type in multiple declarations
248
+ 'export const foo = 5, rule: Rule.RuleModule = { create() {}, meta: {} };' :
249
+ {
250
+ create : { type : 'FunctionExpression' } ,
251
+ meta : { type : 'ObjectExpression' } ,
252
+ isNewStyle : true ,
253
+ } ,
219
254
// No helper, variable, `export =` syntax.
220
255
'const rule = { create() {}, meta: {} }; export = rule;' : {
221
256
create : { type : 'FunctionExpression' } ,
@@ -474,6 +509,16 @@ describe('utils', () => {
474
509
meta : { type : 'ObjectExpression' } ,
475
510
isNewStyle : true ,
476
511
} ,
512
+ 'export const rule = { create() {}, meta: {} };' : {
513
+ create : { type : 'FunctionExpression' } ,
514
+ meta : { type : 'ObjectExpression' } ,
515
+ isNewStyle : true ,
516
+ } ,
517
+ 'const rule = { create() {}, meta: {} }; export {rule};' : {
518
+ create : { type : 'FunctionExpression' } ,
519
+ meta : { type : 'ObjectExpression' } ,
520
+ isNewStyle : true ,
521
+ } ,
477
522
478
523
// ESM (function style)
479
524
'export default function (context) { return {}; }' : {
0 commit comments