Skip to content

Commit

Permalink
feat: pass count of scanned repositories to config.onComplete (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 6, 2021
1 parent 5a3ffa2 commit 814f6f0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ module.exports = {

#### Configuration options

| Name | Description                               | Type | Required | Default | Example |
| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | :----------------- | :------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- |
| `repositories` | Repositories to scan in format of `owner/project`. See [eslint-remote-tester-repositories] for shared list of repositories. | `string[]` | :white_check_mark: | :x: | `['mui-org/material-ui', 'reach/reach-ui']` |
| `extensions` | Extensions of files under scanning | `string[]` | :white_check_mark: | :x: | `['js', 'jsx', 'ts', 'tsx']` |
| `eslintrc` | ESLint configuration | See [Configuring ESLint] | :white_check_mark: | :x: | `{ root: true, extends: ['eslint:all'] }` |
| `pathIgnorePattern` | Regexp pattern string used to exclude paths | `string` | :x: | :x: | `(node_modules\|docs\|\\/\\.git)` |
| `maxFileSizeBytes` | Max file size used to exclude bigger files | `number` | :x: | `2000000` | `1500000` |
| `rulesUnderTesting` | Array of rules or a filter method used to filter out results. Use `undefined` or empty array when ESLint crashes are the only interest. Filter method is called with `ruleId` and `options`. | `string[] \| (ruleId, { repository }) => boolean` | :x: | `[]` | `['no-empty', 'react/sort-prop-types']` `(ruleId, options) => ruleId === 'no-undef' && options.repository === 'owner/repo'` |
| `resultParser` | Syntax for the result parser | `plaintext\|markdown` | :x: | `markdown` on CLI. `plaintext` on CI | `markdown` |
| `concurrentTasks` | Maximum amount of tasks run concurrently | `number` | :x: | `5` | `3` |
| `CI` | Flag used to set CI mode. `process.env.CI` is used when not set. | `boolean` | :x: | value of `process.env.CI === 'true'` | `true` |
| `logLevel` | Filter log messages based on their priority | `verbose\|info\|warn\|error` | :x: | `verbose` | `warn` |
| `cache` | Flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching due to limited disk space. | `boolean` | :x: | `true` | `true` |
| `timeLimit` | Time limit before scan is interrupted and **exited successfully**. Ideal for avoiding CI timeouts in regression tests. | `number` | :x: | `5.5 * 60 * 60, // 5 hours 30 minutes` | `5 * 60 * 60 // 5 hours` |
| `compare` | Flag used to enable result comparison mode. Compares results of two scans and output the diff. Ideal for identifying new false positives when fixing existing rules. See [Fixing existing rules]. | `boolean` | :x: | `false` | `true` |
| `updateComparisonReference` | Flag used to enable result comparison reference updating. Indicates whether comparison base should be updated after scan has finished. Ideal to be turned off once initial comparison base has been collected. | `boolean` | :x: | `true` | `true` |
| `onComplete` | Callback invoked once scan is completed. Asynchronous functions are supported. Ideal for extending the process with custom features. | `(results, comparisonResults) => void`\|`Promise<void>`. See [onComplete example]. | :x: | :x: | `async (results, comparisonResults) => {}` |
| Name | Description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Required | Default | Example |
| :-------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------- | :----------------- | :------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- |
| `repositories` | Repositories to scan in format of `owner/project`. See [eslint-remote-tester-repositories] for shared list of repositories. | `string[]` | :white_check_mark: | :x: | `['mui-org/material-ui', 'reach/reach-ui']` |
| `extensions` | Extensions of files under scanning | `string[]` | :white_check_mark: | :x: | `['js', 'jsx', 'ts', 'tsx']` |
| `eslintrc` | ESLint configuration | See [Configuring ESLint] | :white_check_mark: | :x: | `{ root: true, extends: ['eslint:all'] }` |
| `pathIgnorePattern` | Regexp pattern string used to exclude paths | `string` | :x: | :x: | `(node_modules\|docs\|\\/\\.git)` |
| `maxFileSizeBytes` | Max file size used to exclude bigger files | `number` | :x: | `2000000` | `1500000` |
| `rulesUnderTesting` | Array of rules or a filter method used to filter out results. Use `undefined` or empty array when ESLint crashes are the only interest. Filter method is called with `ruleId` and `options`. | `string[] \| (ruleId, { repository }) => boolean` | :x: | `[]` | `['no-empty', 'react/sort-prop-types']` `(ruleId, options) => ruleId === 'no-undef' && options.repository === 'owner/repo'` |
| `resultParser` | Syntax for the result parser | `plaintext\|markdown` | :x: | `markdown` on CLI. `plaintext` on CI | `markdown` |
| `concurrentTasks` | Maximum amount of tasks run concurrently | `number` | :x: | `5` | `3` |
| `CI` | Flag used to set CI mode. `process.env.CI` is used when not set. | `boolean` | :x: | value of `process.env.CI === 'true'` | `true` |
| `logLevel` | Filter log messages based on their priority | `verbose\|info\|warn\|error` | :x: | `verbose` | `warn` |
| `cache` | Flag used to enable caching of cloned repositories. For CIs it's ideal to disable caching due to limited disk space. | `boolean` | :x: | `true` | `true` |
| `timeLimit` | Time limit before scan is interrupted and **exited successfully**. Ideal for avoiding CI timeouts in regression tests. | `number` | :x: | `5.5 * 60 * 60, // 5 hours 30 minutes` | `5 * 60 * 60 // 5 hours` |
| `compare` | Flag used to enable result comparison mode. Compares results of two scans and output the diff. Ideal for identifying new false positives when fixing existing rules. See [Fixing existing rules]. | `boolean` | :x: | `false` | `true` |
| `updateComparisonReference` | Flag used to enable result comparison reference updating. Indicates whether comparison base should be updated after scan has finished. Ideal to be turned off once initial comparison base has been collected. | `boolean` | :x: | `true` | `true` |
| `onComplete` | Callback invoked once scan is completed. Asynchronous functions are supported. Ideal for extending the process with custom features. | `(results, comparisonResults, repositoryCount) => void`\|`Promise<void>`. See [onComplete example]. | :x: | :x: | `async (results, comparisonResults, repositoryCount) => {}` |

[configuring eslint]: https://eslint.org/docs/user-guide/configuring
[fixing existing rules]: #fixing-existing-rules
Expand Down
3 changes: 2 additions & 1 deletion docs/onComplete-arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
"source": " 5 | \n 6 | new Vue({\n> 7 | render: h => h(App),\n | ^\n 8 | }).$mount('#app')\n 9 | "
}
]
}
},
"repositoryCount": 123
}
3 changes: 2 additions & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export interface Config {
updateComparisonReference: boolean;
onComplete?: (
results: Result[],
comparisonResults: ComparisonResults | null
comparisonResults: ComparisonResults | null,
repositoryCount: number
) => Promise<void> | void;
}

Expand Down
7 changes: 5 additions & 2 deletions lib/progress-logger/exit-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { LogMessage } from './types';
/**
* Callback invoked once scan is complete and application is about to exit
*/
export default async function onExit(): Promise<LogMessage[]> {
export default async function onExit(
scannedRepositories: number
): Promise<LogMessage[]> {
const messages: LogMessage[] = [];
const errors = [];

Expand Down Expand Up @@ -43,7 +45,8 @@ export default async function onExit(): Promise<LogMessage[]> {
try {
const onCompletePromise = config.onComplete(
results,
comparisonResults
comparisonResults,
scannedRepositories
);

if (onCompletePromise instanceof Promise) {
Expand Down
6 changes: 3 additions & 3 deletions lib/progress-logger/progress-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ class ProgressLogger {
const notifyListeners = () =>
this.listeners.exit.forEach(listener => listener());

// Erroneous exit handler should not crash whole application.
// Log the error and move on.
exitHandler()
exitHandler(this.scannedRepositories)
.then(messages => {
messages.forEach(message => this.addNewMessage(message));
notifyListeners();
})
.catch(error => {
// Erroneous exit handler should not crash whole application.
// Log the error and move on.
console.error(error);
notifyListeners();
});
Expand Down

0 comments on commit 814f6f0

Please sign in to comment.