Skip to content

Commit

Permalink
Now 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 committed Jul 5, 2016
1 parent 0497750 commit fd9c3ab
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,13 +25,19 @@ module.exports = function(context) {
return context.options[0] && context.options[0].extensions || DEFAULTS.extensions;
}

var invalidExtension;
var invalidNode;

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

return {

JSXElement: function(node) {
if (invalidNode) {
return;
}

var allowedExtensions = getExtensionsConfig();
var filename = context.getFilename();

Expand All @@ -43,11 +49,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 fd9c3ab

Please sign in to comment.