Skip to content

Commit

Permalink
[fix] jsx-no-useless-fragment: use array-includes over `.includes…
Browse files Browse the repository at this point in the history
…` for back compat
  • Loading branch information
ljharb committed Oct 3, 2019
1 parent a1dee7c commit 6f14e16
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/rules/jsx-no-useless-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

'use strict';

const arrayIncludes = require('array-includes');

const pragmaUtil = require('../util/pragma');
const jsxUtil = require('../util/jsx');
const docsUrl = require('../util/docsUrl');
Expand Down Expand Up @@ -47,8 +49,8 @@ function trimLikeReact(text) {
const leadingSpaces = /^\s*/.exec(text)[0];
const trailingSpaces = /\s*$/.exec(text)[0];

const start = leadingSpaces.includes('\n') ? leadingSpaces.length : 0;
const end = trailingSpaces.includes('\n') ? text.length - trailingSpaces.length : text.length;
const start = arrayIncludes(leadingSpaces, '\n') ? leadingSpaces.length : 0;
const end = arrayIncludes(trailingSpaces, '\n') ? text.length - trailingSpaces.length : text.length;

return text.slice(start, end);
}
Expand Down Expand Up @@ -92,7 +94,7 @@ module.exports = {
function isPaddingSpaces(node) {
return isJSXText(node) &&
isOnlyWhitespace(node.raw) &&
node.raw.includes('\n');
arrayIncludes(node.raw, '\n');
}

/**
Expand Down

0 comments on commit 6f14e16

Please sign in to comment.