Skip to content

Commit

Permalink
feat: add support for custom success/fail message (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
SDAdham committed Jun 27, 2022
1 parent 9b5604e commit 21ae39a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.yml
Expand Up @@ -8,6 +8,11 @@ plugins:

rules:
file-progress/activate: 1
settings:
progress:
hide-progress: false
success-message: "Lint done..."
fail-message: "Lint done with errors."

env:
node: true
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,11 @@ plugins:

rules:
file-progress/activate: 1
settings:
progress:
hide-progress: false
success-message: "Lint done..."
fail-message: "Lint done with errors."
```

### Demo
Expand Down
33 changes: 26 additions & 7 deletions rules/progress.js
Expand Up @@ -7,26 +7,45 @@ const spinner = ora({
});

let bindExit = false;
let initialReportDone = false;

const exitCallback = (exitCode) => {
const exitCallback = (exitCode, settings) => {
if (exitCode === 0) {
spinner.succeed('Lint done...');
spinner.succeed(
settings && typeof settings['success-message'] === 'string'
? settings['success-message']
: 'Lint done...',
);
} else {
spinner.fail(
settings && typeof settings['fail-message'] === 'string'
? settings['fail-message']
: 'Lint done with errors.',
);
}
};

const rootPath = process.cwd();

const create = (context) => {
if (!bindExit) {
process.on('exit', exitCallback);
process.on('exit', (code) => {
exitCallback(code, context.settings);
});
bindExit = true;
}

const filename = context.getFilename();
const relativeFilePath = path.relative(rootPath, filename);
if (!context.settings['hide-progress']) {
const filename = context.getFilename();
const relativeFilePath = path.relative(rootPath, filename);

spinner.text = `Processing: ${chalk.green(relativeFilePath)} \n`;
spinner.render();
spinner.text = `Processing: ${chalk.green(relativeFilePath)} \n`;
spinner.render();
} else if (!initialReportDone) {
spinner.text = 'Linting \n';
spinner.render();
initialReportDone = true;
}

return {};
};
Expand Down
7 changes: 7 additions & 0 deletions test.js
Expand Up @@ -8,6 +8,13 @@ const ruleName = 'file-progress/activate';
ruleTester.run(ruleName, progress, {
valid: [
'var foo = \'bar\'',
{
code: 'var foo = \'bar\'',
settings: {
'hide-progress': true,
'success-message': 'API lint done...',
},
},
],
invalid: [],
});

0 comments on commit 21ae39a

Please sign in to comment.