Skip to content

Add an option to specify different rules inside a markdown file #170

@aduh95

Description

@aduh95

I'm trying to set up a rule set that is able to discriminate between ESM examples and CJS code snippets inside the markdown documentation:

```js esm
export default {};
```
```js cjs
'use strict';
module.exports = {};
```

The issue is that only the js is passed through unfied lang data, and the part after the space is pass to the meta option:

{
  type: 'html',
  lang: 'js',
  meta: 'esm',
  value: 'export default {};',
  position: {
    start: { line: 1, column: 1, offset: 0 },
    end: { line: 3, column: 4, offset: 32 }
  }
}
{
  type: 'html',
  lang: 'js',
  meta: 'cjs',
  value: "'use strict';\nmodule.exports = {};",
  position: {
    start: { line: 4, column: 1, offset: 33 },
    end: { line: 7, column: 4, offset: 81 }
  }
}

I wish there was a way to create separate rules for those blocks, something like:

// .eslintrc.js
module.exports = {
    plugins: ["markdown"],
    overrides: [
        {
            files: ["**/*.md/*.js:cjs"],
            parserOption: { sourceType: "script" },
            rules: {
                // ...
            }
        },
        {
            files: ["**/*.md/*.js:esm"],
            parserOption: { sourceType: "module" },
            rules: {
                // ...
            }
        },
    ]
};

EDIT: I'm using remark-parse 9.0.0, the meta property doesn't seem to be available in remark-parse 5.x this repo is using.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions