Skip to content

Commit

Permalink
Add support for ignore-patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jul 16, 2023
1 parent 092e376 commit 2b3a054
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ jobs:
- uses: ./
with:
extensions: 'js,ts'
ignore-patterns: dist/
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ inputs:
ignore-file:
description: Path to ignore file.
required: false
ignore-patterns:
description: Patterns to ignore. Similar to eslint ignorePatterns
required: false
7 changes: 7 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Inputs {
rootDir: string;
extensions: string[];
ignoreFile: string;
ignorePatterns: string[];
}

export const runEslint = async (inputs: Inputs): Promise<void> => {
Expand All @@ -39,6 +40,14 @@ export const runEslint = async (inputs: Inputs): Promise<void> => {
}
}

if (inputs.ignorePatterns.length > 0) {
startGroup('Using ignore pattern, filtering files changed.');
inputs.ignorePatterns.forEach((pattern) => info(`- ${pattern}`));
endGroup();

ig.add(inputs.ignorePatterns);
}

const files = changedFiles
.filter((filename) => {
const isFileSupported = inputs.extensions.find((ext) => filename.endsWith(`.${ext}`));
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setFailed, getInput, getBooleanInput } from '@actions/core';
import { setFailed, getInput, getBooleanInput, getMultilineInput } from '@actions/core';

import { Inputs, runEslint } from './eslint';

Expand All @@ -11,6 +11,7 @@ const run = async ():Promise<void> => {
rootDir: getInput('root-dir'),
extensions: getInput('extensions').split(',').map((ext) => ext.trim()),
ignoreFile: getInput('ignore-file'),
ignorePatterns: getMultilineInput('ignore-patterns'),
};

await runEslint(inputs);
Expand Down

0 comments on commit 2b3a054

Please sign in to comment.