diff --git a/README.md b/README.md index 983a84a2..c9b8e845 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Add new script to your `package.json` file. Create new configuration file `eslint-remote-tester.config.js` in the root of your project. This is used as configuration file by default. Use `-c` or `--config` argument for custom configuration file, e.g. `--config path/custom.config.js`. ```js +/** @type {import('eslint-remote-tester').Config} */ module.exports = { repositories: ['mui-org/material-ui', 'reach/reach-ui'], extensions: ['js', 'jsx', 'ts', 'tsx'], @@ -75,6 +76,23 @@ module.exports = { }; ``` +Configuration file can also be written in TypeScript if [`ts-node`](https://www.npmjs.com/package/ts-node) is installed. Use `--config` argument for TypeScript configuration file, e.g. `--config eslint-remote-tester.config.ts`. + +```ts +import type { Config } from 'eslint-remote-tester'; + +const config: Config = { + repositories: ['mui-org/material-ui', 'reach/reach-ui'], + extensions: ['js', 'jsx', 'ts', 'tsx'], + eslintrc: { + root: true, + extends: ['eslint:recommended'], + }, +}; + +export default config; +``` + #### Configuration options | Name | Description                               | Type | Required | Default | Example | diff --git a/lib/config/types.ts b/lib/config/types.ts index 4320a7e5..e52a8a18 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -14,27 +14,81 @@ export type LogLevel = typeof LogLevels[number]; /** Internal config typings after defaults have been set */ export interface Config { + /** Repositories to scan in format of `owner/project` */ repositories: string[]; + + /** Extensions of files under scanning */ extensions: string[]; + + /** Regexp pattern string used to exclude paths */ pathIgnorePattern?: RegExp; + + /** Max file size used to exclude bigger files */ maxFileSizeBytes: number; + + /** + * Array of rules or a filter method used to filter out results. + * Use `undefined` or empty array when ESLint crashes are the only interest. + */ rulesUnderTesting: | string[] | ((ruleId: string, options: { repository: string }) => boolean); + + /** Syntax for the result parser */ resultParser: ResultParser; + + /** Maximum amount of tasks run concurrently */ concurrentTasks: number; + + /** + * ESLint configuration. + * Supports lazy initialization based on currently tested repository when a function is passed. + * Function is called with current repository and its location on filesystem. + */ eslintrc: | Linter.Config | ((options?: { repository: string; location: string; }) => Linter.Config); + + /** Flag used to set CI mode. `process.env.CI` is used when not set. */ CI: boolean; + + /** Filter log messages based on their priority */ logLevel: LogLevel; + + /** + * Flag used to enable caching of cloned repositories. + * For CIs it's ideal to disable caching due to limited disk space. + */ cache: boolean; + + /** + * Time limit before scan is interrupted and **exited successfully**. + * Ideal for avoiding CI timeouts in regression tests. + */ timeLimit: number; + + /** + * 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. + */ compare: boolean; + + /** + * 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. + */ updateComparisonReference: boolean; + + /** + * Callback invoked once scan is completed. + * Asynchronous functions are supported. + * Ideal for extending the process with custom features. + */ onComplete?: ( results: Result[], comparisonResults: ComparisonResults | null, diff --git a/lib/types.ts b/lib/types.ts new file mode 100644 index 00000000..c1469f9e --- /dev/null +++ b/lib/types.ts @@ -0,0 +1,18 @@ +/* + * Typings exported as part of public API + */ + +import type { ConfigWithOptionals } from '@config/types'; + +/** + * Configuration for `eslint-remote-tester.config.ts` + */ +interface Config extends Omit { + /** Regexp pattern string used to exclude paths */ + pathIgnorePattern?: Exclude< + ConfigWithOptionals['pathIgnorePattern'], + RegExp + >; +} + +export type { Config }; diff --git a/package.json b/package.json index f3befbf1..1602efc6 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "files": [ "dist" ], + "types": "dist/types.d.ts", "bin": { "eslint-remote-tester": "dist/index.js" },