diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f6904d879de..3e2d0e9dd51c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,10 +93,13 @@ jobs: - name: Check code formatting run: yarn format-check - - name: Run linting + - name: Lint code run: yarn lint - - name: Validate spelling + - name: Lint markdown + run: yarn lint:markdown + + - name: Check spelling run: yarn check:spelling integration_tests: diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 000000000000..77f01355394d --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,95 @@ +{ + "default": false, + + // MD001/heading-increment/header-increment - Heading levels should only increment by one level at a time + "MD001": true, + // MD002/first-heading-h1/first-header-h1 - First heading should be a top level heading + "MD002": false, + // MD003/heading-style/header-style - Heading style + "MD003": false, + // MD004/ul-style - Unordered list style + "MD004": false, + // MD005/list-indent - Inconsistent indentation for list items at the same level + "MD005": false, + // MD006/ul-start-left - Consider starting bulleted lists at the beginning of the line + "MD006": false, + // MD007/ul-indent - Unordered list indentation + "MD007": false, + // MD009/no-trailing-spaces - Trailing spaces + "MD009": false, + // MD010/no-hard-tabs - Hard tabs + "MD010": false, + // MD011/no-reversed-links - Reversed link syntax + "MD011": true, + // MD012/no-multiple-blanks - Multiple consecutive blank lines + "MD012": false, + // MD013/line-length - Line length + "MD013": { "line_length": 99999 }, // no line length + // MD014/commands-show-output - Dollar signs used before commands without showing output + "MD014": false, + // MD018/no-missing-space-atx - No space after hash on atx style heading + "MD018": true, + // MD019/no-multiple-space-atx - Multiple spaces after hash on atx style heading + "MD019": false, + // MD020/no-missing-space-closed-atx - No space inside hashes on closed atx style heading + "MD020": false, + // MD021/no-multiple-space-closed-atx - Multiple spaces inside hashes on closed atx style heading + "MD021": false, + // MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines + "MD022": true, + // MD023/heading-start-left/header-start-left - Headings must start at the beginning of the line + "MD023": false, + // MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content + "MD024": false, + // MD025/single-title/single-h1 - Multiple top level headings in the same document + "MD025": true, + // MD026/no-trailing-punctuation - Trailing punctuation in heading + "MD026": { "punctuation": ".,;:!。,;:!?" }, // specifically allow "?" + // MD027/no-multiple-space-blockquote - Multiple spaces after blockquote symbol + "MD027": false, + // MD028/no-blanks-blockquote - Blank line inside blockquote + "MD028": true, + // MD029/ol-prefix - Ordered list item prefix + "MD029": false, + // MD030/list-marker-space - Spaces after list markers + "MD030": true, + // MD031/blanks-around-fences - Fenced code blocks should be surrounded by blank lines + "MD031": false, + // MD032/blanks-around-lists - Lists should be surrounded by blank lines + "MD032": false, + // MD033/no-inline-html - Inline HTML + "MD033": { "allowed_elements": ["a", "img", "br", "sup", "h1", "p"] }, + // MD034/no-bare-urls - Bare URL used + "MD034": false, + // MD035/hr-style - Horizontal rule style + "MD035": false, + // MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading + "MD036": true, + // MD037/no-space-in-emphasis - Spaces inside emphasis markers + "MD037": true, + // MD038/no-space-in-code - Spaces inside code span elements + "MD038": true, + // MD039/no-space-in-links - Spaces inside link text + "MD039": true, + // MD040/fenced-code-language - Fenced code blocks should have a language specified + "MD040": true, + // MD041/first-line-heading/first-line-h1 - First line in file should be a top level heading + "MD041": false, // would love to do this, but our README files use `
`${}`
template literals.
+JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
The default Object `.toString()` returns `"[object Object]"`, so this rule requires stringified objects define a more useful `.toString()` method.
@@ -52,6 +52,32 @@ const literalWithToString = {
`Value: ${literalWithToString}`;
```
+## Options
+
+The rule accepts an options object with the following properties:
+
+```ts
+type Options = {
+ // if true, interpolated expressions in tagged templates will not be checked
+ ignoreTaggedTemplateExpressions?: boolean;
+};
+
+const defaults = {
+ ignoreTaggedTemplateExpressions: false,
+};
+```
+
+### `ignoreTaggedTemplateExpressions`
+
+This allows to skip checking tagged templates, for cases where the tags do not necessarily stringify interpolated values.
+
+Examples of additional **correct** code for this rule with `{ ignoreTaggedTemplateExpressions: true }`:
+
+```ts
+function tag() {}
+tag`${{}}`;
+```
+
## When Not To Use It
If you don't mind `"[object Object]"` in your strings, then you will not need this rule.
diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
index d0b3b57d988a..ddfc1b9f1bd8 100644
--- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
+++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
@@ -7,7 +7,7 @@ It adds support for TypeScript's method overload definitions.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-dupe-class-members": "off",
@@ -15,4 +15,8 @@ It adds support for TypeScript's method overload definitions.
}
```
+## Options
+
+See [`eslint/no-dupe-class-members` options](https://eslint.org/docs/rules/no-dupe-class-members#options).
+
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-dupe-class-members.md)
diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md
index 17628cb93c8b..df6a3f825836 100644
--- a/packages/eslint-plugin/docs/rules/no-empty-function.md
+++ b/packages/eslint-plugin/docs/rules/no-empty-function.md
@@ -1,80 +1,24 @@
# Disallow empty functions (`no-empty-function`)
-Empty functions can reduce readability because readers need to guess whether it’s intentional or not. So writing a clear comment for empty functions is a good practice.
-
## Rule Details
-The `@typescript-eslint/no-empty-function` rule extends the `no-empty-function` rule from ESLint core, and adds support for handling TypeScript specific code that would otherwise trigger the rule.
+This rule extends the base [`eslint/no-empty-function`](https://eslint.org/docs/rules/no-empty-function) rule.
+It adds support for handling TypeScript specific code that would otherwise trigger the rule.
One example of valid TypeScript specific code that would otherwise trigger the `no-empty-function` rule is the use of [parameter properties](https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties) in constructor functions:
-```typescript
-class Person {
- constructor(private firstName: string, private surname: string) {}
-}
-```
-
-The above code is functionally equivalent to:
+## How to use
-```typescript
-class Person {
- private firstName: string;
- private surname: string;
-
- constructor(firstName: string, surname: string) {
- this.firstName = firstName;
- this.surname = surname;
- }
-}
-```
-
-Parameter properties enable both the _declaration_ and _initialization_ of member properties in a single location, avoiding the boilerplate & duplication that is common when initializing member properties from parameter values in a constructor function.
-
-In these cases, although the constructor has an empty function body, it is technically valid and should not trigger an error.
-
-See the [ESLint documentation](https://eslint.org/docs/rules/no-empty-function) for more details on the `no-empty-function` rule.
-
-## Rule Changes
-
-```cjson
+```jsonc
{
- // note you must disable the base rule as it can report incorrect errors
- "no-empty-function": "off",
- "@typescript-eslint/no-empty-function": "error"
+ // note you must disable the base rule as it can report incorrect errors
+ "no-empty-function": "off",
+ "@typescript-eslint/no-empty-function": ["error"]
}
```
## Options
-This rule has an object option:
-
-- `allow` (`string[]`)
- - `"protected-constructors"` - Protected class constructors.
- - `"private-constructors"` - Private class constructors.
- - [See the other options allowed](https://github.com/eslint/eslint/blob/master/docs/rules/no-empty-function.md#options)
-
-#### allow: protected-constructors
-
-Examples of **correct** code for the `{ "allow": ["protected-constructors"] }` option:
-
-```ts
-/*eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["protected-constructors"] }]*/
-
-class Foo {
- protected constructor() {}
-}
-```
-
-#### allow: private-constructors
-
-Examples of **correct** code for the `{ "allow": ["private-constructors"] }` option:
-
-```ts
-/*eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["private-constructors"] }]*/
-
-class Foo {
- private constructor() {}
-}
-```
+See [`eslint/no-empty-function` options](https://eslint.org/docs/rules/no-empty-function#options).
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-empty-function.md)
diff --git a/packages/eslint-plugin/docs/rules/no-extra-parens.md b/packages/eslint-plugin/docs/rules/no-extra-parens.md
index bcb21dec28df..8173b2ef1adb 100644
--- a/packages/eslint-plugin/docs/rules/no-extra-parens.md
+++ b/packages/eslint-plugin/docs/rules/no-extra-parens.md
@@ -1,22 +1,22 @@
# Disallow unnecessary parentheses (`no-extra-parens`)
-This rule restricts the use of parentheses to only where they are necessary.
-
## Rule Details
This rule extends the base [`eslint/no-extra-parens`](https://eslint.org/docs/rules/no-extra-parens) rule.
-It supports all options and features of the base rule plus TS type assertions.
+It adds support for TypeScript type assertions.
## How to use
-```cjson
+```jsonc
{
- // note you must disable the base rule as it can report incorrect errors
- "no-extra-parens": "off",
- "@typescript-eslint/no-extra-parens": ["error"]
+ // note you must disable the base rule as it can report incorrect errors
+ "no-extra-parens": "off",
+ "@typescript-eslint/no-extra-parens": ["error"]
}
```
## Options
See [`eslint/no-extra-parens` options](https://eslint.org/docs/rules/no-extra-parens#options).
+
+Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-extra-parens.md)
diff --git a/packages/eslint-plugin/docs/rules/no-extra-semi.md b/packages/eslint-plugin/docs/rules/no-extra-semi.md
index bed5e29d657b..f6865bd8b54a 100644
--- a/packages/eslint-plugin/docs/rules/no-extra-semi.md
+++ b/packages/eslint-plugin/docs/rules/no-extra-semi.md
@@ -3,10 +3,11 @@
## Rule Details
This rule extends the base [`eslint/no-extra-semi`](https://eslint.org/docs/rules/no-extra-semi) rule.
+It adds support for class properties.
## How to use
-```cjson
+```jsonc
{
// note you must disable the base rule as it can report incorrect errors
"no-extra-semi": "off",
@@ -14,4 +15,8 @@ This rule extends the base [`eslint/no-extra-semi`](https://eslint.org/docs/rule
}
```
+## Options
+
+See [`eslint/no-extra-semi` options](https://eslint.org/docs/rules/no-extra-semi#options).
+
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-extra-semi.md)
diff --git a/packages/eslint-plugin/docs/rules/no-magic-numbers.md b/packages/eslint-plugin/docs/rules/no-magic-numbers.md
index 377e92723607..f41204c132bf 100644
--- a/packages/eslint-plugin/docs/rules/no-magic-numbers.md
+++ b/packages/eslint-plugin/docs/rules/no-magic-numbers.md
@@ -1,25 +1,72 @@
# Disallow magic numbers (`no-magic-numbers`)
-'Magic numbers' are numbers that occur multiple times in code without an explicit meaning.
-They should preferably be replaced by named constants.
-
## Rule Details
-The `@typescript-eslint/no-magic-numbers` rule extends the `no-magic-numbers` rule from ESLint core, and adds support for handling TypeScript specific code that would otherwise trigger the rule.
+This rule extends the base [`eslint/no-magic-numbers`](https://eslint.org/docs/rules/no-magic-numbers) rule.
+It adds support for:
-See the [ESLint documentation](https://eslint.org/docs/rules/no-magic-numbers) for more details on the `no-magic-numbers` rule.
+- numeric literal types (`type T = 1`),
+- `enum` members (`enum Foo { bar = 1 }`),
+- `readonly` class properties (`class Foo { readonly bar = 1 }`).
-## Rule Changes
+## How to use
-```cjson
+```jsonc
{
- // note you must disable the base rule as it can report incorrect errors
- "no-magic-numbers": "off",
- "@typescript-eslint/no-magic-numbers": ["error", { "ignoreNumericLiteralTypes": true }]
+ // note you must disable the base rule as it can report incorrect errors
+ "no-magic-numbers": "off",
+ "@typescript-eslint/no-magic-numbers": [
+ "error",
+ {
+ /* options */
+ }
+ ]
+}
+```
+
+## Options
+
+See [`eslint/no-magic-numbers` options](https://eslint.org/docs/rules/no-magic-numbers#options).
+This rule adds the following options:
+
+```ts
+interface Options extends BaseNoMagicNumbersOptions {
+ ignoreEnums?: boolean;
+ ignoreNumericLiteralTypes?: boolean;
+ ignoreReadonlyClassProperties?: boolean;
+}
+
+const defaultOptions: Options = {
+ ...baseNoMagicNumbersDefaultOptions,
+ ignoreEnums: false,
+ ignoreNumericLiteralTypes: false,
+ ignoreReadonlyClassProperties: false,
+};
+```
+
+### `ignoreEnums`
+
+A boolean to specify if enums used in TypeScript are considered okay. `false` by default.
+
+Examples of **incorrect** code for the `{ "ignoreEnums": false }` option:
+
+```ts
+/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": false }]*/
+
+enum foo = {
+ SECOND = 1000,
}
```
-In addition to the options supported by the `no-magic-numbers` rule in ESLint core, the rule adds the following options:
+Examples of **correct** code for the `{ "ignoreEnums": true }` option:
+
+```ts
+/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": true }]*/
+
+enum foo = {
+ SECOND = 1000,
+}
+```
### `ignoreNumericLiteralTypes`
@@ -69,28 +116,4 @@ class Foo {
}
```
-### `ignoreEnums`
-
-A boolean to specify if enums used in TypeScript are considered okay. `false` by default.
-
-Examples of **incorrect** code for the `{ "ignoreEnums": false }` option:
-
-```ts
-/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": false }]*/
-
-enum foo = {
- SECOND = 1000,
-}
-```
-
-Examples of **correct** code for the `{ "ignoreEnums": true }` option:
-
-```ts
-/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreEnums": true }]*/
-
-enum foo = {
- SECOND = 1000,
-}
-```
-
Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-magic-numbers.md)
diff --git a/packages/eslint-plugin/docs/rules/no-this-alias.md b/packages/eslint-plugin/docs/rules/no-this-alias.md
index 7f5ee719fa0f..b5d2afb542cc 100644
--- a/packages/eslint-plugin/docs/rules/no-this-alias.md
+++ b/packages/eslint-plugin/docs/rules/no-this-alias.md
@@ -39,15 +39,15 @@ Examples of **correct** code for this rule:
You can pass an object option:
-```json5
+```jsonc
{
- '@typescript-eslint/no-this-alias': [
- 'error',
+ "@typescript-eslint/no-this-alias": [
+ "error",
{
- allowDestructuring: true, // Allow `const { props, state } = this`; false by default
- allowedNames: ['self'], // Allow `const self = this`; `[]` by default
- },
- ],
+ "allowDestructuring": true, // Allow `const { props, state } = this`; false by default
+ "allowedNames": ["self"] // Allow `const self = this`; `[]` by default
+ }
+ ]
}
```
diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md
new file mode 100644
index 000000000000..1a452e431eb3
--- /dev/null
+++ b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md
@@ -0,0 +1,62 @@
+# Disallows assigning any to variables and properties (`no-unsafe-assignment`)
+
+Despite your best intentions, the `any` type can sometimes leak into your codebase.
+Assigning an `any` typed value to a variable can be hard to pick up on, particularly if it leaks in from an external library. Operations on the variable will not be checked at all by TypeScript, so it creates a potential safety hole, and source of bugs in your codebase.
+
+## Rule Details
+
+This rule disallows assigning `any` to a variable, and assigning `any[]` to an array destructuring.
+This rule also compares the assigned type to the variable's type to ensure you don't assign an unsafe `any` in a generic position to a receiver that's expecting a specific type. For example, it will error if you assign `Set