Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat: improve rule schemas, add test to validate schemas, add tooling to generate schema types#6899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
036ee57
deee1e9
2129e39
ddeb0f6
dd3fb3d
e7b686c
d396ce9
e67b3bf
2e1e0fc
455f077
27fe656
9184e36
6d57bbe
6ffbee8
0d8c5cc
d3389f7
f02d485
f113341
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -71,6 +71,42 @@ See our docs on [type aware linting](./Typed_Linting.mdx) for more information. | ||
You're using an outdated version of `@typescript-eslint/parser`. | ||
Update to the latest version to see a more informative version of this error message, explained [above](#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file 'backlink to I get errors telling me ESLint was configured to run ...'). | ||
## How do I turn on a `@typescript-eslint` rule? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Meant for another PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Intentionally added as part of cleaning up the holistic docs update in this PR. | ||
First make sure you've read the docs and understand ESLint configuration files: | ||
- [Read our getting started guide](../Getting_Started.mdx) to ensure your config is properly setup to start configuring our rules. | ||
- [Checkout ESLint's documentation on configuring rules](https://eslint.org/docs/latest/use/configure/rules) to ensure you understand how to configure rules. | ||
Our [rule docs](/rules) detail the options each rule supports under the "Options" heading. | ||
We use TypeScript types to describe an `Options` tuple type for the rule which you can use to configure the a rule. | ||
In your config file the keys of the `rules` object are the names of the rules you wish to configure and the values follow the following form: | ||
```ts | ||
type Severity = 'off' | 'warn' | 'error'; | ||
type RuleConfig = | ||
| Severity | ||
| [Severity] | ||
| [ | ||
Severiy, | ||
// Options is the tuple type from the rule docs | ||
...Options, | ||
]; | ||
``` | ||
Some examples | ||
```js title=".eslintrc.js" | ||
module.exports = { | ||
rules: { | ||
// turns a rule on with no configuration (i.e. uses the default configuration) | ||
'@typescript-eslint/array-type': 'error', | ||
// turns on a rule with configuration | ||
'@typescript-eslint/no-explicit-any': ['warn', { ignoreRestArgs: true }], | ||
}, | ||
}; | ||
``` | ||
## I use a framework (like Vue) that requires custom file extensions, and I get errors like "You should add `parserOptions.extraFileExtensions` to your config" | ||
You can use `parserOptions.extraFileExtensions` to specify an array of non-TypeScript extensions to allow, for example: | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,7 +6,7 @@ import * as util from '../util'; | ||
type Types = Record< | ||
string, | ||
| null | ||
|boolean | ||
| string | ||
| { | ||
message: string; | ||
@@ -35,9 +35,9 @@ function stringifyNode( | ||
} | ||
function getCustomMessage( | ||
bannedType: null |true |string | { message?: string; fixWith?: string }, | ||
): string { | ||
if (bannedType == null || bannedType === true) { | ||
bradzacher marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return ''; | ||
} | ||
@@ -140,28 +140,57 @@ export default util.createRule<Options, MessageIds>({ | ||
}, | ||
schema: [ | ||
{ | ||
$defs: { | ||
banConfig: { | ||
oneOf: [ | ||
{ | ||
type: 'null', | ||
description: 'Bans the type with the default message', | ||
}, | ||
{ | ||
enum: [false], | ||
description: | ||
'Un-bans the type (useful when paired with `extendDefaults`)', | ||
}, | ||
{ | ||
enum: [true], | ||
description: 'Bans the type with the default message', | ||
}, | ||
{ | ||
type: 'string', | ||
description: 'Bans the type with a custom message', | ||
}, | ||
{ | ||
type: 'object', | ||
description: 'Bans a type', | ||
properties: { | ||
message: { | ||
type: 'string', | ||
description: 'Custom error message', | ||
}, | ||
fixWith: { | ||
type: 'string', | ||
description: | ||
'Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.', | ||
}, | ||
suggest: { | ||
type: 'array', | ||
items: { type: 'string' }, | ||
description: 'Types to suggest replacing with.', | ||
additionalItems: false, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
}, | ||
}, | ||
type: 'object', | ||
properties: { | ||
types: { | ||
type: 'object', | ||
additionalProperties: { | ||
$ref: '#/items/0/$defs/banConfig', | ||
}, | ||
}, | ||
extendDefaults: { | ||
Uh oh!
There was an error while loading.Please reload this page.