From 2fbbbfbec720492d3bcfa96c6e309a2b599f62e2 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Nov 2022 12:34:36 +0800 Subject: [PATCH 1/5] Improve `lintFiles` --- index.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 44e77b22..cc70c328 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ const lintText = async (string, options) => { filePath && ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - || isGitIgnoredSync({cwd, ignore: ignorePatterns})(filePath) + || isGitIgnoredSync({cwd})(filePath) ) ) { return getIgnoredReport(filePath); @@ -87,16 +87,11 @@ const lintFiles = async (patterns, options) => { for (const options of filesWithOptions) { const {filePath, eslintOptions} = options; const {cwd, baseConfig: {ignorePatterns}} = eslintOptions; - if (filePath - && ( - micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - || isGitIgnoredSync({cwd, ignore: ignorePatterns})(filePath) - )) { - continue; - } - - // eslint-disable-next-line no-await-in-loop - if ((await eslint.isPathIgnored(filePath))) { + if ( + micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) + // eslint-disable-next-line no-await-in-loop + || (await eslint.isPathIgnored(filePath)) + ) { continue; } From 1d08d34ccae7b3acc9aec8c0122c7bf759e6964f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Nov 2022 12:45:18 +0800 Subject: [PATCH 2/5] Use async version --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cc70c328..fabc5c2d 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ import path from 'node:path'; import {ESLint} from 'eslint'; -import {globby, isGitIgnoredSync} from 'globby'; +import {globby, isGitIgnored} from 'globby'; import {isEqual} from 'lodash-es'; import micromatch from 'micromatch'; import arrify from 'arrify'; @@ -53,7 +53,7 @@ const lintText = async (string, options) => { filePath && ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - || isGitIgnoredSync({cwd})(filePath) + || (await isGitIgnored({cwd})(filePath)) ) ) { return getIgnoredReport(filePath); From 4c419e84d6622e33d4e83ff60d45cf7f52d3416a Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Nov 2022 12:49:17 +0800 Subject: [PATCH 3/5] Remove unnecessary parens --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fabc5c2d..6bc95293 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ const lintText = async (string, options) => { filePath && ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - || (await isGitIgnored({cwd})(filePath)) + || await isGitIgnored({cwd})(filePath) ) ) { return getIgnoredReport(filePath); @@ -90,7 +90,7 @@ const lintFiles = async (patterns, options) => { if ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) // eslint-disable-next-line no-await-in-loop - || (await eslint.isPathIgnored(filePath)) + || await eslint.isPathIgnored(filePath) ) { continue; } From b24693abef7ba30f67646a0461913584e10cca78 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Nov 2022 12:52:19 +0800 Subject: [PATCH 4/5] Fix --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6bc95293..62cb6a9d 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ import path from 'node:path'; import {ESLint} from 'eslint'; -import {globby, isGitIgnored} from 'globby'; +import {globby, isGitIgnoredSync} from 'globby'; import {isEqual} from 'lodash-es'; import micromatch from 'micromatch'; import arrify from 'arrify'; @@ -53,7 +53,8 @@ const lintText = async (string, options) => { filePath && ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - || await isGitIgnored({cwd})(filePath) + // TODO: Use async version when `globby` fix `isGitIgnored` + || isGitIgnoredSync({cwd})(filePath) ) ) { return getIgnoredReport(filePath); From a4c491fedabdb667197001b7dcbd7de187c3d3f7 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 17 Nov 2022 13:14:24 +0800 Subject: [PATCH 5/5] remove todo --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index 62cb6a9d..afc541ed 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,6 @@ const lintText = async (string, options) => { filePath && ( micromatch.isMatch(path.relative(cwd, filePath), ignorePatterns) - // TODO: Use async version when `globby` fix `isGitIgnored` || isGitIgnoredSync({cwd})(filePath) ) ) {