Skip to content

Commit

Permalink
feat: export configuration types (#321)
Browse files Browse the repository at this point in the history
* feat: export `config` typings as part of public API

* docs: typescript configuration file instructions
  • Loading branch information
AriPerkkio committed Dec 30, 2021
1 parent b5f1252 commit 3d8bee0
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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 |
Expand Down
54 changes: 54 additions & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -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<ConfigWithOptionals, 'pathIgnorePattern'> {
/** Regexp pattern string used to exclude paths */
pathIgnorePattern?: Exclude<
ConfigWithOptionals['pathIgnorePattern'],
RegExp
>;
}

export type { Config };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"files": [
"dist"
],
"types": "dist/types.d.ts",
"bin": {
"eslint-remote-tester": "dist/index.js"
},
Expand Down

0 comments on commit 3d8bee0

Please sign in to comment.