Skip to content

Commit

Permalink
docs: Fix tabs in rule examples (#17653)
Browse files Browse the repository at this point in the history
* Different ways to handle tabs

* Option to remove Playground links

* use tabs with `markdownlint-disable` comments

* add missing `eslint` comments

* Apply review suggestions

* Remove comments from `no-mixed-spaces-and-tabs`
  • Loading branch information
fasttime committed Oct 26, 2023
1 parent 3aec1c5 commit 8651895
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
11 changes: 7 additions & 4 deletions docs/src/rules/indent-legacy.md
Expand Up @@ -140,20 +140,23 @@ function foo(d) {

Examples of **correct** code for this rule with the `"tab"` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/*eslint indent-legacy: ["error", "tab"]*/

if (a) {
/*tab*/b=c;
/*tab*/function foo(d) {
/*tab*//*tab*/e=f;
/*tab*/}
b=c;
function foo(d) {
e=f;
}
}
```

:::
<!-- markdownlint-restore -->

### SwitchCase

Expand Down
11 changes: 7 additions & 4 deletions docs/src/rules/indent.md
Expand Up @@ -141,20 +141,23 @@ function foo(d) {

Examples of **correct** code for this rule with the `"tab"` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/*eslint indent: ["error", "tab"]*/

if (a) {
/*tab*/b=c;
/*tab*/function foo(d) {
/*tab*//*tab*/e=f;
/*tab*/}
b=c;
function foo(d) {
e=f;
}
}
```

:::
<!-- markdownlint-restore -->

### ignoredNodes

Expand Down
19 changes: 13 additions & 6 deletions docs/src/rules/max-len.md
Expand Up @@ -69,30 +69,36 @@ var foo = {

Examples of **incorrect** code for this rule with the default `{ "tabWidth": 4 }` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: incorrect

```js
/*eslint max-len: ["error", { "code": 80, "tabWidth": 4 }]*/

\t \t var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" } };
var foo = { "bar": "This is a bar.", "baz": { "qux": "This is a qux" } };
```

:::
<!-- markdownlint-restore -->

Examples of **correct** code for this rule with the default `{ "tabWidth": 4 }` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/*eslint max-len: ["error", { "code": 80, "tabWidth": 4 }]*/

\t \t var foo = {
\t \t \t \t "bar": "This is a bar.",
\t \t \t \t "baz": { "qux": "This is a qux" }
\t \t };
var foo = {
"bar": "This is a bar.",
"baz": { "qux": "This is a qux" }
};
```

:::
<!-- markdownlint-restore -->

### comments

Expand Down Expand Up @@ -203,7 +209,8 @@ Examples of **correct** code for this rule with the `ignorePattern` option:
::: correct

```js
/*eslint max-len: ["error", { "ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\(" }]*/
/*eslint max-len:
["error", { "ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\(" }]*/

var dep = require('really/really/really/really/really/really/really/really/long/module');
```
Expand Down
30 changes: 15 additions & 15 deletions docs/src/rules/no-mixed-spaces-and-tabs.md
Expand Up @@ -15,42 +15,42 @@ This rule disallows mixed spaces and tabs for indentation.

Examples of **incorrect** code for this rule:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: incorrect

```js
/*eslint no-mixed-spaces-and-tabs: "error"*/

function add(x, y) {
// --->..return x + y;

return x + y;
return x + y;
}

function main() {
// --->var x = 5,
// --->....y = 7;

var x = 5,
y = 7;
var x = 5,
y = 7;
}
```

:::
<!-- markdownlint-restore -->

Examples of **correct** code for this rule:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/*eslint no-mixed-spaces-and-tabs: "error"*/

function add(x, y) {
// --->return x + y;
return x + y;
return x + y;
}
```

:::
<!-- markdownlint-restore -->

## Options

Expand All @@ -62,18 +62,18 @@ This rule has a string option.

Examples of **correct** code for this rule with the `"smart-tabs"` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/*eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/

function main() {
// --->var x = 5,
// --->....y = 7;

var x = 5,
y = 7;
var x = 5,
y = 7;
}
```

:::
<!-- markdownlint-restore -->
20 changes: 15 additions & 5 deletions docs/src/rules/no-tabs.md
Expand Up @@ -12,26 +12,33 @@ This rule looks for tabs anywhere inside a file: code, comments or anything else

Examples of **incorrect** code for this rule:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: incorrect

```js
var a \t= 2;
/* eslint no-tabs: "error" */

var a = 2;

/**
* \t\t it's a test function
* it's a test function
*/
function test(){}

var x = 1; // \t test
var x = 1; // test
```

:::
<!-- markdownlint-restore -->

Examples of **correct** code for this rule:

::: correct

```js
/* eslint no-tabs: "error" */

var a = 2;

/**
Expand All @@ -54,19 +61,22 @@ This rule has an optional object option with the following properties:

Examples of **correct** code for this rule with the `allowIndentationTabs: true` option:

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD010 -->
::: correct

```js
/* eslint no-tabs: ["error", { allowIndentationTabs: true }] */

function test() {
\tdoSomething();
doSomething();
}

\t// comment with leading indentation tab
// comment with leading indentation tab
```

:::
<!-- markdownlint-restore -->

## When Not To Use It

Expand Down

0 comments on commit 8651895

Please sign in to comment.