Skip to content

Commit

Permalink
Only reporting up to once per file for jsx-filename-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieumg authored and yannickcr committed Jul 23, 2016
1 parent f9ea195 commit 0f4ec75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/rules/jsx-filename-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ module.exports = function(context) {
return context.options[0] && context.options[0].extensions || DEFAULTS.extensions;
}

var invalidExtension;
var invalidNode;

// --------------------------------------------------------------------------
// Public
// --------------------------------------------------------------------------

return {

JSXElement: function(node) {
var filename = context.getFilename();
if (filename === '<text>') {
return;
}

if (invalidNode) {
return;
}

var allowedExtensions = getExtensionsConfig();
var isAllowedExtension = allowedExtensions.some(function (extension) {
return filename.slice(-extension.length) === extension;
Expand All @@ -46,11 +52,18 @@ module.exports = function(context) {
return;
}

var extension = path.extname(filename);
invalidNode = node;
invalidExtension = path.extname(filename);
},

'Program:exit': function() {
if (!invalidNode) {
return;
}

context.report({
node: node,
message: 'JSX not allowed in files with extension \'' + extension + '\''
node: invalidNode,
message: 'JSX not allowed in files with extension \'' + invalidExtension + '\''
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/jsx-filename-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var parserOptions = {
// Code Snippets
// ------------------------------------------------------------------------------

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

// ------------------------------------------------------------------------------
Expand Down

0 comments on commit 0f4ec75

Please sign in to comment.