Skip to content

Commit

Permalink
Add support for ignore-file
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jul 16, 2023
1 parent 3cb3ba9 commit d9bb279
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ inputs:
description: Path to project containing npm/yarn installation
required: false
default: ''
ignore-file:
description: Path to ignore file.
required: false
default: ''
13 changes: 10 additions & 3 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.

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

export const runEslint = async (inputs: Inputs): Promise<void> => {
Expand All @@ -28,9 +29,14 @@ export const runEslint = async (inputs: Inputs): Promise<void> => {
endGroup();

const ig = ignore();
if (fs.existsSync('.eslintignore')) {
notice('Found .eslintignore, filtering files changed.');
ig.add(fs.readFileSync('.eslintignore', 'utf8').toString());
if (inputs.ignoreFile) {
if (fs.existsSync(inputs.ignoreFile)) {
info(`Using ignore file ${inputs.ignoreFile}, filtering files changed.`);
const ignoreFileContent = await fs.promises.readFile(inputs.ignoreFile, 'utf-8');
ig.add(ignoreFileContent);
} else {
notice(`Provided ignore file ${inputs.ignoreFile} doesn't exist. Skipping...`);
}
}

const files = changedFiles
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const run = async ():Promise<void> => {
eslintArgs: getInput('eslint-args').split(' '),
rootDir: getInput('root-dir'),
extensions: getInput('extensions').split(',').map((ext) => ext.trim()),
ignoreFile: getInput('ignore-file'),
};

await runEslint(inputs);
Expand Down

0 comments on commit d9bb279

Please sign in to comment.