eslint / eslint-plugin-markdown

Lint JavaScript code blocks in Markdown documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for typescript

SimonSiefke opened this issue · comments

I'm using https://github.com/typescript-eslint/typescript-eslint for linting typescript files with eslint. Would it be possible to also lint typescript-blocks inside markdown files with this plugin?

Thank you for this issue.

For now, we cannot check ts code blocks. But ESLint 6 will support multiple processors (eslint/eslint#11552), then we will get the ability to lint ts code blocks.

commented

Now that eslint@6.x.x is out, any chance this could be readdressed?

👋 I'm now actively working on implementing the new processor API so that this plugin can extract TypeScript code blocks and pass them to ESLint! I'm tracking progress in #138, so subscribe to that issue if you'd like updates, and I'll close this so that #138 is the primary issue for this work.

I see #138 is now closed. Does this mean that TypeScript is now supported? There is no mention of TypeScript in readme.

v2.0.0-alpha.0, released this weekend, should work with ```ts code blocks! Please try it out and let me know how it goes. I'm also working on a set of examples, so if you're so inclined, I'd welcome a PR to add add an examples/typescript subdirectory with TypeScript working!

I made a pull request for adding it to a project. I get the following error message.

/home/travis/build/maasglobal/scrapql/README.md
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: README.md/0_0.ts.
The file must be included in at least one of the projects provided
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: README.md/1_1.ts.
The file must be included in at least one of the projects provided
...

See https://github.com/maasglobal/scrapql/pull/73/files
and https://travis-ci.com/github/maasglobal/scrapql/builds/160517417

@btmills Thanks for this plugin!
@cyberixae

I faced the same error for my typescript project when I used js or javascript for the code blocks. But the errors went away once I switched to ts or typescript (which seems different than your situation).

Error:

  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: README.md/0_0.js.
The file must be included in at least one of the projects provided

Setup that is working for me currently with v2:

.eslintrc.js

module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    parserOptions: {
        project: './tsconfig.eslint.json',
    },
  plugins: [
        'markdown',
    ],
overrides: [
        {
            // Enable the Markdown processor for all .md files.
            files: ['**/*.md'],
            processor: 'markdown/markdown',
        },
    ]
}

tsconfig.eslint.json:

{
    "compilerOptions": { "strict": true },
    "include": ["./packages/**/*.ts", "*.js"]
}

I tried including "**/*.md/*.js" in the include list above - but it didn't seem to make a difference.

Maybe adding sourceType: 'module' to parserOptions breaks markdown plugin.

Having the same issue as @mohanraj-r, can this issue be reopened as it doesn't seem possible to use parserOptions.project with this plugin

Same issue. Any known workaround?

Same issue, if add *.md mask for linting.
Steps for reproduce:

  1. change eslint **/*.{ts,json,js} to eslint **/*.{ts,json,js,md} in package.json
  2. npm run lint
  3. Have error:
0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: readme.md\0_0.js.
The file must be included in at least one of the projects provided

Unfortunately it's not possible to use type-aware linting rules with any ESLint processors, this Markdown plugin included. Since code blocks aren't real .ts files on disk, the TypeScript compiler doesn't know how readme.md/0_0.ts fits into any known tsconfig.json. If you remove parserOptions.project, you should still be able to use the @typescript-eslint rules that don't require a tsconfig.json. For more details, check out #155 (comment) from the PR where I added the TypeScript example to the repository.

@btmills Why #114 was closed? Where I can see working configuration example for Typescript? I tried your example, but no success

@viT-1 if something is broken in the TypeScript example, please open an issue describing what's broken or better yet a PR to fix it! If you're able to use some @typescript-eslint rules but not the type-aware rules, see the comment above you for why that's not currently possible.

The same problem here, any workaround to avoid the error message from tsc?

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: no-console.md/2_2.ts.
The file must be included in at least one of the projects provided.

@laozhu remove parserOptions.project from your config for Markdown code blocks. tsc doesn't support type-aware lint rules in Markdown code blocks. For details, see #114 (comment).

Thank you, solved this. Some types-required rules have to be disabled for typescript blocks in markdown.