Skip to content

Commit 8594af0

Browse files
aengelbergweb-flow
andauthored
Add fixer-level "ignore" option, fix file filtering in custom fixers (#19)
--------- Co-authored-by: Fix-it Felix[bot] <[email protected]>
1 parent d9fcbcb commit 8594af0

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed

.felixrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"fixers": ["eslint", "prettier"],
2+
"fixers": ["eslint", "prettier", "wc"],
33
"paths": ["src/**", "examples/**", "tests/**", "*.md", "jest.config.js", "test-felix.js"],
44
"ignore": ["node_modules/**", "dist/**", "build/**", ".git/**", "coverage/**", "test-files/**", "package.json", "package-lock.json", ".github/**"],
55
"_comment": "Using custom commands to demonstrate the feature. In production, ensure 'npm ci' runs before Felix.",
@@ -10,5 +10,10 @@
1010
"prettier": {
1111
"command": ["npm", "run", "format:fix"],
1212
"appendPaths": false
13+
},
14+
"wc": {
15+
"command": ["wc", "-l"],
16+
"ignore": [".felixrc.json"],
17+
"paths": ["."]
1318
}
1419
}

dist/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30021,6 +30021,12 @@ class ConfigManager {
3002130021
getIgnorePatterns() {
3002230022
return this.config.ignore || ['node_modules/**', 'dist/**', 'build/**', '.git/**'];
3002330023
}
30024+
getFixerIgnorePatterns(fixerName) {
30025+
const globalIgnores = this.getIgnorePatterns();
30026+
const fixerConfig = this.getFixerConfig(fixerName);
30027+
const localIgnores = Array.isArray(fixerConfig.ignore) ? fixerConfig.ignore : [];
30028+
return [...globalIgnores, ...localIgnores];
30029+
}
3002430030
getFixerConfig(fixerName) {
3002530031
return this.config[fixerName] || {};
3002630032
}
@@ -30602,6 +30608,8 @@ To apply these fixes, remove the \`dry_run: true\` option from your workflow.`;
3060230608
return this.config.getPaths();
3060330609
}
3060430610
filterFilesByFixer(files, fixerName, fixerConfig, configuredPaths) {
30611+
// Gather ignore patterns (global + fixer-level)
30612+
const ignorePatterns = this.config.getFixerIgnorePatterns(fixerName);
3060530613
// Get the extensions this fixer handles
3060630614
let extensions = [];
3060730615
switch (fixerName) {
@@ -30644,16 +30652,27 @@ To apply these fixes, remove the \`dry_run: true\` option from your workflow.`;
3064430652
extensions = fixerConfig.extensions || ['.md', '.markdown'];
3064530653
break;
3064630654
default:
30647-
return files;
30655+
extensions = fixerConfig.extensions || [];
30656+
break;
3064830657
}
30658+
const isIgnored = (filePath) => {
30659+
return ignorePatterns.some(pattern => (0, minimatch_1.minimatch)(filePath, pattern));
30660+
};
3064930661
if (this.inputs.debug) {
3065030662
core.info(`🔍 Debug: Filtering ${files.length} files for ${fixerName}`);
3065130663
core.info(`🔍 Debug: Extensions: ${extensions.join(', ')}`);
30664+
core.info(`🔍 Debug: Ignore patterns (${ignorePatterns.length}): ${ignorePatterns.join(', ')}`);
3065230665
core.info(`🔍 Debug: Configured paths: ${configuredPaths.join(', ')}`);
3065330666
}
3065430667
const filteredFiles = files.filter(file => {
3065530668
const ext = path.extname(file).toLowerCase();
30656-
if (!extensions.includes(ext)) {
30669+
if (isIgnored(file)) {
30670+
if (this.inputs.debug) {
30671+
core.info(`🔍 Debug: Excluded ${file}: matches ignore patterns`);
30672+
}
30673+
return false;
30674+
}
30675+
if (extensions.length > 0 && !extensions.includes(ext)) {
3065730676
if (this.inputs.debug) {
3065830677
core.info(`🔍 Debug: Excluded ${file}: extension ${ext} not in allowed extensions`);
3065930678
}
@@ -31305,7 +31324,7 @@ class PrettierFixer extends base_1.BaseFixer {
3130531324
if (!this.configManager) {
3130631325
return paths;
3130731326
}
31308-
const ignorePatterns = this.configManager.getIgnorePatterns();
31327+
const ignorePatterns = this.configManager.getFixerIgnorePatterns(this.name);
3130931328
return paths.filter(path => {
3131031329
const cleanPath = path.endsWith('/') ? path.slice(0, -1) : path;
3131131330
// Check if this path matches any ignore pattern

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export class ConfigManager {
7070
return this.config.ignore || ['node_modules/**', 'dist/**', 'build/**', '.git/**']
7171
}
7272

73+
getFixerIgnorePatterns(fixerName: string): string[] {
74+
const globalIgnores = this.getIgnorePatterns()
75+
const fixerConfig = this.getFixerConfig(fixerName)
76+
const localIgnores = Array.isArray(fixerConfig.ignore) ? fixerConfig.ignore : []
77+
return [...globalIgnores, ...localIgnores]
78+
}
79+
7380
getFixerConfig(fixerName: string): any {
7481
return this.config[fixerName as keyof FelixConfig] || {}
7582
}

src/felix.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ To apply these fixes, remove the \`dry_run: true\` option from your workflow.`
607607
fixerConfig: any,
608608
configuredPaths: string[]
609609
): string[] {
610+
// Gather ignore patterns (global + fixer-level)
611+
const ignorePatterns = this.config.getFixerIgnorePatterns(fixerName)
612+
610613
// Get the extensions this fixer handles
611614
let extensions: string[] = []
612615

@@ -650,19 +653,34 @@ To apply these fixes, remove the \`dry_run: true\` option from your workflow.`
650653
extensions = fixerConfig.extensions || ['.md', '.markdown']
651654
break
652655
default:
653-
return files
656+
extensions = fixerConfig.extensions || []
657+
break
658+
}
659+
660+
const isIgnored = (filePath: string): boolean => {
661+
return ignorePatterns.some(pattern => minimatch(filePath, pattern))
654662
}
655663

656664
if (this.inputs.debug) {
657665
core.info(`🔍 Debug: Filtering ${files.length} files for ${fixerName}`)
658666
core.info(`🔍 Debug: Extensions: ${extensions.join(', ')}`)
667+
core.info(
668+
`🔍 Debug: Ignore patterns (${ignorePatterns.length}): ${ignorePatterns.join(', ')}`
669+
)
659670
core.info(`🔍 Debug: Configured paths: ${configuredPaths.join(', ')}`)
660671
}
661672

662673
const filteredFiles = files.filter(file => {
663674
const ext = path.extname(file).toLowerCase()
664675

665-
if (!extensions.includes(ext)) {
676+
if (isIgnored(file)) {
677+
if (this.inputs.debug) {
678+
core.info(`🔍 Debug: Excluded ${file}: matches ignore patterns`)
679+
}
680+
return false
681+
}
682+
683+
if (extensions.length > 0 && !extensions.includes(ext)) {
666684
if (this.inputs.debug) {
667685
core.info(`🔍 Debug: Excluded ${file}: extension ${ext} not in allowed extensions`)
668686
}

src/fixers/prettier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class PrettierFixer extends BaseFixer {
3232
return paths
3333
}
3434

35-
const ignorePatterns = this.configManager.getIgnorePatterns()
35+
const ignorePatterns = this.configManager.getFixerIgnorePatterns(this.name)
3636
return paths.filter(path => {
3737
const cleanPath = path.endsWith('/') ? path.slice(0, -1) : path
3838

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ export interface FelixConfig {
2121
paths?: string[]
2222
command?: string[]
2323
appendPaths?: boolean
24+
ignore?: string[]
2425
}
2526
prettier?: {
2627
configFile?: string
2728
extensions?: string[]
2829
paths?: string[]
2930
command?: string[]
3031
appendPaths?: boolean
32+
ignore?: string[]
3133
}
3234
markdownlint?: {
3335
configFile?: string
3436
paths?: string[]
3537
command?: string[]
3638
appendPaths?: boolean
39+
ignore?: string[]
3740
}
3841
}
3942

0 commit comments

Comments
 (0)