Skip to content

Commit

Permalink
refactor: avoid duplicate implementation for isJSXText
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Jul 12, 2019
1 parent 01eb97e commit 7425244
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/rules/jsx-no-useless-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const pragmaUtil = require('../util/pragma');
const jsxUtil = require('../util/jsx');
const docsUrl = require('../util/docsUrl');

function isJSXText(node) {
return !!node && (node.type === 'JSXText' || node.type === 'Literal');
}

module.exports = {
meta: {
Expand Down Expand Up @@ -34,7 +37,7 @@ module.exports = {
* @returns {boolean}
*/
function isPaddingSpaces(node) {
return (node.type === 'JSXText' || node.type === 'Literal')
return isJSXText(node)
&& /^\s*$/.test(node.raw)
&& node.raw.includes('\n');
}
Expand Down Expand Up @@ -65,10 +68,6 @@ module.exports = {
&& /^[a-z]+$/.test(node.parent.openingElement.name.name);
}

function isJSXText(node) {
return !!node && (node.type === 'JSXText' || node.type === 'Literal');
}

/**
* Avoid fixing case like:
* ```jsx
Expand Down

0 comments on commit 7425244

Please sign in to comment.