Skip to content

Commit fd9c3ab

Browse files
committed
Now only reporting up to once per file for jsx-filename-extension.
1 parent 0497750 commit fd9c3ab

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/rules/jsx-filename-extension.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ module.exports = function(context) {
2525
return context.options[0] && context.options[0].extensions || DEFAULTS.extensions;
2626
}
2727

28+
var invalidExtension;
29+
var invalidNode;
30+
2831
// --------------------------------------------------------------------------
2932
// Public
3033
// --------------------------------------------------------------------------
3134

3235
return {
33-
3436
JSXElement: function(node) {
37+
if (invalidNode) {
38+
return;
39+
}
40+
3541
var allowedExtensions = getExtensionsConfig();
3642
var filename = context.getFilename();
3743

@@ -43,11 +49,18 @@ module.exports = function(context) {
4349
return;
4450
}
4551

46-
var extension = path.extname(filename);
52+
invalidNode = node;
53+
invalidExtension = path.extname(filename);
54+
},
55+
56+
'Program:exit': function() {
57+
if (!invalidNode) {
58+
return;
59+
}
4760

4861
context.report({
49-
node: node,
50-
message: 'JSX not allowed in files with extension \'' + extension + '\''
62+
node: invalidNode,
63+
message: 'JSX not allowed in files with extension \'' + invalidExtension + '\''
5164
});
5265
}
5366
};

tests/lib/rules/jsx-filename-extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var parserOptions = {
2222
// Code Snippets
2323
// ------------------------------------------------------------------------------
2424

25-
var withJSX = 'module.exports = function MyComponent() { return <div />; }';
25+
var withJSX = 'module.exports = function MyComponent() { return <div>\n<div />\n</div>; }';
2626
var withoutJSX = 'module.exports = {}';
2727

2828
// ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)