Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for typescript #114

Closed
SimonSiefke opened this issue Mar 29, 2019 · 20 comments
Closed

Support for typescript #114

SimonSiefke opened this issue Mar 29, 2019 · 20 comments
Labels

Comments

@SimonSiefke
Copy link

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?

@mysticatea
Copy link
Member

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.

@alex996
Copy link

alex996 commented Aug 3, 2019

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

@btmills
Copy link
Member

btmills commented Feb 26, 2020

👋 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.

@btmills btmills closed this as completed Feb 26, 2020
@cyberixae
Copy link

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

@btmills
Copy link
Member

btmills commented Apr 14, 2020

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!

@cyberixae
Copy link

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

@mohanraj-r
Copy link

@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.

@cyberixae
Copy link

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

@DetachHead
Copy link

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

@hugotox
Copy link

hugotox commented Apr 8, 2021

Same issue. Any known workaround?

@viT-1
Copy link

viT-1 commented Apr 9, 2021

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

@btmills
Copy link
Member

btmills commented Apr 13, 2021

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.

@viT-1
Copy link

viT-1 commented Apr 23, 2021

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

@btmills
Copy link
Member

btmills commented Apr 24, 2021

@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.

@laozhu
Copy link

laozhu commented May 11, 2021

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.

@btmills
Copy link
Member

btmills commented May 19, 2021

@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).

@laozhu
Copy link

laozhu commented May 19, 2021

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

@iambumblehead
Copy link

I've tried changing the eslint command for a project here from "eslint --ext .ts,.tsx,.js ." to "eslint ." and am seeing the same error reported by others here

/home/bumble/software/snabbdom/README.md
  790:1  error  Parsing error: ESLint was configured to run on `<tsconfigRootDir>/README.md/33_33.tsx` using `parserOptions.project`: 
- <tsconfigRootDir>/tsconfig.json
- <tsconfigRootDir>/test/tsconfig.json
However, none of those TSConfigs include this file. Either:
- Change ESLint's list of included files to not include this file
- Change one of those TSConfigs to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file

The project does not define parserOptions.project for markdown files https://github.com/snabbdom/snabbdom/blob/master/.eslintrc.json

Would anyone tell me what I'm doing wrong? I've tried explicitly setting null parserOptions.project, but it did not have any effect

{
    "files": ["**/*.md"],
    "processor": "markdown/markdown",
    "parserOptions": {
      "project": null
    }
}

@iambumblehead
Copy link

The issue was resolved by explicitly ignoring README-related files in the eslint typescript configuration. The full PR and changes are here snabbdom/snabbdom#1074

@meteorlxy
Copy link

For flat config, this snippet should help:

{
  files: ['**/*.md/**'],
  languageOptions: {
    parserOptions: {
      project: null,
    },
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests