Skip to content

Commit b5d4c26

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

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,18 +25,24 @@ 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) {
3537
var filename = context.getFilename();
3638
if (filename === '<text>') {
3739
return;
3840
}
3941

42+
if (invalidNode) {
43+
return;
44+
}
45+
4046
var allowedExtensions = getExtensionsConfig();
4147
var isAllowedExtension = allowedExtensions.some(function (extension) {
4248
return filename.slice(-extension.length) === extension;
@@ -46,11 +52,18 @@ module.exports = function(context) {
4652
return;
4753
}
4854

49-
var extension = path.extname(filename);
55+
invalidNode = node;
56+
invalidExtension = path.extname(filename);
57+
},
58+
59+
'Program:exit': function() {
60+
if (!invalidNode) {
61+
return;
62+
}
5063

5164
context.report({
52-
node: node,
53-
message: 'JSX not allowed in files with extension \'' + extension + '\''
65+
node: invalidNode,
66+
message: 'JSX not allowed in files with extension \'' + invalidExtension + '\''
5467
});
5568
}
5669
};

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)