-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Docs: Add TypeScript example * WIP: Add tsconfig.json for type-aware linting It works on the first block but not the second. See diff for additional context. Any ideas? * Docs: Remove tsconfig.json and add type-aware rule note
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
module.exports = { | ||
root: true, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:markdown/recommended", | ||
], | ||
overrides: [ | ||
{ | ||
files: [".eslintrc.js"], | ||
env: { | ||
node: true | ||
} | ||
}, | ||
{ | ||
files: ["*.ts"], | ||
parser: "@typescript-eslint/parser", | ||
extends: ["plugin:@typescript-eslint/recommended"] | ||
}, | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# React Example | ||
|
||
The `@typescript-eslint` parser and the `recommended` config's rules will work in `ts` code blocks. However, [type-aware rules](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md) will not work because the code blocks are not part of a compilable `tsconfig.json` project. | ||
|
||
```ts | ||
function hello(name: String) { | ||
console.log(`Hello, ${name}!`); | ||
} | ||
|
||
hello(42 as any); | ||
``` | ||
|
||
```sh | ||
$ git clone https://github.com/eslint/eslint-plugin-markdown.git | ||
$ cd eslint-plugin-markdown/examples/typescript | ||
$ npm install | ||
$ npm test | ||
|
||
eslint-plugin-markdown/examples/typescript/README.md | ||
6:22 error Don’t use `String` as a type. Use string instead @typescript-eslint/ban-types | ||
10:13 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any | ||
|
||
✖ 2 problems (1 error, 1 warning) | ||
1 error and 0 warnings potentially fixable with the `--fix` option. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"test": "eslint ." | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^3.6.1", | ||
"@typescript-eslint/parser": "^3.6.1", | ||
"eslint": "^7.5.0", | ||
"eslint-plugin-markdown": "file:../..", | ||
"typescript": "^3.9.7" | ||
} | ||
} |