From 97e0fa1acc8c928353de2d732b05e799c140c407 Mon Sep 17 00:00:00 2001 From: azu Date: Tue, 11 May 2021 12:20:54 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Node.js=2010=E3=81=AE=E3=82=B5=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88[=E3=83=AA=E3=82=B0=E3=83=AC=E3=83=83?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E4=BF=AE=E6=AD=A3]=20(#91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Node.js 10のサポート * refactor: remove unneeded spread --- .github/workflows/test.yml | 2 +- src/util/pair-checker.js | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 170443f..b42b898 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [12, 14] + node-version: [10, 12, 14] steps: - name: checkout uses: actions/checkout@v2 diff --git a/src/util/pair-checker.js b/src/util/pair-checker.js index eabfc75..03ae51c 100644 --- a/src/util/pair-checker.js +++ b/src/util/pair-checker.js @@ -9,6 +9,9 @@ */ import assert from "assert"; import { RuleHelper } from "textlint-rule-helper"; +const flat = (array) => { + return [].concat.apply([], array); +}; export function checkPair(context, { left, right }) { assert(left); assert(right); @@ -36,17 +39,17 @@ export function checkPair(context, { left, right }) { return symbolLocations; }; const foundMissingPairNodes = (currentStrInParagraph) => { - let matchParentheses = currentStrInParagraph - .map((node) => { + const matchParentheses = flat( + currentStrInParagraph.map((node) => { let text = getSource(node); const leftSymbolLocations = findAllSymbolLocations(left, text); const rightSymbolLocations = left !== right ? findAllSymbolLocations(right, text) : []; const allSymbolLocations = [...leftSymbolLocations, ...rightSymbolLocations].sort( (a, b) => a.index - b.index ); - return allSymbolLocations.map((loc) => ({ ...loc, ...{ node } })); + return allSymbolLocations.map((loc) => ({ ...loc, node })); }) - .flat(); + ); if (left === right) { const isCompletedParentheses = matchParentheses.length % 2 == 0; if (isCompletedParentheses) {