|
| 1 | +# `eslint-plugin-example-typed-linting` |
| 2 | + |
| 3 | +An example ESLint plugin showing typed linting with `@typescript-eslint/utils`. |
| 4 | + |
| 5 | +For documentation on custom ESLint plugins with typescript-eslint, see: <https://typescript-eslint.io/developers/custom-rules>. |
| 6 | + |
| 7 | +```js |
| 8 | +// eslint.config.js |
| 9 | +import eslint from '@eslint/js'; |
| 10 | +import exampleTypedLinting from 'eslint-plugin-example-typed-linting' |
| 11 | +import tseslint from 'typescript-eslint'; |
| 12 | + |
| 13 | +export default tseslint.config( |
| 14 | + { ignores: ["lib"] }, |
| 15 | + eslint.configs.recommended, |
| 16 | + ...tseslint.configs.recommendedTypeChecked, |
| 17 | + exampleTypedLinting.configs.recommended // 👈 |
| 18 | + { |
| 19 | + languageOptions: { |
| 20 | + parserOptions: { |
| 21 | + projectService:true, |
| 22 | + tsconfigRootDir: import.meta.dirname, |
| 23 | + }, |
| 24 | + }, |
| 25 | + }, |
| 26 | +); |
| 27 | +``` |
| 28 | + |
| 29 | +## Rules |
| 30 | + |
| 31 | +<!-- begin auto-generated rules list --> |
| 32 | + |
| 33 | +💭 Requires [type information](https://typescript-eslint.io/linting/typed-linting). |
| 34 | + |
| 35 | +| Name | Description | 💭 | |
| 36 | +| :----------------------------------------------------- | :------------------------ | :- | |
| 37 | +| [no-loop-over-enums](docs/rules/no-loop-over-enums.md) | Avoid looping over enums. | 💭 | |
| 38 | + |
| 39 | +<!-- end auto-generated rules list --> |
| 40 | + |
| 41 | +## Development |
| 42 | + |
| 43 | +To set up this individual package, `cd` to the path to it, then install dependencies: |
| 44 | + |
| 45 | +```shell |
| 46 | +cd path/to/eslint-plugin-example-typed-linting |
| 47 | +npm i |
| 48 | +``` |
| 49 | + |
| 50 | +Then build files into the `lib` directory with TypeScript: |
| 51 | + |
| 52 | +```shell |
| 53 | +npm run tsc |
| 54 | +``` |
| 55 | + |
| 56 | +You'll then be able to run standard package scripts: |
| 57 | + |
| 58 | +- `npm run docs`: Regenerates documentation using [`eslint-doc-generator`](https://github.com/bmish/eslint-doc-generator) |
| 59 | + - `npm run docs --check`: Validates that documentation is generated and up-to-date. |
| 60 | +- `npm run lint`: Linting this plugin itself with ESLint |
| 61 | + |
| 62 | +### Testing |
| 63 | + |
| 64 | +This example uses [Vitest](https://vitest.dev): |
| 65 | + |
| 66 | +```shell |
| 67 | +npm run test |
| 68 | +``` |
| 69 | + |
| 70 | +Note that files don't need to have been built to the `lib` directory to run tests. |
0 commit comments