Skip to content

Commit 7cecd01

Browse files
authored
Merge pull request #527 from wayofdev/feat/526-upgrade-concatFilesForPrettier-func
2 parents e4e4ab8 + 629e9af commit 7cecd01

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wayofdev/lint-staged-config": minor
3+
---
4+
5+
Updated concatFilesForPrettier function from lint-staged-config to allow ignore files

packages/lint-staged-config/src/common.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,24 @@ const eslintGlobalRulesForFix = [
3232
* Lint-staged command for running eslint in packages or apps.
3333
* @param {{cwd: string, files: string[], fix: boolean, fixType?: ('problem'|'suggestion'|'layout'|'directive')[], cache: boolean, rules?: string[], maxWarnings?: number}} params
3434
*/
35-
const getEslintFixCmd = ({ cwd, files, rules, fix, fixType, cache, maxWarnings }) => {
35+
const getEslintFixCmd = ({
36+
cwd,
37+
files,
38+
rules,
39+
fix,
40+
fixType,
41+
cache,
42+
maxWarnings,
43+
}) => {
3644
const cliRules = [...(rules ?? []), ...eslintGlobalRulesForFix]
3745
.filter(rule => rule.trim().length > 0)
3846
.map(r => `"${r.trim()}"`)
3947

4048
// For lint-staged it's safer to not apply the fix command if it changes the AST
4149
// @see https://eslint.org/docs/user-guide/command-line-interface#--fix-type
42-
const cliFixType = [...(fixType ?? ['layout'])].filter(type => type.trim().length > 0)
50+
const cliFixType = [...(fixType ?? ['layout'])].filter(
51+
type => type.trim().length > 0
52+
)
4353

4454
const args = [
4555
cache ? '--cache' : '',
@@ -64,10 +74,17 @@ const getEslintFixCmd = ({ cwd, files, rules, fix, fixType, cache, maxWarnings }
6474
* @link https://github.com/okonet/lint-staged/issues/676
6575
*
6676
* @param {string[]} filenames
77+
* @param {string[]} [ignoreFilenames]
6778
* @returns {string} Return concatenated and escaped filenames
6879
*/
69-
const concatFilesForPrettier = filenames =>
70-
filenames.map(filename => `"${isWin ? filename : escape([filename])}"`).join(' ')
80+
const concatFilesForPrettier = (filenames, ignoreFilenames = []) =>
81+
filenames
82+
.filter(
83+
filename =>
84+
!ignoreFilenames.includes(filename.split('/').slice(-1)[0] || '')
85+
)
86+
.map(filename => `"${isWin ? filename : escape([filename])}"`)
87+
.join(' ')
7188

7289
const concatFilesForStylelint = concatFilesForPrettier
7390

0 commit comments

Comments
 (0)